76 lines
2.3 KiB
Java
76 lines
2.3 KiB
Java
|
/**
|
||
|
*
|
||
|
*/
|
||
|
package org.gcube.accounting.couchdb.query;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
import java.util.UUID;
|
||
|
|
||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||
|
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.quartz.CronExpression;
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
|
||
|
/**
|
||
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||
|
*/
|
||
|
public class CouchDBQueryPluginSmartExecutorSchedulerTest {
|
||
|
|
||
|
private static Logger logger = LoggerFactory.getLogger(CouchDBQueryPluginSmartExecutorSchedulerTest.class);
|
||
|
|
||
|
public static final String START = "START";
|
||
|
public static final String END = "END";
|
||
|
|
||
|
public static final String SCOPE = "";
|
||
|
|
||
|
private SmartExecutorProxy proxy;
|
||
|
|
||
|
//@Before
|
||
|
public void before() throws Exception{
|
||
|
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||
|
proxy = ExecutorPlugin.getExecutorProxy(CouchDBQueryPluginDeclaration.NAME).build();
|
||
|
Assert.assertNotNull(proxy);
|
||
|
}
|
||
|
|
||
|
//@After
|
||
|
public void after(){
|
||
|
SecurityTokenProvider.instance.reset();
|
||
|
}
|
||
|
|
||
|
public UUID scheduleTest(Scheduling scheduling, Long sleepTime) throws Exception {
|
||
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
||
|
if(sleepTime==null){
|
||
|
sleepTime = new Long(10*1000); // 10 sec = 10 * 1000 millisec
|
||
|
}
|
||
|
inputs.put(CouchDBQueryPlugin.DELAY_MILLIS, sleepTime);
|
||
|
logger.debug("Inputs : {}", inputs);
|
||
|
|
||
|
LaunchParameter parameter = new LaunchParameter(CouchDBQueryPluginDeclaration.NAME, inputs);
|
||
|
parameter.setScheduling(scheduling);
|
||
|
|
||
|
String uuidString = proxy.launch(parameter);
|
||
|
return UUID.fromString(uuidString);
|
||
|
}
|
||
|
|
||
|
//@Test
|
||
|
public void cronExpPreviousMustBeTerminated() throws Exception {
|
||
|
CronExpression cronExpression = new CronExpression("0 */10 * * * ?"); // every 10 minutes starting from now
|
||
|
Scheduling scheduling = new Scheduling(cronExpression, true);
|
||
|
scheduling.setGlobal(true);
|
||
|
UUID uuid = scheduleTest(scheduling, new Long(1000*60)); // 1 min
|
||
|
logger.debug("Launched with UUID : {}", uuid);
|
||
|
}
|
||
|
|
||
|
//@Test
|
||
|
public void unSchedule() throws Exception {
|
||
|
proxy.unSchedule(null, true);
|
||
|
}
|
||
|
|
||
|
}
|