88 lines
2.7 KiB
Java
88 lines
2.7 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.accounting.persistence;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
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 final long timeout = 5000;
|
|
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
|
|
|
public static AccountingPersistence getPersistence(){
|
|
ScopeProvider.instance.set(PersistenceConfigurationTest.GCUBE_DEVNEXT_SCOPE);
|
|
AccountingPersistenceFactory.setFallbackLocation(null);
|
|
return AccountingPersistenceFactory.getPersistence();
|
|
}
|
|
|
|
@Test
|
|
public void singleTestNoScope() throws Exception {
|
|
AccountingPersistenceFactory.setFallbackLocation(null);
|
|
final AccountingPersistence persistence = AccountingPersistenceFactory.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(timeout, timeUnit);
|
|
}
|
|
|
|
@Test
|
|
public void singleTest() throws Exception {
|
|
final AccountingPersistence persistence = getPersistence();
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
|
persistence.validateAccountAggregate(usageRecord, true, false);
|
|
}
|
|
}, 1);
|
|
|
|
persistence.flush(timeout, timeUnit);
|
|
}
|
|
|
|
@Test
|
|
public void stressTestNoAggregation() throws Exception {
|
|
final AccountingPersistence 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 AccountingPersistence persistence = getPersistence();
|
|
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) throws Exception {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
|
persistence.account(usageRecord);
|
|
}
|
|
});
|
|
persistence.flush(timeout, timeUnit);
|
|
}
|
|
|
|
}
|