2015-07-28 15:41:35 +02:00
|
|
|
package org.gcube.vremanagement.executor.pluginmanager;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-11-30 12:25:05 +01:00
|
|
|
import java.util.Calendar;
|
2015-07-28 15:41:35 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-05-18 17:33:07 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
2019-02-21 14:12:27 +01:00
|
|
|
import org.gcube.vremanagement.executor.ContextTest;
|
2015-07-28 15:41:35 +02:00
|
|
|
import org.gcube.vremanagement.executor.exception.InputsNullException;
|
|
|
|
import org.gcube.vremanagement.executor.exception.InvalidInputsException;
|
2015-08-26 14:29:00 +02:00
|
|
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector;
|
2015-10-12 18:33:47 +02:00
|
|
|
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
|
2015-07-28 15:41:35 +02:00
|
|
|
import org.gcube.vremanagement.executor.plugin.PluginState;
|
|
|
|
import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
|
2019-09-24 14:59:25 +02:00
|
|
|
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
|
2015-07-28 15:41:35 +02:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
2015-08-26 18:01:58 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2015-07-28 15:41:35 +02:00
|
|
|
|
|
|
|
/**
|
2017-02-01 17:01:15 +01:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2015-07-28 15:41:35 +02:00
|
|
|
*
|
|
|
|
*/
|
2019-02-21 14:12:27 +01:00
|
|
|
public class RunnablePluginTest extends ContextTest {
|
2016-02-09 17:33:06 +01:00
|
|
|
|
2015-08-26 18:01:58 +02:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(SmartExecutorSchedulerTest.class);
|
|
|
|
|
2015-07-28 15:41:35 +02:00
|
|
|
@Test
|
|
|
|
public void launchNullInputsTest() throws Exception {
|
2016-02-09 17:33:06 +01:00
|
|
|
logger.debug("Testing Null inputs");
|
2015-07-28 15:41:35 +02:00
|
|
|
UUID uuid = UUID.randomUUID();
|
2020-09-30 11:19:49 +02:00
|
|
|
|
2015-10-12 18:33:47 +02:00
|
|
|
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
2015-07-28 15:41:35 +02:00
|
|
|
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
|
2015-08-26 14:29:00 +02:00
|
|
|
pluginStateNotifications.add(persistenceConnector);
|
2020-09-30 11:19:49 +02:00
|
|
|
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
|
2015-07-28 15:41:35 +02:00
|
|
|
try {
|
2017-05-18 17:33:07 +02:00
|
|
|
RunnablePlugin<HelloWorldPlugin> runnablePlugin = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, null, uuid, 1, pluginStateNotifications, SecurityTokenProvider.instance.get());
|
2015-07-28 15:41:35 +02:00
|
|
|
runnablePlugin.run();
|
|
|
|
} catch(Exception e){
|
|
|
|
Assert.assertEquals(InputsNullException.class, e.getCause().getClass());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void launchEmptyInputsTest() throws Exception {
|
2016-02-09 17:33:06 +01:00
|
|
|
logger.debug("Testing Empty inputs");
|
2015-07-28 15:41:35 +02:00
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
UUID uuid = UUID.randomUUID();
|
2015-10-12 18:33:47 +02:00
|
|
|
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
2015-07-28 15:41:35 +02:00
|
|
|
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
|
2015-08-26 14:29:00 +02:00
|
|
|
pluginStateNotifications.add(persistenceConnector);
|
2020-09-30 11:19:49 +02:00
|
|
|
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
|
2015-07-28 15:41:35 +02:00
|
|
|
|
2017-05-18 17:33:07 +02:00
|
|
|
RunnablePlugin<HelloWorldPlugin> pt = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,SecurityTokenProvider.instance.get());
|
2015-07-28 15:41:35 +02:00
|
|
|
try {
|
|
|
|
pt.run();
|
|
|
|
} catch(RuntimeException e) {
|
|
|
|
Assert.assertEquals(InvalidInputsException.class, e.getCause().getClass());
|
|
|
|
}
|
2015-08-26 14:29:00 +02:00
|
|
|
|
2015-07-28 15:41:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void launchValidInputsTest() throws Exception {
|
2016-02-09 17:33:06 +01:00
|
|
|
logger.debug("Testing Some inputs");
|
2015-07-28 15:41:35 +02:00
|
|
|
Map<String, Object> inputs = new HashMap<String, Object>();
|
|
|
|
inputs.put("Test", "Test");
|
|
|
|
long sleepTime = 10000;
|
|
|
|
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
|
|
|
|
|
|
|
|
UUID uuid = UUID.randomUUID();
|
2015-10-12 18:33:47 +02:00
|
|
|
SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector();
|
2015-07-28 15:41:35 +02:00
|
|
|
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
|
2015-08-26 14:29:00 +02:00
|
|
|
pluginStateNotifications.add(persistenceConnector);
|
2020-09-30 11:19:49 +02:00
|
|
|
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
|
2017-05-18 17:33:07 +02:00
|
|
|
RunnablePlugin<HelloWorldPlugin> rp = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,SecurityTokenProvider.instance.get());
|
2015-11-30 12:25:05 +01:00
|
|
|
long startTime = Calendar.getInstance().getTimeInMillis();
|
|
|
|
long endTime = startTime;
|
|
|
|
while(endTime <= (startTime + 1000)){
|
|
|
|
endTime = Calendar.getInstance().getTimeInMillis();
|
|
|
|
}
|
2016-09-22 11:31:05 +02:00
|
|
|
Assert.assertTrue(PluginState.CREATED == persistenceConnector.getPluginInstanceState (uuid, 1).getPluginState());
|
2015-07-28 15:41:35 +02:00
|
|
|
|
|
|
|
rp.run();
|
2015-11-30 12:25:05 +01:00
|
|
|
|
|
|
|
startTime = Calendar.getInstance().getTimeInMillis();
|
|
|
|
endTime = startTime;
|
|
|
|
while(endTime <= (startTime + 1000)){
|
|
|
|
endTime = Calendar.getInstance().getTimeInMillis();
|
|
|
|
}
|
2016-09-22 11:31:05 +02:00
|
|
|
Assert.assertTrue(PluginState.DONE == persistenceConnector.getPluginInstanceState(uuid, 1).getPluginState());
|
2015-07-28 15:41:35 +02:00
|
|
|
|
2015-08-26 18:01:58 +02:00
|
|
|
}
|
|
|
|
|
2015-07-28 15:41:35 +02:00
|
|
|
}
|