Fixing test

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@128098 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-04-14 15:34:38 +00:00
parent 5b68f1709f
commit 4c582ca032
1 changed files with 6 additions and 25 deletions

View File

@ -7,15 +7,13 @@ import java.util.Calendar;
import java.util.concurrent.TimeUnit;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
import org.gcube.testutility.ScopedTest;
import org.gcube.testutility.StressTestUtility;
import org.gcube.testutility.TestOperation;
import org.gcube.testutility.TestUsageRecord;
import org.gcube.testutility.TestUtility;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -31,18 +29,8 @@ public class PersistenceBackendTest extends ScopedTest {
public static final long timeout = 5000;
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
@Before
public void before() throws Exception{
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
}
@After
public void after() throws Exception{
SecurityTokenProvider.instance.reset();
}
public static PersistenceBackend getPersistence(){
AccountingPersistenceFactory.initAccountingPackages();
PersistenceBackendFactory.setFallbackLocation(null);
return PersistenceBackendFactory.getPersistenceBackend(TestUtility.getScope());
}
@ -106,28 +94,21 @@ public class PersistenceBackendTest extends ScopedTest {
@Test
public void testScopeRecheck() throws Exception {
PersistenceBackendFactory.setFallbackLocation(null);
logger.debug("Going to check First Time");
PersistenceBackend first = PersistenceBackendFactory.getPersistenceBackend(TestUtility.getScope());
PersistenceBackend first = getPersistence();
logger.debug("First {} : {}", PersistenceBackend.class.getSimpleName(), first);
Long firstCheck = PersistenceBackendFactory.getFallbackLastCheck(TestUtility.getScope());
logger.debug("First Check Time {}", firstCheck);
long startTime = Calendar.getInstance().getTimeInMillis();
long endTime = startTime;
while(endTime <= (startTime + (PersistenceBackendFactory.FALLBACK_RETRY_TIME + 100))){
while(endTime <= (startTime + (PersistenceBackendFactory.FALLBACK_RETRY_TIME + 2100))){
endTime = Calendar.getInstance().getTimeInMillis();
}
logger.debug("Going to check Second Time");
PersistenceBackend second = PersistenceBackendFactory.getPersistenceBackend(TestUtility.getScope());
PersistenceBackend second = getPersistence();
logger.debug("Second {} : {}", PersistenceBackend.class.getSimpleName(), second);
Long secondCheck = PersistenceBackendFactory.getFallbackLastCheck(TestUtility.getScope());
logger.debug("Second Check Time {}", secondCheck);
Assert.assertNotEquals(firstCheck, secondCheck);
Assert.assertEquals(first, second);
}
}