infrastructure-tests/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginSmartExecut...

91 lines
2.6 KiB
Java

/**
*
*/
package org.gcube.informationsystem.exporter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.testutility.ScopedTest;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.quartz.CronExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ISExporterPluginSmartExecutorSchedulerTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(ISExporterPluginSmartExecutorSchedulerTest.class);
private SmartExecutorProxy proxy;
@Before
public void before() throws Exception{
proxy = ExecutorPlugin.getExecutorProxy(ISExporterPluginDeclaration.NAME).build();
Assert.assertNotNull(proxy);
}
public UUID scheduleTest(Scheduling scheduling) throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
logger.debug("Inputs : {}", inputs);
LaunchParameter parameter = new LaunchParameter(ISExporterPluginDeclaration.NAME, inputs);
if(scheduling!=null){
parameter.setScheduling(scheduling);
}
try {
String uuidString = proxy.launch(parameter);
return UUID.fromString(uuidString);
} catch(Exception e){
logger.error("Error launching sheduled task", e);
throw e;
}
}
@Test
public void cronExpPreviousMustBeTerminated() throws Exception {
Map<String, String> tokenMinutes = new HashMap<>();
tokenMinutes.put(ScopedTest.GCUBE, "1");
tokenMinutes.put(ScopedTest.GCUBE_DEVSEC, "20");
tokenMinutes.put(ScopedTest.GCUBE_DEVSEC_DEVVRE, "30");
tokenMinutes.put(ScopedTest.GCUBE_DEVNEXT, "40");
tokenMinutes.put(ScopedTest.GCUBE_DEVNEXT_NEXTNEXT, "50");
for(String token : tokenMinutes.keySet()){
logger.info("\n\n\n-------------------------------------------------------------------------");
ScopedTest.setContext(token);
CronExpression cronExpression = new CronExpression("0 " + tokenMinutes.get(token) + " 0/1 * * ?"); // every hour at tokenMinutes.get(token) minutes
Scheduling scheduling = new Scheduling(cronExpression, true);
scheduling.setGlobal(true);
UUID uuid = scheduleTest(scheduling);
logger.debug("Launched with UUID : {}", uuid);
logger.info("\n\n\n");
}
}
//@Test
public void unSchedule() throws Exception {
proxy.unSchedule(null, true);
}
}