Improved tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124256 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-17 14:09:38 +00:00
parent e8c79ad211
commit 365f19d8f2
3 changed files with 50 additions and 26 deletions

View File

@ -6,6 +6,7 @@ package org.gcube.accounting.couchdb.query;
import java.util.concurrent.TimeUnit;
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;
@ -15,6 +16,7 @@ import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.testutility.TestUsageRecord;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,11 +29,17 @@ public class AccountingTest {
private static Logger logger = LoggerFactory.getLogger(AccountingTest.class);
private AccountingPersistence accountingPersistence;
@Before
public void before(){
accountingPersistence = AccountingPersistenceFactory.getPersistence();
}
@After
public void after(){
AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
try {
accountingPersistence.flush(100, TimeUnit.MILLISECONDS);
accountingPersistence.flush(1000, TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error("Error flushing Buffered Records", e);
}
@ -40,8 +48,6 @@ public class AccountingTest {
@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);
@ -53,9 +59,6 @@ public class AccountingTest {
@Test
public void accountingStorageUsageRecordStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
for(int i=0; i<1000; i++){
StorageUsageRecord sur = org.gcube.testutility.TestUsageRecord.createTestStorageUsageRecord();
sur.setScope(TestUsageRecord.TEST_SCOPE);
@ -65,9 +68,6 @@ public class AccountingTest {
@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);
@ -75,25 +75,18 @@ public class AccountingTest {
}
}
/*
@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);

View File

@ -40,7 +40,7 @@ public class RecordUtilityTest {
Class<? extends AggregatedRecord> aggregatedClass = RecordUtility.getAggregatedRecordClass(recordClass.getSimpleName());
logger.error("Aggregated Record Class for {} is {}",
recordClass.getSimpleName(),
aggregatedClass.getSimpleName());
aggregatedClass.getName());
} catch (ClassNotFoundException e) {
logger.error("Error getting Aggregated Record Class for {}",
recordClass.getSimpleName(), e);

View File

@ -13,6 +13,7 @@ import java.util.UUID;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
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;
@ -30,7 +31,8 @@ public class TestUsageRecord {
public final static String TEST_CONSUMER_ID = "name.surname";
public final static String TEST_SCOPE = "/infrastructure/vo";
public final static OperationResult TEST_OPERATION_RESULT = OperationResult.SUCCESS;
public final static String TEST_SERVICE_CLASS = "TestServiceClass";
public final static String TEST_SERVICE_NAME = "TestServiceName";
public final static String TEST_CALLED_METHOD = "TestCalledMethod";
@ -46,12 +48,14 @@ public class TestUsageRecord {
public final static int TEST_VMS_USED = 2;
public final static String TEST_JOB_QUALIFIER = "TestJobQualifier";
public final static long HALF_DURATION = 10 * 60 * 1000; // 10 min
public final static OperationResult TEST_JOB_OPERATION_RESULT = OperationResult.SUCCESS;
public final static String TEST_TASK_ID = UUID.randomUUID().toString();
public final static String TEST_NESTED_MAP = "TestNestedMap";
public final static String TEST_PORTLET_ID = "TestPortlet";
public final static String TEST_PORTLET_OPERATION_ID = "TestPortletOperationID";
public final static String TEST_PORTLET_MESSAGE = "TestPortletMessage";
private final static long MIN_DURATION = 60; // millisec
private final static long MAX_DURATION = 1000; // millisec
@ -72,7 +76,7 @@ public class TestUsageRecord {
ServiceUsageRecord usageRecord = new ServiceUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(OperationResult.SUCCESS);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setCallerHost(TEST_CALLER_HOST);
usageRecord.setHost(TEST_HOST);
@ -107,7 +111,7 @@ public class TestUsageRecord {
StorageUsageRecord usageRecord = new StorageUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(OperationResult.SUCCESS);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setResourceOwner(TEST_RESOUCE_OWNER);
usageRecord.setResourceScope(TEST_RESOUCE_SCOPE);
@ -139,7 +143,7 @@ public class TestUsageRecord {
JobUsageRecord usageRecord = new JobUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_JOB_OPERATION_RESULT);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setJobId(TEST_JOB_ID);
@ -171,7 +175,7 @@ public class TestUsageRecord {
TaskUsageRecord usageRecord = new TaskUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_JOB_OPERATION_RESULT);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setTaskId(TEST_TASK_ID);
usageRecord.setTaskId(TEST_JOB_ID);
@ -205,4 +209,31 @@ public class TestUsageRecord {
return usageRecord;
}
/**
* @return
*/
public static PortletUsageRecord createTestPortletUsageRecord() {
PortletUsageRecord usageRecord = new PortletUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
usageRecord.setPortletId(TEST_PORTLET_ID);
usageRecord.setOperationId(TEST_PORTLET_OPERATION_ID);
usageRecord.setMessage(TEST_PORTLET_MESSAGE);
} catch (InvalidValueException e) {
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
}
return usageRecord;
}
}