Implementing One Test Usage Record for each Type
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115557 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
5afd95bfa3
commit
99f823c9bb
|
@ -3,8 +3,13 @@
|
|||
*/
|
||||
package org.gcube.accounting.datamodel;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.implementations.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.implementations.StorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.implementations.StorageUsageRecord.OperationType;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -29,8 +34,8 @@ public class TestUsageRecord {
|
|||
public final static String TEST_PROPERTY_NAME = "TestPropertyName";
|
||||
public final static String TEST_PROPERTY_VALUE = "TestPropertyValue";
|
||||
|
||||
private final static long MIN = 60;
|
||||
private final static long MAX = 1000;
|
||||
private final static long MIN_DURATION = 60; // millisec
|
||||
private final static long MAX_DURATION = 1000; // millisec
|
||||
|
||||
/**
|
||||
* Generate A Random long in a range between min and max.
|
||||
|
@ -42,31 +47,67 @@ public class TestUsageRecord {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a valid SingleUsageRecord
|
||||
* @return the created UsageRecord
|
||||
* Create a valid #ServiceUsageRecord
|
||||
* @return the created #ServiceUsageRecord
|
||||
*/
|
||||
public static SingleUsageRecord createTestUsageRecord() {
|
||||
ServiceUsageRecord serviceUsageRecord = new ServiceUsageRecord();
|
||||
public static ServiceUsageRecord createTestServiceUsageRecord() {
|
||||
ServiceUsageRecord usageRecord = new ServiceUsageRecord();
|
||||
try {
|
||||
serviceUsageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
serviceUsageRecord.setScope(TEST_SCOPE);
|
||||
serviceUsageRecord.setOperationResult(OperationResult.SUCCESS);
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setScope(TEST_SCOPE);
|
||||
usageRecord.setOperationResult(OperationResult.SUCCESS);
|
||||
|
||||
serviceUsageRecord.setServiceClass(TEST_SERVICE_CLASS);
|
||||
serviceUsageRecord.setServiceName(TEST_SERVICE_NAME);
|
||||
usageRecord.setServiceClass(TEST_SERVICE_CLASS);
|
||||
usageRecord.setServiceName(TEST_SERVICE_NAME);
|
||||
|
||||
serviceUsageRecord.setRefHost(TEST_REF_HOST);
|
||||
serviceUsageRecord.setRefVM(TEST_REF_VM);
|
||||
usageRecord.setRefHost(TEST_REF_HOST);
|
||||
usageRecord.setRefVM(TEST_REF_VM);
|
||||
|
||||
serviceUsageRecord.setDuration(generateRandomLong(MIN, MAX));
|
||||
usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
|
||||
|
||||
serviceUsageRecord.setResourceProperty(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
usageRecord.setResourceProperty(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
|
||||
} catch (InvalidValueException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e.getCause());
|
||||
}
|
||||
return serviceUsageRecord;
|
||||
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_OBJECT_URI = "testprotocol://objectURI";
|
||||
|
||||
private final static long MIN_DATA_VOLUME = 1024;
|
||||
private final static long MAX_DATA_VOLUME = 10240;
|
||||
/**
|
||||
* Create a valid #StorageUsageRecord
|
||||
* @return the created #StorageUsageRecord
|
||||
*/
|
||||
public static StorageUsageRecord createTestStorageUsageRecord() {
|
||||
StorageUsageRecord usageRecord = new StorageUsageRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setScope(TEST_SCOPE);
|
||||
usageRecord.setOperationResult(OperationResult.SUCCESS);
|
||||
|
||||
usageRecord.setResourceOwner(TEST_RESOUCE_OWNER);
|
||||
usageRecord.setResourceScope(TEST_RESOUCE_SCOPE);
|
||||
|
||||
usageRecord.setObjectURI(new URI(TEST_OBJECT_URI));
|
||||
usageRecord.setOperationType(OperationType.READ);
|
||||
|
||||
//usageRecord.setDataType();
|
||||
usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
|
||||
|
||||
|
||||
usageRecord.setResourceProperty(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
|
||||
} catch (InvalidValueException | URISyntaxException e) {
|
||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e.getCause());
|
||||
}
|
||||
return usageRecord;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,17 +25,34 @@ public class ServiceUsageRecord extends BasicUsageRecord implements SingleUsageR
|
|||
*/
|
||||
private static final long serialVersionUID = -4214891294699473587L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ValidIP
|
||||
public static final String CALLER_IP = "callerIP";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
public static final String REF_HOST = "refHost";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
public static final String REF_VM = "refVM";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
public static final String SERVICE_CLASS = "serviceClass";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
public static final String SERVICE_NAME = "serviceName";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequiredField @ValidLong
|
||||
public static final String DURATION = "duration";
|
||||
|
||||
|
|
|
@ -33,6 +33,9 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
|
|||
CREATE, READ, UPDATE, DELETE, COPY, MOVE
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
public static final String RESOURCE_OWNER = "resourceOwner";
|
||||
@RequiredField @NotEmpty
|
||||
|
@ -48,6 +51,10 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
|
|||
public static final String OPERATION_TYPE = "operationType";
|
||||
@RequiredField @NotEmpty
|
||||
public static final String DATA_TYPE = "dataType";
|
||||
|
||||
/**
|
||||
* Quantity of data in terms of KB
|
||||
*/
|
||||
@RequiredField @ValidLong
|
||||
public static final String DATA_VOLUME = "dataVolume";
|
||||
|
||||
|
@ -115,11 +122,11 @@ public class StorageUsageRecord extends BasicUsageRecord implements SingleUsageR
|
|||
setResourceProperty(OBJECT_URI, objectURI);
|
||||
}
|
||||
|
||||
public String getOperationType() {
|
||||
return (String) this.resourceProperties.get(OPERATION_TYPE);
|
||||
public OperationType getOperationType() {
|
||||
return (OperationType) this.resourceProperties.get(OPERATION_TYPE);
|
||||
}
|
||||
|
||||
public void setOperationType(String operationType) throws InvalidValueException {
|
||||
public void setOperationType(OperationType operationType) throws InvalidValueException {
|
||||
setResourceProperty(OPERATION_TYPE, operationType);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ public abstract class Persistence {
|
|||
if(persistence==null){
|
||||
persistence = fallback;
|
||||
}
|
||||
persistence.account(TestUsageRecord.createTestUsageRecord());
|
||||
persistence.account(TestUsageRecord.createTestServiceUsageRecord());
|
||||
} catch(Exception e){
|
||||
logger.error("Unable to instance a Persistence Implementation. Using fallback as default",
|
||||
e.getCause());
|
||||
|
|
|
@ -15,7 +15,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToSameObject() throws InvalidValueException {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestUsageRecord();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = usageRecord;
|
||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||
|
@ -23,7 +23,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToEqualsObject() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestUsageRecord();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = BasicUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
|
||||
Assert.assertEquals(0, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(0, ur.compareTo(usageRecord));
|
||||
|
@ -31,7 +31,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToComparedAddedProperty() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestUsageRecord();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = BasicUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
|
||||
for(int i=1; i<31; i++){
|
||||
ur.setResourceProperty(Integer.toString(i), i);
|
||||
|
@ -42,7 +42,7 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToDifferentForAddedProperties() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestUsageRecord();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = BasicUsageRecord.getUsageRecord(usageRecord.getResourceProperties());
|
||||
usageRecord.setResourceProperty(Integer.toString(1), 2);
|
||||
ur.setResourceProperty(Integer.toString(2), 2);
|
||||
|
@ -52,8 +52,8 @@ public class UsageRecordTest {
|
|||
|
||||
@Test
|
||||
public void testCompareToDifferentFromCreation() throws Exception {
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestUsageRecord();
|
||||
UsageRecord ur = TestUsageRecord.createTestUsageRecord();
|
||||
UsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
UsageRecord ur = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertEquals(1, usageRecord.compareTo(ur));
|
||||
Assert.assertEquals(1, ur.compareTo(usageRecord));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord = (ServiceUsageRecord) TestUsageRecord.createTestUsageRecord();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
serviceUsageRecord.validate();
|
||||
logger.debug("ServiceUsageRecord : {}", serviceUsageRecord);
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord2 = (ServiceUsageRecord) TestUsageRecord.createTestUsageRecord();
|
||||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecord();
|
||||
serviceUsageRecord2.validate();
|
||||
logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2);
|
||||
ServiceUsageRecordAggregationStrategy suras = new ServiceUsageRecordAggregationStrategy(aggregated);
|
||||
|
@ -63,7 +63,7 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord = (ServiceUsageRecord) TestUsageRecord.createTestUsageRecord();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
serviceUsageRecord.validate();
|
||||
logger.debug("ServiceUsageRecord : {}", serviceUsageRecord);
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
logger.debug("ServiceUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord2 = (ServiceUsageRecord) TestUsageRecord.createTestUsageRecord();
|
||||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecord();
|
||||
serviceUsageRecord2.validate();
|
||||
logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2);
|
||||
org.gcube.accounting.datamodel.aggregation.ServiceUsageRecord converted2 =
|
||||
|
@ -104,7 +104,7 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
|
||||
ServiceUsageRecord serviceUsageRecord = (ServiceUsageRecord) TestUsageRecord.createTestUsageRecord();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
serviceUsageRecord.validate();
|
||||
logger.debug("ServiceUsageRecord : {}", serviceUsageRecord);
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
|
||||
for(int i=2; i<1002; i++){
|
||||
|
||||
ServiceUsageRecord sur = (ServiceUsageRecord) TestUsageRecord.createTestUsageRecord();
|
||||
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
||||
sur.validate();
|
||||
logger.debug("Cycle ServiceUsageRecord {}: {}", i, sur);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class PersistenceTest {
|
|||
int quantity = 3000;
|
||||
Calendar startTestTime = new GregorianCalendar();
|
||||
for(int i=0; i< quantity; i++){
|
||||
SingleUsageRecord usageRecord = TestUsageRecord.createTestUsageRecord();
|
||||
SingleUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
persistence.account(usageRecord);
|
||||
}
|
||||
Calendar stopTestTime = new GregorianCalendar();
|
||||
|
|
Loading…
Reference in New Issue