Refactored tests due to changes on accounting model
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@152891 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
afbc456f5f
commit
612e338645
|
@ -1,7 +1,9 @@
|
|||
package org.gcube.accounting.analytics.persistence.couchbase;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.accounting.aggregator.aggregation.AggregationType;
|
||||
|
@ -77,10 +79,9 @@ public class RemoveOldRecords extends ScopedTest {
|
|||
logger.debug("--View Query: startKey:{} - endKey:{} designDocId:{} - viewName:{}",startKey, endKey,designDocId,viewName);
|
||||
|
||||
|
||||
Bucket[] buckets = new Bucket[] {
|
||||
accountingPersistenceQueryCouchBase.bucketService,
|
||||
accountingPersistenceQueryCouchBase.bucketStorage
|
||||
};
|
||||
List<Bucket> buckets = new ArrayList<Bucket>();
|
||||
|
||||
buckets.add(accountingPersistenceQueryCouchBase.connectionMa.get("ServiceUsageRecord"));
|
||||
|
||||
for(Bucket bucket : buckets){
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ 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;
|
||||
|
@ -32,7 +31,6 @@ public class RecordUtilityTest {
|
|||
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 {
|
||||
|
|
|
@ -79,15 +79,4 @@ public class AccountingTest extends ScopedTest{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.datamodel.usagerecords;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.testutility.ScopedTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class TaskUsageRecordScopedTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(TaskUsageRecordScopedTest.class);
|
||||
|
||||
public static Set<String> getExpectedRequiredFields(){
|
||||
Set<String> expectedRequiredFields = new HashSet<String>();
|
||||
expectedRequiredFields.add(Record.ID);
|
||||
expectedRequiredFields.add(UsageRecord.CONSUMER_ID);
|
||||
expectedRequiredFields.add(UsageRecord.CREATION_TIME);
|
||||
expectedRequiredFields.add(UsageRecord.RECORD_TYPE);
|
||||
expectedRequiredFields.add(UsageRecord.SCOPE);
|
||||
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
||||
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_ID);
|
||||
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_START_TIME);
|
||||
expectedRequiredFields.add(AbstractTaskUsageRecord.TASK_END_TIME);
|
||||
|
||||
return expectedRequiredFields;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFieldsScoped() throws InvalidValueException{
|
||||
TaskUsageRecord usageRecord = TestUsageRecord.createTestTaskUsageRecord();
|
||||
|
||||
Set<String> expectedRequiredFields = TaskUsageRecordTest.getExpectedRequiredFields();
|
||||
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
|
||||
|
||||
Set<String> gotRequiredFields = usageRecord.getRequiredFields();
|
||||
logger.debug("Got Required Fields : {}", gotRequiredFields);
|
||||
|
||||
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
|
||||
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
|
||||
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,20 +3,19 @@
|
|||
*/
|
||||
package org.gcube.accounting.datamodel.usagerecords;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||
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.StorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -28,38 +27,37 @@ import org.slf4j.LoggerFactory;
|
|||
public class TestUsageRecord {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TestUsageRecord.class);
|
||||
|
||||
|
||||
public final static String TEST_CONSUMER_ID = "name.surname";
|
||||
public final static String TEST_SCOPE = "/infrastructure/vo";
|
||||
public final static String TEST_SCOPE_2 = "/infrastructure/vo/vre";
|
||||
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";
|
||||
public final static String TEST_CALLER_QUALIFIER = "TestCalledQualifier";
|
||||
|
||||
public final static String TEST_CALLER_QUALIFIER = "TestCallerQualifier";
|
||||
|
||||
public final static String TEST_CALLER_HOST = "remotehost";
|
||||
public final static String TEST_HOST = "localhost";
|
||||
|
||||
|
||||
public final static String TEST_PROPERTY_NAME = "TestPropertyName";
|
||||
public final static String TEST_PROPERTY_VALUE = "TestPropertyValue";
|
||||
|
||||
|
||||
public final static String TEST_JOB_ID = UUID.randomUUID().toString();
|
||||
public final static String TEST_JOB_NAME = "TestJobName";
|
||||
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 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
|
||||
|
||||
|
||||
static {
|
||||
AccountingPersistenceFactory.initAccountingPackages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate A Random long in a range between min and max.
|
||||
* This function is internally used to set random duration.
|
||||
|
@ -68,7 +66,7 @@ public class TestUsageRecord {
|
|||
public static long generateRandomLong(long min, long max){
|
||||
return min + (int)(Math.random() * ((max - min) + 1));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a valid #ServiceUsageRecord with scope set automatically.
|
||||
* @return the created #ServiceUsageRecord
|
||||
|
@ -78,30 +76,28 @@ public class TestUsageRecord {
|
|||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
usageRecord.setCallerHost(TEST_CALLER_HOST);
|
||||
usageRecord.setHost(TEST_HOST);
|
||||
|
||||
usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER);
|
||||
usageRecord.setServiceClass(TEST_SERVICE_CLASS);
|
||||
usageRecord.setServiceName(TEST_SERVICE_NAME);
|
||||
usageRecord.setCalledMethod(TEST_CALLED_METHOD);
|
||||
usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER);
|
||||
|
||||
|
||||
usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
|
||||
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return usageRecord;
|
||||
|
||||
|
||||
}
|
||||
public final static String TEST_RESOUCE_OWNER = "resource.owner";
|
||||
public final static String TEST_RESOUCE_SCOPE = TEST_SCOPE;
|
||||
|
||||
|
||||
public final static String TEST_RESOURCE_URI = "testprotocol://objectURI";
|
||||
public final static String TEST_PROVIDER_URI = "testprotocol://providerURI";
|
||||
|
||||
|
||||
private final static long MIN_DATA_VOLUME = 1024;
|
||||
private final static long MAX_DATA_VOLUME = 10240;
|
||||
|
||||
|
@ -114,18 +110,18 @@ public class TestUsageRecord {
|
|||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
|
||||
usageRecord.setResourceOwner(TEST_RESOUCE_OWNER);
|
||||
usageRecord.setResourceScope(TEST_RESOUCE_SCOPE);
|
||||
|
||||
|
||||
usageRecord.setResourceURI(new URI(TEST_RESOURCE_URI));
|
||||
usageRecord.setProviderURI(new URI(TEST_PROVIDER_URI));
|
||||
|
||||
|
||||
usageRecord.setOperationType(AbstractStorageUsageRecord.OperationType.READ);
|
||||
usageRecord.setDataType(AbstractStorageUsageRecord.DataType.STORAGE);
|
||||
|
||||
|
||||
usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
|
||||
|
||||
|
||||
usageRecord.setQualifier("image/png");
|
||||
|
||||
|
||||
|
@ -134,108 +130,81 @@ public class TestUsageRecord {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
return usageRecord;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a valid #StorageVolumeUsageRecord with scope set automatically.
|
||||
* @return the created #StorageVolumeUsageRecord
|
||||
*/
|
||||
public static StorageStatusRecord createTestStorageVolumeUsageRecord() {
|
||||
StorageStatusRecord usageRecord = new StorageStatusRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
|
||||
usageRecord.setDataType(AbstractStorageStatusRecord.DataType.STORAGE);
|
||||
usageRecord.setDataCount(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
|
||||
usageRecord.setDataServiceClass("dataServiceClass");
|
||||
usageRecord.setDataServiceName("dataServiceName");
|
||||
usageRecord.setDataServiceId("dataServiceId");
|
||||
usageRecord.setProviderId(new URI(TEST_PROVIDER_URI));
|
||||
|
||||
|
||||
|
||||
} catch (InvalidValueException | URISyntaxException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return usageRecord;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static JobUsageRecord createTestJobUsageRecord() {
|
||||
|
||||
|
||||
JobUsageRecord usageRecord = new JobUsageRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
usageRecord.setJobId(TEST_JOB_ID);
|
||||
|
||||
usageRecord.setJobName(TEST_JOB_NAME);
|
||||
usageRecord.setJobQualifier(TEST_JOB_QUALIFIER);
|
||||
|
||||
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
|
||||
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
|
||||
|
||||
usageRecord.setJobStartTime(startTime);
|
||||
usageRecord.setJobEndTime(endTime);
|
||||
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
}
|
||||
|
||||
return usageRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static TaskUsageRecord createTestTaskUsageRecord() {
|
||||
|
||||
TaskUsageRecord usageRecord = new TaskUsageRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
usageRecord.setTaskId(TEST_TASK_ID);
|
||||
usageRecord.setTaskId(TEST_JOB_ID);
|
||||
usageRecord.setHost(TEST_HOST);
|
||||
|
||||
usageRecord.setRefHostingNodeId(UUID.randomUUID().toString());
|
||||
|
||||
Calendar startTime = Calendar.getInstance();
|
||||
Calendar endTime = Calendar.getInstance();
|
||||
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
|
||||
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
|
||||
|
||||
usageRecord.setTaskStartTime(startTime);
|
||||
usageRecord.setTaskEndTime(endTime);
|
||||
|
||||
HashMap<String, Serializable> inputParameters = new HashMap<>();
|
||||
inputParameters.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
inputParameters.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
|
||||
|
||||
HashMap<String, Serializable> parameter = new HashMap<>();
|
||||
parameter.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
parameter.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
|
||||
|
||||
inputParameters.put(TEST_NESTED_MAP, parameter);
|
||||
|
||||
//usageRecord.setInputParameters(inputParameters);
|
||||
|
||||
usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER);
|
||||
usageRecord.setServiceClass(TEST_SERVICE_CLASS);
|
||||
usageRecord.setServiceName(TEST_SERVICE_NAME);
|
||||
usageRecord.setJobName(TEST_JOB_NAME);
|
||||
usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -54,15 +54,4 @@ public class PersistenceCouchBaseTest extends ScopedTest {
|
|||
Assert.assertEquals(0, r.compareTo(record));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonNodeUsageRecordConversionsWithNestedMap() throws Exception {
|
||||
Record record = TestUsageRecord.createTestTaskUsageRecord();
|
||||
logger.debug("UsageRecord : {}", record.toString());
|
||||
JsonNode node = PersistenceCouchBase.usageRecordToJsonNode(record);
|
||||
logger.debug("Node : {}", node.toString());
|
||||
Record r = PersistenceCouchBase.jsonNodeToUsageRecord(node);
|
||||
Assert.assertEquals(0, record.compareTo(r));
|
||||
Assert.assertEquals(0, r.compareTo(record));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue