package org.gcube.vremanagement.executor.pluginmanager; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.acme.HelloWorldPlugin; import org.acme.HelloWorldPluginDeclaration; import org.gcube.vremanagement.executor.exception.InputsNullException; import org.gcube.vremanagement.executor.exception.InvalidInputsException; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConnector; import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory; import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.plugin.PluginStateNotification; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ * */ public class RunnablePluginTest { private static Logger logger = LoggerFactory.getLogger(SmartExecutorSchedulerTest.class); @Test public void launchNullInputsTest() throws Exception { logger.debug("Testing Null inputs"); UUID uuid = UUID.randomUUID(); HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration(); SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); List pluginStateNotifications = new ArrayList(); pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); try { RunnablePlugin runnablePlugin = new RunnablePlugin(helloWorldPlugin, null, uuid, 1, pluginStateNotifications); runnablePlugin.run(); } catch(Exception e){ Assert.assertEquals(InputsNullException.class, e.getCause().getClass()); } } @Test public void launchEmptyInputsTest() throws Exception { logger.debug("Testing Empty inputs"); Map inputs = new HashMap(); UUID uuid = UUID.randomUUID(); HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration(); SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); List pluginStateNotifications = new ArrayList(); pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); RunnablePlugin pt = new RunnablePlugin(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications); try { pt.run(); } catch(RuntimeException e) { Assert.assertEquals(InvalidInputsException.class, e.getCause().getClass()); } } @Test public void launchValidInputsTest() throws Exception { logger.debug("Testing Some inputs"); Map inputs = new HashMap(); inputs.put("Test", "Test"); long sleepTime = 10000; inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime); UUID uuid = UUID.randomUUID(); HelloWorldPluginDeclaration hwpd = new HelloWorldPluginDeclaration(); SmartExecutorPersistenceConnector persistenceConnector = SmartExecutorPersistenceFactory.getPersistenceConnector(); List pluginStateNotifications = new ArrayList(); pluginStateNotifications.add(persistenceConnector); HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin(hwpd); RunnablePlugin rp = new RunnablePlugin(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications); long startTime = Calendar.getInstance().getTimeInMillis(); long endTime = startTime; while(endTime <= (startTime + 1000)){ endTime = Calendar.getInstance().getTimeInMillis(); } Assert.assertTrue(PluginState.CREATED == persistenceConnector.getPluginInstanceState (uuid, 1).getPluginState()); rp.run(); startTime = Calendar.getInstance().getTimeInMillis(); endTime = startTime; while(endTime <= (startTime + 1000)){ endTime = Calendar.getInstance().getTimeInMillis(); } Assert.assertTrue(PluginState.DONE == persistenceConnector.getPluginInstanceState(uuid, 1).getPluginState()); } }