diff --git a/src/test/java/org/gcube/vremanagement/executor/rest/client/DefaultExecutorTest.java b/src/test/java/org/gcube/vremanagement/executor/rest/client/DefaultExecutorTest.java index 523e8f3..6ed0530 100644 --- a/src/test/java/org/gcube/vremanagement/executor/rest/client/DefaultExecutorTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/rest/client/DefaultExecutorTest.java @@ -1,6 +1,3 @@ -/** - * - */ package org.gcube.vremanagement.executor.rest.client; import java.util.HashMap; @@ -16,8 +13,8 @@ import org.gcube.vremanagement.executor.api.rest.SmartExecutor; import org.gcube.vremanagement.executor.api.types.LaunchParameter; import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory; +import org.gcube.vremanagement.executor.exception.ExecutorException; import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException; -import org.gcube.vremanagement.executor.exception.PluginNotFoundException; import org.gcube.vremanagement.executor.json.SEMapper; import org.gcube.vremanagement.executor.plugin.PluginState; import org.junit.Assert; @@ -36,29 +33,33 @@ public class DefaultExecutorTest extends ScopedTest { private SmartExecutor smartExecutor; @Before - public void before() throws Exception{ + public void before() throws Exception { smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME); Assert.assertNotNull(smartExecutor); } @Test - public void launch() { + public void launch() throws Exception { Map inputs = new HashMap(); LaunchParameter launchParameter = new LaunchParameter("Test", inputs); try { smartExecutor.launch(launchParameter); + } catch (ExecutorException e) { + // OK } catch (Exception e) { - Assert.assertEquals(PluginNotFoundException.class, e.getCause().getClass()); + throw e; } } @Test - public void getState() { + public void getState() throws Exception { UUID executionIdentifier = UUID.randomUUID(); try { smartExecutor.getPluginStateEvolution(executionIdentifier, null); + } catch (PluginInstanceNotFoundException e) { + // OK } catch (Exception e) { - Assert.assertEquals(PluginInstanceNotFoundException.class, e.getCause().getClass()); + throw e; } } @@ -125,40 +126,41 @@ public class DefaultExecutorTest extends ScopedTest { inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime); int minuteinterval = 2; // Every 5 minutes, for 12 times (one hour totally). - Scheduling scheduling = new Scheduling(60*minuteinterval,12,true); + Scheduling scheduling = new Scheduling(60*minuteinterval,2,true); scheduling.setGlobal(false); LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling); Map notificationInputs = new HashMap(); notificationInputs.put("Hello", "Hello World Notification:) :)"); launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs); + try { UUID executionIdentifier = smartExecutor.launch(launchParameter); - Thread.sleep(1000); // 2 sec + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState()); - Thread.sleep(4000); // 8 sec (total : 10 sec) + Thread.sleep(TimeUnit.SECONDS.toMillis(4)); Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState()); - Thread.sleep(6000); // 12 sec (total : 22 sec) + Thread.sleep(TimeUnit.SECONDS.toMillis(6)); Assert.assertEquals(PluginState.DONE, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState()); - Thread.sleep(1000*60*minuteinterval); // After 5 minutes the thread should be active again - Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState()); - Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, 1).getPluginState()); + // Thread.sleep(1000*60*minuteinterval); // After 5 minutes the thread should be active again + // Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState()); + // Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, 1).getPluginState()); //logger.debug("Trying to stop scheduled task"); //proxy.unSchedule(executionIdentifier, true); } catch (Exception e) { - logger.error("testOk Exception", e); + logger.error("", e); throw e; } } - @Test + // @Test public void testScheduledTaskPersisted() throws Exception { Map inputs = new HashMap(); inputs.put("Hello", "World"); @@ -189,16 +191,16 @@ public class DefaultExecutorTest extends ScopedTest { Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState()); Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, 1).getPluginState()); - smartExecutor.stop(executionIdentifier); + smartExecutor.delete(executionIdentifier, false); Thread.sleep(1000*60*5); // After 5 minutes the thread should be active again. Going to unSchedule globally logger.debug("Trying to stop scheduled task"); - Assert.assertTrue(smartExecutor.unSchedule(executionIdentifier, false)); + Assert.assertTrue(smartExecutor.delete(executionIdentifier, false)); Thread.sleep(1000*60); - Assert.assertTrue(smartExecutor.unSchedule(executionIdentifier, true)); + Assert.assertTrue(smartExecutor.delete(executionIdentifier, true)); } catch (Exception e) { logger.error("testOk Exception", e); @@ -209,8 +211,7 @@ public class DefaultExecutorTest extends ScopedTest { @Test public void testUnschedule() throws Exception { - //proxy.unSchedule("542ddb03-d8d7-4913-8700-2acfa74c7485", true); - //proxy.unSchedule("37d8f020-cdeb-4b2c-b245-4deabc1fe149", false); + // smartExecutor.delete(UUID.fromString("c665f79a-f4b0-46d8-9aa6-51d31c2b1bea"), true); } } diff --git a/src/test/java/org/gcube/vremanagement/executor/rest/client/QueriedClientTest.java b/src/test/java/org/gcube/vremanagement/executor/rest/client/QueriedClientTest.java index 9a76cdf..74cca4e 100644 --- a/src/test/java/org/gcube/vremanagement/executor/rest/client/QueriedClientTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/rest/client/QueriedClientTest.java @@ -42,6 +42,7 @@ public class QueriedClientTest extends ScopedTest { UUID executionIdentifier = smartExecutor.launch(launchParameter); smartExecutor.getPluginStateEvolution(executionIdentifier, null); } catch(Exception e) { + logger.error("", e); throw e; } } @@ -50,12 +51,7 @@ public class QueriedClientTest extends ScopedTest { public void testNoConditions() throws Exception { SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME); Assert.assertNotNull(smartExecutor); - try { - launchTest(smartExecutor); - } catch(Exception e) { - logger.error("testNoConditions Exception", e); - throw e; - } + launchTest(smartExecutor); } @Test @@ -70,7 +66,6 @@ public class QueriedClientTest extends ScopedTest { try { launchTest(smartExecutor); } catch(Exception e) { - logger.error("testWithSingleRighConditions Exception", e); throw e; } } @@ -85,27 +80,22 @@ public class QueriedClientTest extends ScopedTest { null, null); Assert.assertNotNull(smartExecutor); - try { - launchTest(smartExecutor); - } catch(Exception e) { - logger.error("testWithMultipleRighConditions Exception", e); - throw e; - } + launchTest(smartExecutor); } @Test - public void testWithUnsatisfiedConditions() { + public void testWithUnsatisfiedConditions() throws Exception { Map capabilities = new HashMap<>(); capabilities.put("Unsatisfied", "Condition"); - SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities, - null, null); - Assert.assertNotNull(smartExecutor); - try { - launchTest(smartExecutor); + SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, + capabilities, null, null); + Assert.assertNull(smartExecutor); + } catch(DiscoveryException e) { + // OK } catch(Exception e) { - Assert.assertEquals(DiscoveryException.class, e.getClass()); + throw e; } } @@ -118,12 +108,7 @@ public class QueriedClientTest extends ScopedTest { null, new RandomGCoreEndpointQueryFilter()); Assert.assertNotNull(smartExecutor); - try { - launchTest(smartExecutor); - } catch(Exception e) { - logger.error("testManagedPersonalfilters Exception", e); - throw e; - } + launchTest(smartExecutor); } @Test @@ -132,21 +117,14 @@ public class QueriedClientTest extends ScopedTest { Map capabilities = helloWorldPluginDeclaration.getSupportedCapabilities(); Discover discover = new Discover(Constants.SERVICE_ENTRY_NAME); - List endpoints = discover.getAddresses(); - - + List endpoints = discover.getAddresses(); for(String endpoint : endpoints) { - SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities, - null, new SpecificGCoreEndpointQueryFilter(endpoint)); + SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, + capabilities, null, new SpecificGCoreEndpointQueryFilter(endpoint)); Assert.assertNotNull(smartExecutor); - try { - launchTest(smartExecutor); - } catch(Exception e) { - logger.error("testManagedPersonalfilters Exception", e); - throw e; - } + launchTest(smartExecutor); } } diff --git a/src/test/java/org/gcube/vremanagement/executor/soap/client/DefaultExecutorTest.java b/src/test/java/org/gcube/vremanagement/executor/soap/client/DefaultExecutorTest.java index 1c8f120..d71a7af 100644 --- a/src/test/java/org/gcube/vremanagement/executor/soap/client/DefaultExecutorTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/soap/client/DefaultExecutorTest.java @@ -54,14 +54,13 @@ public class DefaultExecutorTest extends ScopedTest { } @Test - public void getState() { + public void getState() throws Exception { String executionIdentifier = UUID.randomUUID().toString(); try { proxy.getStateEvolution(executionIdentifier); } catch (Exception e) { Assert.assertEquals(PluginInstanceNotFoundException.class, e.getCause().getClass()); } - } @Test @@ -83,8 +82,8 @@ public class DefaultExecutorTest extends ScopedTest { Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); - //Thread.sleep(TimeUnit.SECONDS.toMillis(4)); // 1 + 4 sec (total : 5 sec) - //Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); + Thread.sleep(TimeUnit.SECONDS.toMillis(4)); // 1 + 4 sec (total : 5 sec) + Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); Thread.sleep(TimeUnit.SECONDS.toMillis(6)); // 5 + 6 sec (total : 11 sec) Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState()); @@ -119,13 +118,10 @@ public class DefaultExecutorTest extends ScopedTest { @Test - public void testScheduledTaskNotPersisted() throws Exception { - proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build(); - Assert.assertNotNull(proxy); - + public void testScheduledTaskNotPersisted() throws Exception { Map inputs = new HashMap(); inputs.put("Hello", "World"); - long sleepTime = TimeUnit.SECONDS.toMillis(20); + long sleepTime = TimeUnit.SECONDS.toMillis(10); inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime); int minuteinterval = 2; // Every 5 minutes, for 12 times (one hour totally). @@ -139,18 +135,18 @@ public class DefaultExecutorTest extends ScopedTest { try { String executionIdentifier = proxy.launch(launchParameter); - Thread.sleep(1000); // 2 sec + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); - Thread.sleep(4000); // 8 sec (total : 10 sec) + Thread.sleep(TimeUnit.SECONDS.toMillis(4)); Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); - Thread.sleep(6000); // 12 sec (total : 22 sec) + Thread.sleep(TimeUnit.SECONDS.toMillis(6)); Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState()); - Thread.sleep(1000*60*minuteinterval); // After 5 minutes the thread should be active again - Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); - Assert.assertEquals(PluginState.RUNNING, proxy.getIterationStateEvolution(executionIdentifier, 1).getPluginState()); + // Thread.sleep(1000*60*minuteinterval); // After 5 minutes the thread should be active again + // Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); + // Assert.assertEquals(PluginState.RUNNING, proxy.getIterationStateEvolution(executionIdentifier, 1).getPluginState()); //logger.debug("Trying to stop scheduled task"); //proxy.unSchedule(executionIdentifier, true); @@ -162,17 +158,17 @@ public class DefaultExecutorTest extends ScopedTest { } - @Test + //@Test public void testScheduledTaskPersisted() throws Exception { proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build(); Assert.assertNotNull(proxy); Map inputs = new HashMap(); inputs.put("Hello", "World"); - long sleepTime = 20000; // 1000 millisec * 20 = 20 sec + long sleepTime = TimeUnit.SECONDS.toMillis(20); // 1000 millisec * 20 = 20 sec inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime); // Every 5 minutes, for 12 times (one hour totally). - Scheduling scheduling = new Scheduling(60*5,12,true); + Scheduling scheduling = new Scheduling(60*5,2,true); scheduling.setGlobal(true); LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling); @@ -183,15 +179,16 @@ public class DefaultExecutorTest extends ScopedTest { String executionIdentifier = proxy.launch(launchParameter); logger.debug("Task Lauched with ID : {}", executionIdentifier); - Thread.sleep(1000); // 2 sec + Thread.sleep(TimeUnit.SECONDS.toMillis(1)); Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); - Thread.sleep(4000); // 8 sec (total : 10 sec) + Thread.sleep(TimeUnit.SECONDS.toMillis(4)); Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); - Thread.sleep(6000); // 12 sec (total : 22 sec) + Thread.sleep(TimeUnit.SECONDS.toMillis(6)); Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState()); + /* Thread.sleep(1000*60*5); // After 5 minutes the thread should be active again Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); Assert.assertEquals(PluginState.RUNNING, proxy.getIterationStateEvolution(executionIdentifier, 1).getPluginState()); @@ -202,7 +199,7 @@ public class DefaultExecutorTest extends ScopedTest { Thread.sleep(1000*60*5); // After 5 minutes the thread should be active again. Goign to unschedule globally logger.debug("Trying to stop scheduled task"); Assert.assertTrue(proxy.unSchedule(executionIdentifier, false)); - + */ Thread.sleep(1000*60); Assert.assertTrue(proxy.unSchedule(executionIdentifier, true)); diff --git a/src/test/java/org/gcube/vremanagement/executor/soap/client/QueriedClientTest.java b/src/test/java/org/gcube/vremanagement/executor/soap/client/QueriedClientTest.java index 2dd124e..cd3ff58 100644 --- a/src/test/java/org/gcube/vremanagement/executor/soap/client/QueriedClientTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/soap/client/QueriedClientTest.java @@ -64,7 +64,7 @@ public class QueriedClientTest extends ScopedTest { } @Test - public void testWithSingleRighConditions() throws Exception { + public void testWithSingleRightConditions() throws Exception { HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration(); Map map = helloWorldPluginDeclaration.getSupportedCapabilities(); Tuple tuple = new Tuple(); @@ -84,7 +84,7 @@ public class QueriedClientTest extends ScopedTest { } @Test - public void testWithMultipleRighConditions() throws Exception { + public void testWithMultipleRightConditions() throws Exception { HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration(); Map map = helloWorldPluginDeclaration.getSupportedCapabilities();