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

110 lines
3.3 KiB
Java

/**
*
*/
package org.gcube.accounting.aggregation.scheduler;
import org.gcube.accounting.datamodel.SingleUsageRecord;
import org.gcube.accounting.datamodel.TestUsageRecord;
import org.gcube.accounting.datamodel.UsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.persistence.PersistenceExecutor;
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 PersistenceExecutor persistenceExecutor = new PersistenceExecutor(){
@Override
public void persist(UsageRecord... usageRecords) throws Exception {
logger.debug(usageRecords.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.createTestServiceUsageRecord();
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
}
});
aggregationScheduler.flush(persistenceExecutor);
}
public static final String ALTERNATIVE_SERVICE_CLASS = "ContentManagement";
@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.createTestServiceUsageRecord();
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.createTestServiceUsageRecord();
}else{
usageRecord = TestUsageRecord.createTestStorageUsageRecord();
}
aggregationScheduler.aggregate(usageRecord, persistenceExecutor);
}
});
aggregationScheduler.flush(persistenceExecutor);
}
/*
@Test
public void stressTestDifferentAggregableURMultipleType() throws Exception {
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
}
});
}
@Test
public void stressTestDifferentAggregableAndNotAggregable() throws Exception {
StressTestUtility.stressTest(new TestOperation() {
@Override
public void operate(int i) throws Exception {
}
});
}
*/
}