From 03d5e26530a84a2681c5b7f30eac364558ae9d42 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 1 Aug 2017 13:56:08 +0000 Subject: [PATCH] Refactoring Infrastructure Tests git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@151528 82a268e6-3cf1-43bd-a215-b396298e98cf --- ...ntingPluginSmartExecutorSchedulerTest.java | 93 +++++++++++++++---- 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java b/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java index 0ce0f07..4264df9 100644 --- a/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java +++ b/src/test/java/org/gcube/aggregator/plugin/AggregatorAccountingPluginSmartExecutorSchedulerTest.java @@ -3,11 +3,16 @@ */ package org.gcube.aggregator.plugin; +import java.util.Calendar; import java.util.HashMap; import java.util.Map; -import java.util.UUID; +import org.gcube.accounting.aggregator.aggregation.AggregationType; +import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin; +import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPlugin.ElaborationType; import org.gcube.accounting.aggregator.plugin.AccountingAggregatorPluginDeclaration; +import org.gcube.accounting.aggregator.utility.Utility; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.testutility.ScopedTest; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.Scheduling; @@ -25,50 +30,102 @@ public class AggregatorAccountingPluginSmartExecutorSchedulerTest extends Scoped private static Logger logger = LoggerFactory.getLogger(AggregatorAccountingPluginSmartExecutorSchedulerTest.class); private SmartExecutorProxy proxy; - + @Before - public void before() throws Exception{ - proxy = ExecutorPlugin.getExecutorProxy(AccountingAggregatorPluginDeclaration.NAME).build(); + public void before() throws Exception { + proxy = ExecutorPlugin.getExecutorProxy(AccountingAggregatorPluginDeclaration.NAME).build(); Assert.assertNotNull(proxy); } - private Map getInputs() throws Exception { + private String getPersistEndTimeParameter() { + Calendar persistEndTime = Calendar.getInstance(); + persistEndTime.set(Calendar.HOUR_OF_DAY, 19); + persistEndTime.set(Calendar.MINUTE, 00); + String persistEndTimeParameter = AccountingAggregatorPlugin.RECOVERY_END_TIME_DATE_FORMAT + .format(persistEndTime.getTime()); + return persistEndTimeParameter; + } + + private Map getRecoveryInputs() throws Exception { Map inputs = new HashMap(); - - + inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.RECOVERY.name()); + + String persistEndTimeParameter = getPersistEndTimeParameter(); + inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, persistEndTimeParameter); + return inputs; } - - private UUID launch(Scheduling scheduling) throws Exception { + + private Map getAggregateInputs() throws Exception { Map inputs = new HashMap(); - + inputs.put(AccountingAggregatorPlugin.AGGREGATION_TYPE_INPUT_PARAMETER, AggregationType.DAILY.name()); + + inputs.put(AccountingAggregatorPlugin.ELABORATION_TYPE_INPUT_PARAMETER, ElaborationType.AGGREGATE.name()); + + String persistEndTimeParameter = getPersistEndTimeParameter(); + inputs.put(AccountingAggregatorPlugin.PERSIST_END_TIME_INPUT_PARAMETER, persistEndTimeParameter); + + inputs.put(AccountingAggregatorPlugin.RECORD_TYPE_INPUT_PARAMETER, + ServiceUsageRecord.class.newInstance().getRecordType()); + + // Start Aggregation Date + Calendar aggregationStartCalendar = Utility.getAggregationStartCalendar(2017, Calendar.JUNE, + 17); + String aggregationStartDate = AccountingAggregatorPlugin.AGGREGATION_START_DATE_DATE_FORMAT + .format(aggregationStartCalendar.getTime()); + logger.trace("{} : {}", AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, + aggregationStartDate); + inputs.put(AccountingAggregatorPlugin.AGGREGATION_START_DATE_INPUT_PARAMETER, aggregationStartDate); + + inputs.put(AccountingAggregatorPlugin.RESTART_FROM_LAST_AGGREGATION_DATE_INPUT_PARAMETER, true); + + return inputs; + } + + private void launch(Scheduling scheduling, Map inputs) throws Exception { + LaunchParameter launchParameter = new LaunchParameter(AccountingAggregatorPluginDeclaration.NAME, inputs); launchParameter.setScheduling(scheduling); - + try { String uuidString = proxy.launch(launchParameter); logger.debug("Launched with UUID : {}", uuidString); - return UUID.fromString(uuidString); - }catch (Exception e) { + } catch (Exception e) { logger.error("Error while launching {}", e); throw e; } } - + @Test public void cronExpPreviousMustBeTerminated() throws Exception { - CronExpression cronExpression = new CronExpression("0 0 2 * * ?"); // every day at 2:00 + // Every 15 minutes + CronExpression cronExpression = new CronExpression("0 0/15 * 1/1 * ? *"); Scheduling scheduling = new Scheduling(cronExpression, true); scheduling.setGlobal(true); - UUID uuid = launch(scheduling); - + + Map inputs = getAggregateInputs(); + + launch(scheduling, inputs); + } + @Test + public void recovery() throws Exception { + // Every Day at 8:00 + CronExpression cronExpression = new CronExpression("0 0 8 1/1 * ? *"); + Scheduling scheduling = new Scheduling(cronExpression, true); + scheduling.setGlobal(true); + + Map inputs = getRecoveryInputs(); + + launch(scheduling, inputs); + + } @Test public void unSchedule() throws Exception { - //proxy.unSchedule("", true); + // proxy.unSchedule("", true); } @Test