refs #200: Create accouting-lib library
https://support.d4science.org/issues/200 Implementing tests for Aggregation Strategy git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@115585 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
091e0d27d4
commit
10918da739
|
@ -159,7 +159,7 @@ public abstract class BasicUsageRecord implements UsageRecord, Serializable {
|
|||
/**
|
||||
* Initialize variable
|
||||
*/
|
||||
private void init() {
|
||||
protected void init() {
|
||||
this.validation = new HashMap<String, List<FieldAction>>();
|
||||
this.requiredFields = new HashSet<String>();
|
||||
this.aggregatedFields = new HashSet<String>();
|
||||
|
|
|
@ -20,14 +20,18 @@ public class JobUsageRecord extends org.gcube.accounting.datamodel.implementatio
|
|||
*/
|
||||
private static final long serialVersionUID = -3376423316219914682L;
|
||||
|
||||
@Override
|
||||
protected void init(){
|
||||
super.init();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public JobUsageRecord(){
|
||||
super();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public JobUsageRecord(Map<String, Serializable> properties) throws InvalidValueException{
|
||||
super(properties);
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,15 +20,19 @@ public class PortletUsageRecord extends org.gcube.accounting.datamodel.implement
|
|||
* Generated Serial version UID
|
||||
*/
|
||||
private static final long serialVersionUID = 7445526162102677455L;
|
||||
|
||||
|
||||
@Override
|
||||
protected void init(){
|
||||
super.init();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public PortletUsageRecord(){
|
||||
super();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public PortletUsageRecord(Map<String, Serializable> properties) throws InvalidValueException{
|
||||
super(properties);
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,18 +36,18 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.implement
|
|||
@RequiredField @ValidLong @AggregatedField
|
||||
protected static final String MIN_INVOCATION_TIME = "minInvocationTime";
|
||||
|
||||
private void init(){
|
||||
@Override
|
||||
protected void init(){
|
||||
super.init();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public ServiceUsageRecord(){
|
||||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
protected ServiceUsageRecord(Map<String, Serializable> properties) throws InvalidValueException{
|
||||
super(properties);
|
||||
init();
|
||||
}
|
||||
|
||||
public ServiceUsageRecord(org.gcube.accounting.datamodel.implementations.ServiceUsageRecord record) throws InvalidValueException{
|
||||
|
@ -60,7 +60,6 @@ public class ServiceUsageRecord extends org.gcube.accounting.datamodel.implement
|
|||
this.setCreationTime(creationTime);
|
||||
this.setStartTime(creationTime);
|
||||
this.setEndTime(creationTime);
|
||||
init();
|
||||
}
|
||||
|
||||
public int getInvocationCount() {
|
||||
|
|
|
@ -33,19 +33,22 @@ public class StorageUsageRecord extends org.gcube.accounting.datamodel.implement
|
|||
@RequiredField @ValidInteger @AggregatedField
|
||||
public static final String OPERATION_COUNT = "operationCount";
|
||||
|
||||
@Override
|
||||
protected void init(){
|
||||
super.init();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public StorageUsageRecord(){
|
||||
super();
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
public StorageUsageRecord(Map<String, Serializable> properties) throws InvalidValueException{
|
||||
super(properties);
|
||||
this.resourceProperties.put(AGGREGATED, true);
|
||||
}
|
||||
|
||||
protected StorageUsageRecord(org.gcube.accounting.datamodel.implementations.StorageUsageRecord usageRecord) throws InvalidValueException{
|
||||
public StorageUsageRecord(org.gcube.accounting.datamodel.implementations.StorageUsageRecord usageRecord) throws InvalidValueException{
|
||||
super(usageRecord.getResourceProperties());
|
||||
// TODO
|
||||
}
|
||||
|
||||
public int getOperationCount() {
|
||||
|
|
|
@ -39,22 +39,22 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2);
|
||||
ServiceUsageRecordAggregationStrategy suras = new ServiceUsageRecordAggregationStrategy(aggregated);
|
||||
|
||||
long firstduration = serviceUsageRecord.getDuration();
|
||||
long firstDuration = serviceUsageRecord.getDuration();
|
||||
long secondDuration = serviceUsageRecord2.getDuration();
|
||||
|
||||
suras.aggregate(serviceUsageRecord2);
|
||||
logger.debug("Resulting Aggregated ServiceUsageRecord: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
Assert.assertTrue(aggregated.getDuration() == ((firstduration + secondDuration)/2));
|
||||
Assert.assertTrue(aggregated.getDuration() == ((firstDuration + secondDuration)/2));
|
||||
Assert.assertTrue(aggregated.getInvocationCount() == 2);
|
||||
|
||||
if(firstduration >= secondDuration){
|
||||
Assert.assertTrue(aggregated.getMaxInvocationTime() == firstduration);
|
||||
if(firstDuration >= secondDuration){
|
||||
Assert.assertTrue(aggregated.getMaxInvocationTime() == firstDuration);
|
||||
Assert.assertTrue(aggregated.getMinInvocationTime() == secondDuration);
|
||||
}else{
|
||||
Assert.assertTrue(aggregated.getMaxInvocationTime() == secondDuration);
|
||||
Assert.assertTrue(aggregated.getMinInvocationTime() == firstduration);
|
||||
Assert.assertTrue(aggregated.getMinInvocationTime() == firstDuration);
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,17 +75,17 @@ public class ServiceUsageRecordAggregationStrategyTest {
|
|||
ServiceUsageRecord serviceUsageRecord2 = TestUsageRecord.createTestServiceUsageRecord();
|
||||
serviceUsageRecord2.validate();
|
||||
logger.debug("ServiceUsageRecord 2 : {}", serviceUsageRecord2);
|
||||
org.gcube.accounting.datamodel.aggregation.ServiceUsageRecord converted2 =
|
||||
org.gcube.accounting.datamodel.aggregation.ServiceUsageRecord converted =
|
||||
new org.gcube.accounting.datamodel.aggregation.ServiceUsageRecord(serviceUsageRecord2);
|
||||
logger.debug("ServiceUsageRecord 2 Converted to Aggregated: {}", converted2);
|
||||
converted2.validate();
|
||||
logger.debug("ServiceUsageRecord 2 Converted to Aggregated: {}", converted);
|
||||
converted.validate();
|
||||
|
||||
ServiceUsageRecordAggregationStrategy suras = new ServiceUsageRecordAggregationStrategy(aggregated);
|
||||
|
||||
long firstduration = aggregated.getDuration();
|
||||
long secondDuration = converted2.getDuration();
|
||||
long secondDuration = converted.getDuration();
|
||||
|
||||
suras.aggregate(converted2);
|
||||
suras.aggregate(converted);
|
||||
logger.debug("Resulting Aggregated ServiceUsageRecord: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.datamodel.aggreagtion.aggregationstrategy;
|
||||
|
||||
import org.gcube.accounting.datamodel.TestUsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.aggregationstrategy.StorageUsageRecordAggregationStrategy;
|
||||
import org.gcube.accounting.datamodel.implementations.StorageUsageRecord;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.accounting.exception.NotAggregatableRecordsExceptions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class StorageUsageRecordAggregationStrategyTest {
|
||||
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageUsageRecordAggregationStrategyTest.class);
|
||||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord.validate();
|
||||
logger.debug("StorageUsageRecord : {}", storageUsageRecord);
|
||||
|
||||
org.gcube.accounting.datamodel.aggregation.StorageUsageRecord aggregated =
|
||||
new org.gcube.accounting.datamodel.aggregation.StorageUsageRecord(storageUsageRecord);
|
||||
logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord2.validate();
|
||||
logger.debug("StorageUsageRecord 2 : {}", storageUsageRecord2);
|
||||
StorageUsageRecordAggregationStrategy suras = new StorageUsageRecordAggregationStrategy(aggregated);
|
||||
|
||||
long firstDataVolume = storageUsageRecord.getDataVolume();
|
||||
long secondDataVolume = storageUsageRecord2.getDataVolume();
|
||||
|
||||
suras.aggregate(storageUsageRecord2);
|
||||
logger.debug("Resulting Aggregated ServiceUsageRecord: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
Assert.assertTrue(aggregated.getDataVolume() == ((firstDataVolume + secondDataVolume)/2));
|
||||
Assert.assertTrue(aggregated.getOperationCount() == 2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord.validate();
|
||||
logger.debug("StorageUsageRecord : {}", storageUsageRecord);
|
||||
|
||||
org.gcube.accounting.datamodel.aggregation.StorageUsageRecord aggregated =
|
||||
new org.gcube.accounting.datamodel.aggregation.StorageUsageRecord(storageUsageRecord);
|
||||
logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord2.validate();
|
||||
logger.debug("StorageUsageRecord 2 : {}", storageUsageRecord2);
|
||||
org.gcube.accounting.datamodel.aggregation.StorageUsageRecord converted =
|
||||
new org.gcube.accounting.datamodel.aggregation.StorageUsageRecord(storageUsageRecord2);
|
||||
logger.debug("StorageUsageRecord Converted to Aggregated: {}", converted);
|
||||
converted.validate();
|
||||
|
||||
|
||||
StorageUsageRecordAggregationStrategy suras = new StorageUsageRecordAggregationStrategy(aggregated);
|
||||
|
||||
long firstDataVolume = aggregated.getDataVolume();
|
||||
long secondDataVolume = converted.getDataVolume();
|
||||
|
||||
suras.aggregate(converted);
|
||||
logger.debug("Resulting Aggregated StorageUsageRecord: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
Assert.assertTrue(aggregated.getDataVolume() == ((firstDataVolume + secondDataVolume)/2));
|
||||
Assert.assertTrue(aggregated.getOperationCount() == 2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord.validate();
|
||||
logger.debug("StorageUsageRecord : {}", storageUsageRecord);
|
||||
|
||||
org.gcube.accounting.datamodel.aggregation.StorageUsageRecord aggregated =
|
||||
new org.gcube.accounting.datamodel.aggregation.StorageUsageRecord(storageUsageRecord);
|
||||
logger.debug("StorageUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
StorageUsageRecordAggregationStrategy suras = new StorageUsageRecordAggregationStrategy(aggregated);
|
||||
|
||||
for(int i=2; i<1002; i++){
|
||||
|
||||
StorageUsageRecord sur = TestUsageRecord.createTestStorageUsageRecord();
|
||||
sur.validate();
|
||||
logger.debug("Cycle StorageUsageRecord {}: {}", i, sur);
|
||||
|
||||
long oldDataVolume = aggregated.getDataVolume();
|
||||
long newDataVolume = sur.getDataVolume();
|
||||
|
||||
suras.aggregate(sur);
|
||||
logger.debug("Resulting Aggregated StorageUsageRecord : {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
Assert.assertTrue(aggregated.getDataVolume() == ((oldDataVolume + newDataVolume)/2));
|
||||
Assert.assertTrue(aggregated.getOperationCount() == i);
|
||||
|
||||
}
|
||||
|
||||
logger.debug("Resulting Aggregated StorageUsageRecord: {}", aggregated);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue