83 lines
2.4 KiB
Java
83 lines
2.4 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.accounting.persistence;
|
|
|
|
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;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
*
|
|
*/
|
|
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();
|
|
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 stressTestNoAggregation() throws Exception {
|
|
final Persistence persistence = getPersistence();
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
|
persistence.validateAccountAggregate(usageRecord, true, false);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void stressTestWithAggregation() throws Exception {
|
|
final Persistence persistence = getPersistence();
|
|
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) throws Exception {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
|
persistence.account(usageRecord);
|
|
}
|
|
});
|
|
persistence.flush();
|
|
}
|
|
|
|
}
|