From 13282e62367e80814dcaf9250aae9a88547ffc62 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 15 Feb 2024 10:30:21 +0100 Subject: [PATCH] Reorganizing tests --- .../accounting/aggregator/ContextTest.java | 2 +- .../AccountingAggregatorPluginTest.java | 206 ++++-------------- src/test/resources/logback-test.xml | 2 +- 3 files changed, 46 insertions(+), 164 deletions(-) diff --git a/src/test/java/org/gcube/accounting/aggregator/ContextTest.java b/src/test/java/org/gcube/accounting/aggregator/ContextTest.java index 367d1a3..5d4da09 100644 --- a/src/test/java/org/gcube/accounting/aggregator/ContextTest.java +++ b/src/test/java/org/gcube/accounting/aggregator/ContextTest.java @@ -162,7 +162,7 @@ public class ContextTest { @BeforeClass public static void beforeClass() throws Exception { - setContextByName(DEFAULT_TEST_SCOPE); + setContextByName(ROOT_PROD); } @AfterClass diff --git a/src/test/java/org/gcube/accounting/aggregator/plugin/AccountingAggregatorPluginTest.java b/src/test/java/org/gcube/accounting/aggregator/plugin/AccountingAggregatorPluginTest.java index 5951c66..e431e58 100644 --- a/src/test/java/org/gcube/accounting/aggregator/plugin/AccountingAggregatorPluginTest.java +++ b/src/test/java/org/gcube/accounting/aggregator/plugin/AccountingAggregatorPluginTest.java @@ -77,170 +77,56 @@ public class AccountingAggregatorPluginTest extends ContextTest { @JsonIgnore @Test - public void aggregateJobUsageRecord() throws Exception { - ContextTest.setContextByName(GCUBE); - // ContextTest.setContextByName(ROOT_PROD); - - String recordType = JobUsageRecord.class.newInstance().getRecordType(); - - boolean allAgregationTypes = true; - boolean forceRerun = false; - boolean forceEarlyAggregation = false; - - if (!allAgregationTypes) { - AggregationType aggregationType = AggregationType.DAILY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2021, Calendar.NOVEMBER, 10); - // Calendar aggregationEndCalendar = - // Utility.getEndCalendarFromStartCalendar(aggregationType, - // aggregationStartCalendar, 1); - Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2021, Calendar.NOVEMBER, 11); - - - aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRerun, forceEarlyAggregation); - } else { - for (AggregationType at : AggregationType.values()) { - aggregate(recordType, at, null, null, forceRerun, forceEarlyAggregation); - } - } - } - - @JsonIgnore - @Test - public void aggregateStorageStatusRecord() throws Exception { - ContextTest.setContextByName(GCUBE); - // ContextTest.setContextByName(ROOT_PROD); - - String recordType = StorageStatusRecord.class.newInstance().getRecordType(); - - boolean allAgregationTypes = false; - boolean forceRerun = false; - boolean forceEarlyAggregation = false; - - if (!allAgregationTypes) { - AggregationType aggregationType = AggregationType.DAILY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2021, Calendar.NOVEMBER, 10); - // Calendar aggregationEndCalendar = - // Utility.getEndCalendarFromStartCalendar(aggregationType, - // aggregationStartCalendar, 1); - Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2021, Calendar.NOVEMBER, 11); - - aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRerun, forceEarlyAggregation); - } else { - for (AggregationType at : AggregationType.values()) { - aggregate(recordType, at, null, null, forceRerun, forceEarlyAggregation); - } - } - } - - @JsonIgnore - @Test - public void aggregateStorageUsageRecord() throws Exception { - ContextTest.setContextByName(GCUBE); - // ContextTest.setContextByName(ROOT_PROD); - - String recordType = StorageUsageRecord.class.newInstance().getRecordType(); - - boolean allAgregationTypes = false; - boolean forceRerun = false; - boolean forceEarlyAggregation = false; - - - if (!allAgregationTypes) { - AggregationType aggregationType = AggregationType.DAILY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2021, Calendar.NOVEMBER, 10); - // Calendar aggregationEndCalendar = - // Utility.getEndCalendarFromStartCalendar(aggregationType, - // aggregationStartCalendar, 1); - Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2021, Calendar.NOVEMBER, 11); - - aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRerun, forceEarlyAggregation); - } else { - for (AggregationType at : AggregationType.values()) { - aggregate(recordType, at, null, null, forceRerun, forceEarlyAggregation); - } - } - } - - // @JsonIgnore - @Test - public void aggregateService() throws Exception { - // ContextTest.setContextByName(GCUBE); - // ContextTest.setContextByName(ROOT_PROD); - + public void aggregateAllServiceUsageRecord() throws Exception { String recordType = ServiceUsageRecord.class.newInstance().getRecordType(); - - boolean allAgregationTypes = false; - boolean forceRerun = true; - boolean forceEarlyAggregation = false; - - if (!allAgregationTypes) { - AggregationType aggregationType = AggregationType.YEARLY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2019, Calendar.JANUARY, 1); - Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); -// Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2015, Calendar.JANUARY, 1); - - aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRerun, forceEarlyAggregation); - } else { - for (AggregationType at : AggregationType.values()) { - aggregate(recordType, at, null, null, forceRerun, forceEarlyAggregation); - } - } + aggregateEverything(recordType); } - @Test - public void aggregateAprilService() throws Exception { - // ContextTest.setContextByName(GCUBE); - // ContextTest.setContextByName(ROOT_PROD); - - String recordType = ServiceUsageRecord.class.newInstance().getRecordType(); - - boolean allAgregationTypes = false; - boolean forceRerun = true; - boolean forceEarlyAggregation = false; - - if (!allAgregationTypes) { - AggregationType aggregationType = AggregationType.MONTHLY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2023, Calendar.APRIL, 1); - Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); -// Calendar aggregationEndCalendar = Utility.getAggregationStartCalendar(2015, Calendar.JANUARY, 1); - - aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRerun, forceEarlyAggregation); - } else { - for (AggregationType at : AggregationType.values()) { - aggregate(recordType, at, null, null, forceRerun, forceEarlyAggregation); - } - } - } - -// @JsonIgnore + @JsonIgnore @Test public void aggregateAllStorageUsageRecord() throws Exception { - // ContextTest.setContextByName(GCUBE); - // ContextTest.setContextByName(ROOT_PROD); - String recordType = StorageUsageRecord.class.newInstance().getRecordType(); - - aggregateAll(recordType); - + aggregateEverything(recordType); } - - public void aggregateAll(String recordType) throws Exception { + + @JsonIgnore + @Test + public void aggregateAllJobUsageRecord() throws Exception { + String recordType = JobUsageRecord.class.newInstance().getRecordType(); + aggregateEverything(recordType); + } + + @Test + public void aggregateAllStorageStatusRecord() throws Exception { + String recordType = StorageStatusRecord.class.newInstance().getRecordType(); + aggregateOneShot(recordType); + // aggregateEverything(recordType); + } + + public void aggregateOneShot(String recordType) throws Exception { + boolean forceRestart = true; + boolean forceEarlyAggregation = false; + AggregationType aggregationType = AggregationType.YEARLY; + Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JANUARY, 1); + Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); + aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation); + } + + public void aggregateEverything(String recordType) throws Exception { boolean forceRestart = true; boolean forceEarlyAggregation = false; AggregationType aggregationType = AggregationType.YEARLY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2020, Calendar.JANUARY, 1); + Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2015, Calendar.JANUARY, 1); Calendar end = Utility.getAggregationStartCalendar(2021, Calendar.JANUARY, 1); -// while (aggregationStartCalendar.before(end)) { -// Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); -// aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation); -// aggregationStartCalendar = Calendar.getInstance(); -// aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); -// -// } - + while (aggregationStartCalendar.before(end)) { + Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); + aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation); + aggregationStartCalendar = Calendar.getInstance(); + aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); + } aggregationType = AggregationType.MONTHLY; aggregationStartCalendar = Calendar.getInstance(); @@ -251,21 +137,17 @@ public class AccountingAggregatorPluginTest extends ContextTest { aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation); aggregationStartCalendar = Calendar.getInstance(); aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); - } aggregationType = AggregationType.DAILY; - aggregationStartCalendar = Calendar.getInstance(); - aggregationStartCalendar.setTimeInMillis(end.getTimeInMillis()); - aggregationStartCalendar = Utility.getAggregationStartCalendar(2024, Calendar.FEBRUARY, 6); - end = Utility.getAggregationStartCalendar(2024, Calendar.FEBRUARY, 9); -// while (aggregationStartCalendar.before(end)) { -// Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); -// aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, true); -// aggregationStartCalendar = Calendar.getInstance(); -// aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); -// -// } + aggregationStartCalendar = end; + end = Utility.getAggregationStartCalendar(2024, Calendar.FEBRUARY, 14); + while (aggregationStartCalendar.before(end)) { + Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); + aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, true); + aggregationStartCalendar = Calendar.getInstance(); + aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); + } } diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index 0e3d02c..c4fa250 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -10,7 +10,7 @@ - +