92 lines
3.0 KiB
Java
92 lines
3.0 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 AccountingPersistenceTest {
|
|
|
|
public static final String[] SCOPES = new String[]{"/gcube", "/gcube/devNext"};
|
|
public static final String GCUBE_SCOPE = SCOPES[0];
|
|
public static final String GCUBE_DEVNEXT_SCOPE = SCOPES[1];
|
|
|
|
public static final long timeout = 5000;
|
|
public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
|
|
|
public static AccountingPersistenceBackend getPersistence(){
|
|
ScopeProvider.instance.set(GCUBE_DEVNEXT_SCOPE);
|
|
AccountingPersistenceBackendFactory.setFallbackLocation(null);
|
|
return AccountingPersistenceBackendFactory.getPersistenceBackend();
|
|
}
|
|
|
|
@Test
|
|
public void singleTestNoScope() throws Exception {
|
|
AccountingPersistenceBackendFactory.setFallbackLocation(null);
|
|
final AccountingPersistenceBackend persistence = AccountingPersistenceBackendFactory.getPersistenceBackend();
|
|
Assert.assertTrue(persistence instanceof FallbackPersistence);
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
|
persistence.validateAccountAggregate(usageRecord, true, false);
|
|
}
|
|
}, 1);
|
|
|
|
persistence.flush(timeout, timeUnit);
|
|
}
|
|
|
|
@Test
|
|
public void singleTest() throws Exception {
|
|
final AccountingPersistenceBackend persistence = getPersistence();
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
|
persistence.validateAccountAggregate(usageRecord, true, false);
|
|
}
|
|
}, 1);
|
|
|
|
persistence.flush(timeout, timeUnit);
|
|
}
|
|
|
|
@Test
|
|
public void stressTestNoAggregation() throws Exception {
|
|
final AccountingPersistenceBackend persistence = getPersistence();
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
|
persistence.validateAccountAggregate(usageRecord, true, false);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Test
|
|
public void stressTestWithAggregation() throws Exception {
|
|
final AccountingPersistenceBackend persistence = getPersistence();
|
|
|
|
StressTestUtility.stressTest(new TestOperation() {
|
|
@Override
|
|
public void operate(int i) throws Exception {
|
|
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
|
|
persistence.account(usageRecord);
|
|
}
|
|
});
|
|
persistence.flush(timeout, timeUnit);
|
|
}
|
|
|
|
}
|