From 02a67aa9b84b696c4640d6e0aaaef7b2b9ef40dd Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 8 Mar 2024 11:45:19 +0100 Subject: [PATCH] Fixed Test --- .../AccountingAggregatorPluginTest.java | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) 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 238c707..93a21ff 100644 --- a/src/test/java/org/gcube/accounting/aggregator/plugin/AccountingAggregatorPluginTest.java +++ b/src/test/java/org/gcube/accounting/aggregator/plugin/AccountingAggregatorPluginTest.java @@ -2,9 +2,7 @@ package org.gcube.accounting.aggregator.plugin; import java.util.Calendar; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.gcube.accounting.aggregator.ContextTest; @@ -77,36 +75,13 @@ public class AccountingAggregatorPluginTest extends ContextTest { } -// @Ignore - @Test - public void aggregateRecordDaily() throws Exception { - Set types = new HashSet<>(); - types.add(ServiceUsageRecord.class.newInstance().getRecordType()); - types.add(StorageUsageRecord.class.newInstance().getRecordType()); - types.add(JobUsageRecord.class.newInstance().getRecordType()); - - boolean forceRestart = true; - boolean forceEarlyAggregation = true; - - for(String recordType : types) { - AggregationType aggregationType = AggregationType.DAILY; - Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2024, Calendar.MARCH, 1); - Calendar end = Utility.getAggregationStartCalendar(2024, Calendar.MARCH, 2); - while (aggregationStartCalendar.before(end)) { - Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); - aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation, false); - aggregationStartCalendar = Calendar.getInstance(); - aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); - } - } - } - @Ignore @Test public void aggregateAllServiceUsageRecord() throws Exception { String recordType = ServiceUsageRecord.class.newInstance().getRecordType(); // aggregateOneShot(recordType); // aggregateEverything(recordType); +// restart(recordType); } @Ignore @@ -114,7 +89,8 @@ public class AccountingAggregatorPluginTest extends ContextTest { public void aggregateAllStorageStatusRecord() throws Exception { String recordType = StorageStatusRecord.class.newInstance().getRecordType(); // aggregateOneShot(recordType); -// aggregateEverything(recordType); +// aggregateEverything(recordType); +// restart(recordType); } @Ignore @@ -122,7 +98,8 @@ public class AccountingAggregatorPluginTest extends ContextTest { public void aggregateAllJobUsageRecord() throws Exception { String recordType = JobUsageRecord.class.newInstance().getRecordType(); // aggregateOneShot(recordType); -// aggregateEverything(recordType); +// aggregateEverything(recordType); +// restart(recordType); } @Ignore @@ -131,9 +108,26 @@ public class AccountingAggregatorPluginTest extends ContextTest { String recordType = StorageUsageRecord.class.newInstance().getRecordType(); // aggregateOneShot(recordType); // aggregateEverything(recordType); +// restart(recordType); + } + + public void restart(String recordType) throws Exception { + boolean forceRestart = true; + boolean forceEarlyAggregation = true; + + Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2024, Calendar.MARCH, 4); + AggregationType aggregationType = AggregationType.DAILY; + Calendar now = Calendar.getInstance(); + Calendar end = Utility.getAggregationStartCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)+1); +// end = Utility.getAggregationStartCalendar(2024, Calendar.MARCH, 1); + while (aggregationStartCalendar.before(end)) { + Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); + aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation, false); + aggregationStartCalendar = Calendar.getInstance(); + aggregationStartCalendar.setTimeInMillis(aggregationEndCalendar.getTimeInMillis()); + } } - public void aggregateOneShot(String recordType) throws Exception { boolean forceRestart = true; boolean forceEarlyAggregation = true; @@ -144,7 +138,6 @@ public class AccountingAggregatorPluginTest extends ContextTest { } public void aggregateEverything(String recordType) throws Exception { - boolean forceRestart = true; boolean forceEarlyAggregation = false; @@ -161,7 +154,7 @@ public class AccountingAggregatorPluginTest extends ContextTest { aggregationType = AggregationType.MONTHLY; aggregationStartCalendar = Calendar.getInstance(); aggregationStartCalendar.setTimeInMillis(end.getTimeInMillis()); - end = Utility.getAggregationStartCalendar(2023, Calendar.NOVEMBER, 1); + end = Utility.getAggregationStartCalendar(2023, Calendar.DECEMBER, 1); while (aggregationStartCalendar.before(end)) { Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, forceEarlyAggregation, false); @@ -171,7 +164,9 @@ public class AccountingAggregatorPluginTest extends ContextTest { aggregationType = AggregationType.DAILY; aggregationStartCalendar = end; - end = Utility.getAggregationStartCalendar(2024, Calendar.FEBRUARY, 29); + Calendar now = Calendar.getInstance(); + end = Utility.getAggregationStartCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); +// end = Utility.getAggregationStartCalendar(2024, Calendar.MARCH, 1); while (aggregationStartCalendar.before(end)) { Calendar aggregationEndCalendar = Utility.getEndCalendarFromStartCalendar(aggregationType, aggregationStartCalendar, 1); aggregate(recordType, aggregationType, aggregationStartCalendar, aggregationEndCalendar, forceRestart, true, false); @@ -181,6 +176,7 @@ public class AccountingAggregatorPluginTest extends ContextTest { } + @Ignore @Test public void testRecovery() throws Exception { Map inputs = new HashMap();