Added Tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124249 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-17 13:12:45 +00:00
parent a6b11eb2df
commit 45176b5114
2 changed files with 155 additions and 0 deletions

View File

@ -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);
}
}
*/
}

View File

@ -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<Class<? extends Record>> 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<? extends Record> recordClass : recordClasses){
try {
@SuppressWarnings("rawtypes")
Class<? extends AggregatedRecord> 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);
}
}
}
}