Refactoring Infrastructure Tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@151528 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-08-01 13:56:08 +00:00
parent bfc317f086
commit 03d5e26530
1 changed files with 75 additions and 18 deletions

View File

@ -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<String, Object> 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<String, Object> getRecoveryInputs() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
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<String, Object> getAggregateInputs() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
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<String, Object> 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<String, Object> 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<String, Object> inputs = getRecoveryInputs();
launch(scheduling, inputs);
}
@Test
public void unSchedule() throws Exception {
//proxy.unSchedule("", true);
// proxy.unSchedule("", true);
}
@Test