refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Fixing tests git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@117044 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9517ca2577
commit
cdceacdce8
|
@ -59,23 +59,24 @@ public abstract class PersistenceFactory {
|
|||
}
|
||||
}
|
||||
|
||||
public static Persistence getPersistence(){
|
||||
public static Persistence getPersistence() {
|
||||
String scope = ScopeProvider.instance.get();
|
||||
if(scope==null){
|
||||
logger.error("No Scope available. FallbackPersistence will be used");
|
||||
File fallbackFile = new File(fallbackLocation, ACCOUTING_FALLBACK_FILENAME);
|
||||
return new FallbackPersistence(fallbackFile);
|
||||
}
|
||||
|
||||
Persistence persistence = persistences.get(scope);
|
||||
if(persistence==null){
|
||||
|
||||
String name = "";
|
||||
if(scope!=null){
|
||||
ScopeBean bean = new ScopeBean(scope);
|
||||
if(bean.is(Type.VRE)){
|
||||
bean = bean.enclosingScope();
|
||||
}
|
||||
name = bean.name();
|
||||
ScopeBean bean = new ScopeBean(scope);
|
||||
if(bean.is(Type.VRE)){
|
||||
bean = bean.enclosingScope();
|
||||
}
|
||||
String separator = name.compareTo("")==0 ? "" : ".";
|
||||
String name = bean.name();
|
||||
|
||||
File fallbackFile = new File(fallbackLocation, String.format("%s%s%s", name, separator ,ACCOUTING_FALLBACK_FILENAME));
|
||||
File fallbackFile = new File(fallbackLocation, String.format("%s.%s", name, ACCOUTING_FALLBACK_FILENAME));
|
||||
FallbackPersistence fallbackPersistence = new FallbackPersistence(fallbackFile);
|
||||
try {
|
||||
ServiceLoader<Persistence> serviceLoader = ServiceLoader.load(Persistence.class);
|
||||
|
@ -99,7 +100,6 @@ public abstract class PersistenceFactory {
|
|||
break;
|
||||
} catch (Exception e) {
|
||||
logger.debug(String.format("%s not initialized correctly. It will not be used", foundPersistence.getClass().getSimpleName()));
|
||||
|
||||
}
|
||||
}
|
||||
if(persistence==null){
|
||||
|
@ -112,6 +112,7 @@ public abstract class PersistenceFactory {
|
|||
}
|
||||
persistence.setAggregationScheduler(AggregationScheduler.getInstance());
|
||||
persistence.setFallback(fallbackPersistence);
|
||||
persistences.put(scope, persistence);
|
||||
}
|
||||
|
||||
return persistence;
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.gcube.accounting.datamodel.SingleUsageRecord;
|
|||
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
|
||||
import org.gcube.accounting.testutility.StressTestUtility;
|
||||
import org.gcube.accounting.testutility.TestOperation;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -16,10 +18,27 @@ import org.junit.Test;
|
|||
public class PersistenceTest {
|
||||
|
||||
public static Persistence getPersistence(){
|
||||
ScopeProvider.instance.set(PersistenceConfigurationTest.GCUBE_DEVNEXT_SCOPE);
|
||||
PersistenceFactory.setFallbackLocation(null);
|
||||
return PersistenceFactory.getPersistence();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleTestNoScope() throws Exception {
|
||||
PersistenceFactory.setFallbackLocation(null);
|
||||
final Persistence persistence = PersistenceFactory.getPersistence();
|
||||
Assert.assertTrue(persistence instanceof FallbackPersistence);
|
||||
StressTestUtility.stressTest(new TestOperation() {
|
||||
@Override
|
||||
public void operate(int i) {
|
||||
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
persistence.validateAccountAggregate(usageRecord, true, false);
|
||||
}
|
||||
}, 1);
|
||||
|
||||
persistence.flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleTest() throws Exception {
|
||||
final Persistence persistence = getPersistence();
|
||||
|
|
Loading…
Reference in New Issue