accounting-lib/src/test/java/org/gcube/accounting/aggregation/scheduler/AggregationSchedulerTest.java

128 lines
4.1 KiB
Java

/**
*
*/
package org.gcube.accounting.aggregation.scheduler;
import org.gcube.accounting.datamodel.SingleUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.basetypes.TestUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.persistence.AccountingPersistenceExecutor;
import org.gcube.accounting.testutility.StressTestUtility;
import org.gcube.accounting.testutility.TestOperation;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class AggregationSchedulerTest {
private static final Logger logger = LoggerFactory.getLogger(AggregationSchedulerTest.class);
public static AggregationScheduler getAggregationScheduler(){
return AggregationScheduler.getInstance();
}
public static AccountingPersistenceExecutor persistenceExecutor = new AccountingPersistenceExecutor(){
@Override
public void persist(UsageRecord... usageRecords) throws Exception {
for(UsageRecord usageRecord : usageRecords){
logger.debug(usageRecord.toString());
}
}
};
@Test
public void stressTestAggregableURSingleType() throws Exception {
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
}
});
aggregationScheduler.flush(persistenceExecutor);
}
public static final String ALTERNATIVE_SERVICE_CLASS = "AlternativeServiceClass";
@Test
public void stressTestDifferentAggregableURSingleType() throws Exception {
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
if(i%2==0){
usageRecord.setServiceClass(ALTERNATIVE_SERVICE_CLASS);
}
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
}
});
aggregationScheduler.flush(persistenceExecutor);
}
@Test
public void stressTestDifferentAggregableURTwoType() throws Exception {
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
SingleUsageRecord usageRecord;
if(i%2==0){
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
}else{
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
}
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
}
});
aggregationScheduler.flush(persistenceExecutor);
}
@Test
public void stressTestDifferentAggregableURMultipleType() throws Exception {
final AggregationScheduler aggregationScheduler = getAggregationScheduler();
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
SingleUsageRecord usageRecord;
switch (i%3) {
case 0:
usageRecord = TestUsageRecord.createTestServiceUsageRecordAutomaticScope();
break;
case 1:
usageRecord = TestUsageRecord.createTestStorageUsageRecordAutomaticScope();
break;
case 2:
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
break;
default:
usageRecord = TestUsageRecord.createTestJobUsageRecordAutomaticScope();
}
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
}
});
aggregationScheduler.flush(persistenceExecutor);
}
/*
@Test
public void stressTestDifferentAggregableAndNotAggregable() throws Exception {
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
}
});
}
*/
}