From e1dffda5a159e4370a1f1f7878f6dc4da3488253 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 10 Feb 2016 13:56:32 +0000 Subject: [PATCH] refs #2222: Move infrastructure tests outside of components junit tests https://support.d4science.org/issues/2222 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics-persistence-couchbase@124037 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 36 +-- ...tingPersistenceQueryConfigurationTest.java | 38 --- ...AccountingPersistenceQueryFactoryTest.java | 259 ------------------ .../analytics/persistence/TestUtility.java | 14 - .../accounting/analytics/utils/IOUtility.java | 23 -- .../testutility/StressTestUtility.java | 40 --- .../accounting/testutility/TestOperation.java | 15 - 7 files changed, 3 insertions(+), 422 deletions(-) delete mode 100644 src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryConfigurationTest.java delete mode 100644 src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java delete mode 100644 src/test/java/org/gcube/accounting/analytics/persistence/TestUtility.java delete mode 100644 src/test/java/org/gcube/accounting/analytics/utils/IOUtility.java delete mode 100644 src/test/java/org/gcube/accounting/testutility/StressTestUtility.java delete mode 100644 src/test/java/org/gcube/accounting/testutility/TestOperation.java diff --git a/pom.xml b/pom.xml index 5eb9086..9b5858c 100644 --- a/pom.xml +++ b/pom.xml @@ -23,44 +23,25 @@ https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId} - - - - org.gcube.distribution - maven-smartgears-bom - LATEST - pom - import - - - - org.gcube.accounting accounting-analytics [1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT) - - - org.gcube.data.publishing - document-store-lib provided org.gcube.accounting accounting-lib + [2.1.0-SNAPSHOT, 3.0.0-SNAPSHOT) provided org.slf4j slf4j-api + 1.7.5 provided - - org.json - json - 20090211 - @@ -71,16 +52,6 @@ - - org.gcube.resources - registry-publisher - test - - - org.gcube.core - common-encryption - test - junit junit @@ -94,6 +65,7 @@ test + @@ -116,6 +88,4 @@ - - \ No newline at end of file diff --git a/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryConfigurationTest.java b/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryConfigurationTest.java deleted file mode 100644 index caa7e3b..0000000 --- a/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryConfigurationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - */ -package org.gcube.accounting.analytics.persistence; - -import org.gcube.accounting.analytics.persistence.couchbase.AccountingPersistenceQueryCouchBase; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - * - */ -public class AccountingPersistenceQueryConfigurationTest { - - private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryConfigurationTest.class); - - @Before - public void before(){ - SecurityTokenProvider.instance.set(TestUtility.TOKEN); - } - - @After - public void after(){ - SecurityTokenProvider.instance.reset(); - } - - @Test - public void test() throws Exception { - AccountingPersistenceBackendQueryConfiguration acbqc = new AccountingPersistenceBackendQueryConfiguration(AccountingPersistenceQueryCouchBase.class); - logger.debug("{}", acbqc); - } - -} diff --git a/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java b/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java deleted file mode 100644 index 4d45f85..0000000 --- a/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java +++ /dev/null @@ -1,259 +0,0 @@ -/** - * - */ -package org.gcube.accounting.analytics.persistence; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.gcube.accounting.analytics.Filter; -import org.gcube.accounting.analytics.Info; -import org.gcube.accounting.analytics.ResourceRecordQuery; -import org.gcube.accounting.analytics.TemporalConstraint; -import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode; -import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; -import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; -import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; -import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; -import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - * - */ -public class AccountingPersistenceQueryFactoryTest { - - private static Logger logger = LoggerFactory.getLogger(AccountingPersistenceQueryFactoryTest.class); - - protected AccountingPersistenceBackendQuery apq; - - @Before - public void before() throws Exception{ - SecurityTokenProvider.instance.set(TestUtility.TOKEN); - apq = AccountingPersistenceBackendQueryFactory.getInstance(); - } - - @After - public void after(){ - SecurityTokenProvider.instance.reset(); - apq = null; - } - - @Test - public void testNullFilters() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3)); - //startTime.setTimeInMillis(new Long("1449829933665")); - startTime.set(Calendar.YEAR, 2015); - startTime.set(Calendar.MONTH, 1); - Calendar endTime = Calendar.getInstance(); - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY); - Map infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, null); - Assert.assertTrue(infos!=null); - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - } - - @Test - public void testEmptyFilters() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3)); - Calendar endTime = Calendar.getInstance(); - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY); - List filters = new ArrayList(); - Map infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters); - Assert.assertTrue(infos!=null); - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - } - - @Test(expected=Exception.class) - public void testFakeFilters() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3)); - Calendar endTime = Calendar.getInstance(); - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY); - List filters = new ArrayList(); - filters.add(new Filter("AUX", "AUX")); - apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters); - } - - - @Test - public void testFiltersGoodKeyFakeValue() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*3)); - Calendar endTime = Calendar.getInstance(); - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY); - List filters = new ArrayList(); - filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS, "AUX")); - Map infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters); - Assert.assertTrue(infos!=null); - Assert.assertTrue(infos.isEmpty()); - } - - - public static final long timeout = 5000; - public static final TimeUnit timeUnit = TimeUnit.MILLISECONDS; - - @Test - public void testFiltersGoodKeyGoodValue() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.setTimeInMillis(startTime.getTimeInMillis()-(1000*60*60*24*365)); - Calendar endTime = Calendar.getInstance(); - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.SECONDLY); - List filters = new ArrayList(); - filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS, TestUsageRecord.TEST_SERVICE_CLASS)); - Map infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters); - Assert.assertTrue(infos!=null); - Assert.assertTrue(!infos.isEmpty()); - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - - filters = new ArrayList(); - filters.add(new Filter(StorageUsageRecord.RESOURCE_OWNER, TestUsageRecord.TEST_RESOUCE_OWNER)); - infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters); - Assert.assertTrue(infos!=null); - Assert.assertTrue(!infos.isEmpty()); - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - - } - - - //@ Test - public void testRange() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.set(Calendar.MONTH, Calendar.AUGUST); - startTime.set(Calendar.DAY_OF_MONTH, 7); - - Calendar endTime = Calendar.getInstance(); - endTime.set(Calendar.MONTH, Calendar.SEPTEMBER); - endTime.set(Calendar.DAY_OF_MONTH, 7); - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.DAILY); - logger.trace("{} : {}", TemporalConstraint.class.getSimpleName(), temporalConstraint.toString()); - - - List filters = new ArrayList(); - /* - filters.add(new Filter(ServiceUsageRecord.SERVICE_CLASS, TestUsageRecord.TEST_SERVICE_CLASS)); - Map infos = apq.query(AggregatedServiceUsageRecord.class, temporalConstraint, filters); - Assert.assertTrue(infos!=null); - Assert.assertTrue(!infos.isEmpty()); - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - */ - - filters = new ArrayList(); - filters.add(new Filter(UsageRecord.CONSUMER_ID, "gianpaolo.coro")); - - AccountingPersistenceBackendQuery apq = AccountingPersistenceBackendQueryFactory.getInstance(); - Map infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters); - Assert.assertTrue(infos!=null); - Assert.assertTrue(!infos.isEmpty()); - - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - - ResourceRecordQuery resourceRecordQuery = new ResourceRecordQuery(); - List padded = resourceRecordQuery.getInfo(AggregatedStorageUsageRecord.class, temporalConstraint, filters, true); - Assert.assertTrue(padded!=null); - Assert.assertTrue(!padded.isEmpty()); - - for(Info info : padded){ - logger.debug(info.toString()); - } - - } - - - @Test - public void getKeysTest() throws Exception { - Set keys = apq.getKeys(AggregatedServiceUsageRecord.class); - logger.debug("Got keys : {}", keys); - - Set required = AggregatedServiceUsageRecord.class.newInstance().getRequiredFields(); - logger.debug("Required fields : {}", required); - - Assert.assertTrue(required.containsAll(keys)); - - } - - - @Test - public void getPossibileValuesTest() throws Exception { - - @SuppressWarnings("rawtypes") - Class[] classes = new Class[]{ - AggregatedServiceUsageRecord.class, - AggregatedStorageUsageRecord.class - }; - - for(@SuppressWarnings("rawtypes") Class cls : classes){ - @SuppressWarnings("unchecked") - Set keys = apq.getKeys(cls); - for(String key : keys){ - logger.debug("Querying Possible values of {} for key {}", cls.getSimpleName(), key); - @SuppressWarnings("unchecked") - Set values = apq.getPossibleValuesForKey(cls, key); - logger.debug("Possible values of {} for key {} : {}", cls.getSimpleName(), key, values); - } - } - - } - - @Test - public void testMontly() throws Exception { - Calendar startTime = Calendar.getInstance(); - startTime.set(Calendar.MONTH, Calendar.JANUARY); - startTime.set(Calendar.DAY_OF_MONTH, 1); - - Calendar endTime = Calendar.getInstance(); - endTime.set(Calendar.MONTH, Calendar.DECEMBER); - endTime.set(Calendar.DAY_OF_MONTH, 31); - - TemporalConstraint temporalConstraint = new TemporalConstraint(startTime.getTimeInMillis(), endTime.getTimeInMillis(), AggregationMode.MONTHLY); - logger.trace("{} : {}", TemporalConstraint.class.getSimpleName(), temporalConstraint.toString()); - - - List filters = new ArrayList(); - AccountingPersistenceBackendQuery apq = AccountingPersistenceBackendQueryFactory.getInstance(); - Map infos = apq.query(AggregatedStorageUsageRecord.class, temporalConstraint, filters); - - Assert.assertTrue(infos!=null); - Assert.assertTrue(!infos.isEmpty()); - - for(Info info : infos.values()){ - logger.debug(info.toString()); - } - - ResourceRecordQuery resourceRecordQuery = new ResourceRecordQuery(); - List padded = resourceRecordQuery.getInfo(AggregatedStorageUsageRecord.class, temporalConstraint, filters, true); - Assert.assertTrue(padded!=null); - Assert.assertTrue(!padded.isEmpty()); - - for(Info info : padded){ - logger.debug(info.toString()); - } - - } - -} diff --git a/src/test/java/org/gcube/accounting/analytics/persistence/TestUtility.java b/src/test/java/org/gcube/accounting/analytics/persistence/TestUtility.java deleted file mode 100644 index e6dd9e1..0000000 --- a/src/test/java/org/gcube/accounting/analytics/persistence/TestUtility.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * - */ -package org.gcube.accounting.analytics.persistence; - -/** - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - * - */ -public class TestUtility { - - public static final String TOKEN = ""; - -} diff --git a/src/test/java/org/gcube/accounting/analytics/utils/IOUtility.java b/src/test/java/org/gcube/accounting/analytics/utils/IOUtility.java deleted file mode 100644 index fc97380..0000000 --- a/src/test/java/org/gcube/accounting/analytics/utils/IOUtility.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.gcube.accounting.analytics.utils; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; - -public abstract class IOUtility { - - public static String readFile(String filePath) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(filePath)); - String line = null; - StringBuilder stringBuilder = new StringBuilder(); - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - reader.close(); - return stringBuilder.toString(); - } - -} diff --git a/src/test/java/org/gcube/accounting/testutility/StressTestUtility.java b/src/test/java/org/gcube/accounting/testutility/StressTestUtility.java deleted file mode 100644 index 7eddd95..0000000 --- a/src/test/java/org/gcube/accounting/testutility/StressTestUtility.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * - */ -package org.gcube.accounting.testutility; - -import java.util.Calendar; -import java.util.GregorianCalendar; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - * - */ -public class StressTestUtility { - - private static final Logger logger = LoggerFactory.getLogger(StressTestUtility.class); - - protected final static int DEFAULT_NUMBER_OF_RECORDS = 3000; - - public static void stressTest(TestOperation operation) throws Exception { - stressTest(operation, DEFAULT_NUMBER_OF_RECORDS); - } - - public static void stressTest(TestOperation operation, int runs) throws Exception { - Calendar startTestTime = new GregorianCalendar(); - for(int i=0; i< runs; i++){ - operation.operate(i); - } - Calendar stopTestTime = new GregorianCalendar(); - double startMillis = startTestTime.getTimeInMillis(); - double stopMillis = stopTestTime.getTimeInMillis(); - double duration = stopMillis - startMillis; - double average = (duration/runs); - logger.debug("Duration (in millisec) : " + duration); - logger.debug("Average (in millisec) : " + average); - } -} diff --git a/src/test/java/org/gcube/accounting/testutility/TestOperation.java b/src/test/java/org/gcube/accounting/testutility/TestOperation.java deleted file mode 100644 index 62406a4..0000000 --- a/src/test/java/org/gcube/accounting/testutility/TestOperation.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - */ -package org.gcube.accounting.testutility; - - -/** - * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ - * - */ -public interface TestOperation { - - public void operate(int i) throws Exception; - -}