diff --git a/src/test/java/org/gcube/accounting/couchdb/query/AccountingTest.java b/src/test/java/org/gcube/accounting/couchdb/query/AccountingTest.java new file mode 100644 index 0000000..89af50c --- /dev/null +++ b/src/test/java/org/gcube/accounting/couchdb/query/AccountingTest.java @@ -0,0 +1,104 @@ +/** + * + */ +package org.gcube.accounting.couchdb.query; + +import java.util.concurrent.TimeUnit; + +import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; +import org.gcube.accounting.persistence.AccountingPersistence; +import org.gcube.accounting.persistence.AccountingPersistenceFactory; +import org.gcube.documentstore.exception.InvalidValueException; +import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions; +import org.gcube.utils.TestUsageRecord; +import org.junit.After; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + * + */ +public class AccountingTest { + + private static Logger logger = LoggerFactory.getLogger(AccountingTest.class); + + @After + public void after(){ + AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence(); + try { + accountingPersistence.flush(100, TimeUnit.MILLISECONDS); + } catch (Exception e) { + logger.error("Error flushing Buffered Records", e); + } + } + + @Test + public void accountingServiceUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions { + + AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence(); + + 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 { + + AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence(); + + for(int i=0; i<1000; i++){ + StorageUsageRecord sur = org.gcube.utils.TestUsageRecord.createTestStorageUsageRecord(); + sur.setScope(TestUsageRecord.TEST_SCOPE); + accountingPersistence.account(sur); + } + } + + @Test + public void accountingJobUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions { + + AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence(); + + 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 { + + AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence(); + + for(int i=0; i<1000; i++){ + PortletUsageRecord pur = TestUsageRecord.createTestPortletUsageRecord(); + pur.setScope(TestUsageRecord.TEST_SCOPE); + accountingPersistence.account(pur); + } + } + + + @Test + public void accountingTaskUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions { + + AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence(); + + for(int i=0; i<1000; i++){ + TaskUsageRecord tur = TestUsageRecord.createTestTaskUsageRecord(); + tur.setScope(TestUsageRecord.TEST_SCOPE); + accountingPersistence.account(tur); + } + } + */ + +} diff --git a/src/test/java/org/gcube/accounting/datamodel/records/aggregation/RecordUtilityTest.java b/src/test/java/org/gcube/accounting/datamodel/records/aggregation/RecordUtilityTest.java new file mode 100644 index 0000000..147345e --- /dev/null +++ b/src/test/java/org/gcube/accounting/datamodel/records/aggregation/RecordUtilityTest.java @@ -0,0 +1,51 @@ +/** + * + */ +package org.gcube.accounting.datamodel.records.aggregation; + +import java.util.ArrayList; +import java.util.List; + +import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord; +import org.gcube.documentstore.records.AggregatedRecord; +import org.gcube.documentstore.records.Record; +import org.gcube.documentstore.records.RecordUtility; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + * + */ +public class RecordUtilityTest { + + private static Logger logger = LoggerFactory.getLogger(RecordUtilityTest.class); + + @Test + public void recordUtilityTest() { + List> recordClasses = new ArrayList<>(); + recordClasses.add(ServiceUsageRecord.class); + recordClasses.add(StorageUsageRecord.class); + recordClasses.add(JobUsageRecord.class); + recordClasses.add(TaskUsageRecord.class); + recordClasses.add(PortletUsageRecord.class); + for(Class recordClass : recordClasses){ + try { + @SuppressWarnings("rawtypes") + Class aggregatedClass = RecordUtility.getAggregatedRecordClass(recordClass.getSimpleName()); + logger.error("Aggregated Record Class for {} is {}", + recordClass.getSimpleName(), + aggregatedClass.getSimpleName()); + } catch (ClassNotFoundException e) { + logger.error("Error getting Aggregated Record Class for {}", + recordClass.getSimpleName(), e); + } + } + } + +}