From 7204f2574a8043c6e2805982ea77b4371ec54771 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 29 Feb 2016 15:27:46 +0000 Subject: [PATCH] refs #2437: Some records accounted on fallback are not recovered in the proper way in a special case https://support.d4science.org/issues/2437 Added Tests git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124684 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 2 - .../records/RecordUtilityTest.java | 77 +++++++++++++++++++ .../java/org/gcube/test/AccountingTest.java | 6 +- 3 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java diff --git a/pom.xml b/pom.xml index 764970c..0b22621 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,6 @@ org.gcube.data.publishing document-store-lib [1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT) - test org.gcube.data.publishing @@ -40,7 +39,6 @@ org.reflections reflections 0.9.10 - test org.gcube.data.publishing diff --git a/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java b/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java new file mode 100644 index 0000000..8c42ef9 --- /dev/null +++ b/src/test/java/org/gcube/documentstore/records/RecordUtilityTest.java @@ -0,0 +1,77 @@ +/** + * + */ +package org.gcube.documentstore.records; + + +import java.net.URI; + +import org.gcube.accounting.datamodel.UsageRecord.OperationResult; +import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType; +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 RecordUtilityTest { + + private static Logger logger = LoggerFactory.getLogger(RecordUtilityTest.class); + + @Test + public void testImportOldRecord() throws Exception { + String line = "{" + + "resourceScope=/gcube/devsec, " + + "scope=/gcube/devsec, " + + "operationCount=1, " + + "usageRecordType=StorageUsageRecord, " + + "endTime=1448447153009, " + + "consumerId=CSV, " + + "startTime=1448447153009, " + + "id=c7bab219-4024-4019-a8ad-ff5f342b439b, " + + "dataVolume=68, " + + "dataType=STORAGE, " + + "resourceOwner=CSV, " + + "operationResult=SUCCESS, " + + "resourceURI=testprotocol://objectURI, " + + "operationType=CREATE, " + + "aggregated=true, " + + "creationTime=1448447153096, " + + "providerURI=data.d4science.org}"; + + logger.debug(line); + + + Record record = RecordUtility.getRecord(line); + Assert.assertTrue(record instanceof AggregatedStorageUsageRecord); + AggregatedStorageUsageRecord aggregatedStorageUsageRecord = (AggregatedStorageUsageRecord) record; + + Assert.assertTrue(aggregatedStorageUsageRecord.getResourceScope().compareTo("/gcube/devsec")==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getScope().compareTo("/gcube/devsec")==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getOperationCount()==1); + // + Assert.assertTrue(aggregatedStorageUsageRecord.getRecordType().compareTo("StorageUsageRecord")==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getEndTime().getTimeInMillis()==(new Long("1448447153009"))); + Assert.assertTrue(aggregatedStorageUsageRecord.getConsumerId().compareTo("CSV")==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getStartTime().getTimeInMillis()==(new Long("1448447153009"))); + Assert.assertTrue(aggregatedStorageUsageRecord.getId().compareTo("c7bab219-4024-4019-a8ad-ff5f342b439b")==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getDataVolume()==68); + Assert.assertTrue(aggregatedStorageUsageRecord.getDataType()==DataType.STORAGE); + Assert.assertTrue(aggregatedStorageUsageRecord.getResourceOwner().compareTo("CSV")==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getOperationResult()==OperationResult.SUCCESS); + Assert.assertTrue(aggregatedStorageUsageRecord.getResourceURI().compareTo(new URI("testprotocol://objectURI"))==0); + Assert.assertTrue(aggregatedStorageUsageRecord.getOperationType()==OperationType.CREATE); + Assert.assertTrue((Boolean) aggregatedStorageUsageRecord.getResourceProperty(AggregatedStorageUsageRecord.AGGREGATED)); + Assert.assertTrue(aggregatedStorageUsageRecord.getCreationTime().getTimeInMillis()==(new Long("1448447153096"))); + Assert.assertTrue(aggregatedStorageUsageRecord.getProviderURI().compareTo(new URI("data.d4science.org"))==0); + + + logger.debug("{}", aggregatedStorageUsageRecord); + } + +} diff --git a/src/test/java/org/gcube/test/AccountingTest.java b/src/test/java/org/gcube/test/AccountingTest.java index bc81efd..8f107a9 100644 --- a/src/test/java/org/gcube/test/AccountingTest.java +++ b/src/test/java/org/gcube/test/AccountingTest.java @@ -5,6 +5,8 @@ package org.gcube.test; import org.gcube.accounting.persistence.AccountingPersistence; import org.gcube.accounting.persistence.AccountingPersistenceFactory; +import org.gcube.documentstore.records.Record; +import org.gcube.documentstore.records.RecordUtility; import org.gcube.testutility.ScopedTest; import org.junit.Before; import org.junit.Test; @@ -21,13 +23,13 @@ public class AccountingTest extends ScopedTest { protected AccountingPersistence accountingPersistence; - @Before + //@Before public void before() throws Exception { super.before(); AccountingPersistenceFactory.setFallbackLocation("src/test/resources"); accountingPersistence = AccountingPersistenceFactory.getPersistence(); } - + //@Test public void testAccounting() throws Exception { logger.trace("Let See");