2016-02-17 14:12:45 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-02-17 16:36:37 +01:00
|
|
|
package org.gcube.accounting.datamodel.usagerecords;
|
2016-02-17 14:12:45 +01:00
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
2016-02-17 15:09:38 +01:00
|
|
|
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
|
2016-02-17 14:12:45 +01:00
|
|
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
|
|
|
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
2016-02-17 14:17:31 +01:00
|
|
|
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord;
|
2016-02-17 14:12:45 +01:00
|
|
|
import org.gcube.accounting.persistence.AccountingPersistence;
|
|
|
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
|
|
|
import org.gcube.documentstore.exception.InvalidValueException;
|
|
|
|
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
2016-02-17 14:17:31 +01:00
|
|
|
import org.gcube.testutility.TestUsageRecord;
|
2016-02-17 14:12:45 +01:00
|
|
|
import org.junit.After;
|
2016-02-17 15:09:38 +01:00
|
|
|
import org.junit.Before;
|
2016-02-17 14:12:45 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
2016-10-12 14:24:02 +02:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-02-17 14:12:45 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class AccountingTest {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AccountingTest.class);
|
|
|
|
|
2016-02-17 15:09:38 +01:00
|
|
|
private AccountingPersistence accountingPersistence;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void before(){
|
|
|
|
accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
|
|
|
}
|
|
|
|
|
2016-02-17 14:12:45 +01:00
|
|
|
@After
|
|
|
|
public void after(){
|
|
|
|
try {
|
2016-02-17 15:09:38 +01:00
|
|
|
accountingPersistence.flush(1000, TimeUnit.MILLISECONDS);
|
2016-02-17 14:12:45 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error flushing Buffered Records", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void accountingServiceUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
|
|
|
|
|
|
|
for(int i=0; i<2; i++){
|
|
|
|
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
|
|
|
sur.setScope(TestUsageRecord.TEST_SCOPE);
|
|
|
|
accountingPersistence.account(sur);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void accountingStorageUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
|
|
|
for(int i=0; i<1000; i++){
|
2016-02-17 14:17:31 +01:00
|
|
|
StorageUsageRecord sur = org.gcube.testutility.TestUsageRecord.createTestStorageUsageRecord();
|
2016-02-17 14:12:45 +01:00
|
|
|
sur.setScope(TestUsageRecord.TEST_SCOPE);
|
|
|
|
accountingPersistence.account(sur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void accountingJobUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
|
|
|
for(int i=0; i<1000; i++){
|
|
|
|
JobUsageRecord jur = TestUsageRecord.createTestJobUsageRecord();
|
|
|
|
jur.setScope(TestUsageRecord.TEST_SCOPE);
|
|
|
|
accountingPersistence.account(jur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void accountingPortletUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
|
|
|
for(int i=0; i<1000; i++){
|
|
|
|
PortletUsageRecord pur = TestUsageRecord.createTestPortletUsageRecord();
|
|
|
|
pur.setScope(TestUsageRecord.TEST_SCOPE);
|
|
|
|
accountingPersistence.account(pur);
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 15:09:38 +01:00
|
|
|
|
2016-02-17 14:12:45 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void accountingTaskUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
|
|
|
for(int i=0; i<1000; i++){
|
|
|
|
TaskUsageRecord tur = TestUsageRecord.createTestTaskUsageRecord();
|
|
|
|
tur.setScope(TestUsageRecord.TEST_SCOPE);
|
|
|
|
accountingPersistence.account(tur);
|
|
|
|
}
|
|
|
|
}
|
2016-02-17 14:17:31 +01:00
|
|
|
|
2016-02-17 14:12:45 +01:00
|
|
|
|
|
|
|
}
|