Fixed Test

This commit is contained in:
Luca Frosini 2024-03-08 11:45:19 +01:00
parent daaf484e17
commit 02a67aa9b8
1 changed files with 28 additions and 32 deletions

View File

@ -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<String> 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<String, Object> inputs = new HashMap<String, Object>();