Fixed test

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@162060 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-01-10 16:18:22 +00:00
parent ea1d23c46b
commit 7b5773792a
4 changed files with 60 additions and 84 deletions

View File

@ -1,6 +1,3 @@
/**
*
*/
package org.gcube.vremanagement.executor.rest.client; package org.gcube.vremanagement.executor.rest.client;
import java.util.HashMap; 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.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling; import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory; 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.PluginInstanceNotFoundException;
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
import org.gcube.vremanagement.executor.json.SEMapper; import org.gcube.vremanagement.executor.json.SEMapper;
import org.gcube.vremanagement.executor.plugin.PluginState; import org.gcube.vremanagement.executor.plugin.PluginState;
import org.junit.Assert; import org.junit.Assert;
@ -36,29 +33,33 @@ public class DefaultExecutorTest extends ScopedTest {
private SmartExecutor smartExecutor; private SmartExecutor smartExecutor;
@Before @Before
public void before() throws Exception{ public void before() throws Exception {
smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME); smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME);
Assert.assertNotNull(smartExecutor); Assert.assertNotNull(smartExecutor);
} }
@Test @Test
public void launch() { public void launch() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>(); Map<String, Object> inputs = new HashMap<String, Object>();
LaunchParameter launchParameter = new LaunchParameter("Test", inputs); LaunchParameter launchParameter = new LaunchParameter("Test", inputs);
try { try {
smartExecutor.launch(launchParameter); smartExecutor.launch(launchParameter);
} catch (ExecutorException e) {
// OK
} catch (Exception e) { } catch (Exception e) {
Assert.assertEquals(PluginNotFoundException.class, e.getCause().getClass()); throw e;
} }
} }
@Test @Test
public void getState() { public void getState() throws Exception {
UUID executionIdentifier = UUID.randomUUID(); UUID executionIdentifier = UUID.randomUUID();
try { try {
smartExecutor.getPluginStateEvolution(executionIdentifier, null); smartExecutor.getPluginStateEvolution(executionIdentifier, null);
} catch (PluginInstanceNotFoundException e) {
// OK
} catch (Exception e) { } 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); inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
int minuteinterval = 2; int minuteinterval = 2;
// Every 5 minutes, for 12 times (one hour totally). // 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); scheduling.setGlobal(false);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling); LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
Map<String, String> notificationInputs = new HashMap<String, String>(); Map<String, String> notificationInputs = new HashMap<String, String>();
notificationInputs.put("Hello", "Hello World Notification:) :)"); notificationInputs.put("Hello", "Hello World Notification:) :)");
launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs); launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs);
try { try {
UUID executionIdentifier = smartExecutor.launch(launchParameter); 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()); 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()); 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()); Assert.assertEquals(PluginState.DONE, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
Thread.sleep(1000*60*minuteinterval); // After 5 minutes the thread should be active again // 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, null).getPluginState());
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, 1).getPluginState()); // Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, 1).getPluginState());
//logger.debug("Trying to stop scheduled task"); //logger.debug("Trying to stop scheduled task");
//proxy.unSchedule(executionIdentifier, true); //proxy.unSchedule(executionIdentifier, true);
} catch (Exception e) { } catch (Exception e) {
logger.error("testOk Exception", e); logger.error("", e);
throw e; throw e;
} }
} }
@Test // @Test
public void testScheduledTaskPersisted() throws Exception { public void testScheduledTaskPersisted() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>(); Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World"); 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, null).getPluginState());
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, 1).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 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"); logger.debug("Trying to stop scheduled task");
Assert.assertTrue(smartExecutor.unSchedule(executionIdentifier, false)); Assert.assertTrue(smartExecutor.delete(executionIdentifier, false));
Thread.sleep(1000*60); Thread.sleep(1000*60);
Assert.assertTrue(smartExecutor.unSchedule(executionIdentifier, true)); Assert.assertTrue(smartExecutor.delete(executionIdentifier, true));
} catch (Exception e) { } catch (Exception e) {
logger.error("testOk Exception", e); logger.error("testOk Exception", e);
@ -209,8 +211,7 @@ public class DefaultExecutorTest extends ScopedTest {
@Test @Test
public void testUnschedule() throws Exception { public void testUnschedule() throws Exception {
//proxy.unSchedule("542ddb03-d8d7-4913-8700-2acfa74c7485", true); // smartExecutor.delete(UUID.fromString("c665f79a-f4b0-46d8-9aa6-51d31c2b1bea"), true);
//proxy.unSchedule("37d8f020-cdeb-4b2c-b245-4deabc1fe149", false);
} }
} }

View File

@ -42,6 +42,7 @@ public class QueriedClientTest extends ScopedTest {
UUID executionIdentifier = smartExecutor.launch(launchParameter); UUID executionIdentifier = smartExecutor.launch(launchParameter);
smartExecutor.getPluginStateEvolution(executionIdentifier, null); smartExecutor.getPluginStateEvolution(executionIdentifier, null);
} catch(Exception e) { } catch(Exception e) {
logger.error("", e);
throw e; throw e;
} }
} }
@ -50,12 +51,7 @@ public class QueriedClientTest extends ScopedTest {
public void testNoConditions() throws Exception { public void testNoConditions() throws Exception {
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME); SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME);
Assert.assertNotNull(smartExecutor); Assert.assertNotNull(smartExecutor);
try { launchTest(smartExecutor);
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testNoConditions Exception", e);
throw e;
}
} }
@Test @Test
@ -70,7 +66,6 @@ public class QueriedClientTest extends ScopedTest {
try { try {
launchTest(smartExecutor); launchTest(smartExecutor);
} catch(Exception e) { } catch(Exception e) {
logger.error("testWithSingleRighConditions Exception", e);
throw e; throw e;
} }
} }
@ -85,27 +80,22 @@ public class QueriedClientTest extends ScopedTest {
null, null); null, null);
Assert.assertNotNull(smartExecutor); Assert.assertNotNull(smartExecutor);
try { launchTest(smartExecutor);
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testWithMultipleRighConditions Exception", e);
throw e;
}
} }
@Test @Test
public void testWithUnsatisfiedConditions() { public void testWithUnsatisfiedConditions() throws Exception {
Map<String,String> capabilities = new HashMap<>(); Map<String,String> capabilities = new HashMap<>();
capabilities.put("Unsatisfied", "Condition"); capabilities.put("Unsatisfied", "Condition");
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities,
null, null);
Assert.assertNotNull(smartExecutor);
try { try {
launchTest(smartExecutor); SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME,
capabilities, null, null);
Assert.assertNull(smartExecutor);
} catch(DiscoveryException e) {
// OK
} catch(Exception e) { } catch(Exception e) {
Assert.assertEquals(DiscoveryException.class, e.getClass()); throw e;
} }
} }
@ -118,12 +108,7 @@ public class QueriedClientTest extends ScopedTest {
null, new RandomGCoreEndpointQueryFilter()); null, new RandomGCoreEndpointQueryFilter());
Assert.assertNotNull(smartExecutor); Assert.assertNotNull(smartExecutor);
try { launchTest(smartExecutor);
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testManagedPersonalfilters Exception", e);
throw e;
}
} }
@Test @Test
@ -132,21 +117,14 @@ public class QueriedClientTest extends ScopedTest {
Map<String,String> capabilities = helloWorldPluginDeclaration.getSupportedCapabilities(); Map<String,String> capabilities = helloWorldPluginDeclaration.getSupportedCapabilities();
Discover discover = new Discover(Constants.SERVICE_ENTRY_NAME); Discover discover = new Discover(Constants.SERVICE_ENTRY_NAME);
List<String> endpoints = discover.getAddresses(); List<String> endpoints = discover.getAddresses();
for(String endpoint : endpoints) { for(String endpoint : endpoints) {
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities, SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME,
null, new SpecificGCoreEndpointQueryFilter(endpoint)); capabilities, null, new SpecificGCoreEndpointQueryFilter(endpoint));
Assert.assertNotNull(smartExecutor); Assert.assertNotNull(smartExecutor);
try { launchTest(smartExecutor);
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testManagedPersonalfilters Exception", e);
throw e;
}
} }
} }

View File

@ -54,14 +54,13 @@ public class DefaultExecutorTest extends ScopedTest {
} }
@Test @Test
public void getState() { public void getState() throws Exception {
String executionIdentifier = UUID.randomUUID().toString(); String executionIdentifier = UUID.randomUUID().toString();
try { try {
proxy.getStateEvolution(executionIdentifier); proxy.getStateEvolution(executionIdentifier);
} catch (Exception e) { } catch (Exception e) {
Assert.assertEquals(PluginInstanceNotFoundException.class, e.getCause().getClass()); Assert.assertEquals(PluginInstanceNotFoundException.class, e.getCause().getClass());
} }
} }
@Test @Test
@ -83,8 +82,8 @@ public class DefaultExecutorTest extends ScopedTest {
Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState());
//Thread.sleep(TimeUnit.SECONDS.toMillis(4)); // 1 + 4 sec (total : 5 sec) Thread.sleep(TimeUnit.SECONDS.toMillis(4)); // 1 + 4 sec (total : 5 sec)
//Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState());
Thread.sleep(TimeUnit.SECONDS.toMillis(6)); // 5 + 6 sec (total : 11 sec) Thread.sleep(TimeUnit.SECONDS.toMillis(6)); // 5 + 6 sec (total : 11 sec)
Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState()); Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState());
@ -119,13 +118,10 @@ public class DefaultExecutorTest extends ScopedTest {
@Test @Test
public void testScheduledTaskNotPersisted() throws Exception { public void testScheduledTaskNotPersisted() throws Exception {
proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build();
Assert.assertNotNull(proxy);
Map<String, Object> inputs = new HashMap<String, Object>(); Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World"); inputs.put("Hello", "World");
long sleepTime = TimeUnit.SECONDS.toMillis(20); long sleepTime = TimeUnit.SECONDS.toMillis(10);
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime); inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
int minuteinterval = 2; int minuteinterval = 2;
// Every 5 minutes, for 12 times (one hour totally). // Every 5 minutes, for 12 times (one hour totally).
@ -139,18 +135,18 @@ public class DefaultExecutorTest extends ScopedTest {
try { try {
String executionIdentifier = proxy.launch(launchParameter); String executionIdentifier = proxy.launch(launchParameter);
Thread.sleep(1000); // 2 sec Thread.sleep(TimeUnit.SECONDS.toMillis(1));
Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState()); 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()); 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()); Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState());
Thread.sleep(1000*60*minuteinterval); // After 5 minutes the thread should be active again // 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.getStateEvolution(executionIdentifier).getPluginState());
Assert.assertEquals(PluginState.RUNNING, proxy.getIterationStateEvolution(executionIdentifier, 1).getPluginState()); // Assert.assertEquals(PluginState.RUNNING, proxy.getIterationStateEvolution(executionIdentifier, 1).getPluginState());
//logger.debug("Trying to stop scheduled task"); //logger.debug("Trying to stop scheduled task");
//proxy.unSchedule(executionIdentifier, true); //proxy.unSchedule(executionIdentifier, true);
@ -162,17 +158,17 @@ public class DefaultExecutorTest extends ScopedTest {
} }
@Test //@Test
public void testScheduledTaskPersisted() throws Exception { public void testScheduledTaskPersisted() throws Exception {
proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build(); proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build();
Assert.assertNotNull(proxy); Assert.assertNotNull(proxy);
Map<String, Object> inputs = new HashMap<String, Object>(); Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World"); 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); inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
// Every 5 minutes, for 12 times (one hour totally). // 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); scheduling.setGlobal(true);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling); LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
@ -183,15 +179,16 @@ public class DefaultExecutorTest extends ScopedTest {
String executionIdentifier = proxy.launch(launchParameter); String executionIdentifier = proxy.launch(launchParameter);
logger.debug("Task Lauched with ID : {}", executionIdentifier); 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()); 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()); 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()); Assert.assertEquals(PluginState.DONE, proxy.getStateEvolution(executionIdentifier).getPluginState());
/*
Thread.sleep(1000*60*5); // After 5 minutes the thread should be active again 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.getStateEvolution(executionIdentifier).getPluginState());
Assert.assertEquals(PluginState.RUNNING, proxy.getIterationStateEvolution(executionIdentifier, 1).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 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"); logger.debug("Trying to stop scheduled task");
Assert.assertTrue(proxy.unSchedule(executionIdentifier, false)); Assert.assertTrue(proxy.unSchedule(executionIdentifier, false));
*/
Thread.sleep(1000*60); Thread.sleep(1000*60);
Assert.assertTrue(proxy.unSchedule(executionIdentifier, true)); Assert.assertTrue(proxy.unSchedule(executionIdentifier, true));

View File

@ -64,7 +64,7 @@ public class QueriedClientTest extends ScopedTest {
} }
@Test @Test
public void testWithSingleRighConditions() throws Exception { public void testWithSingleRightConditions() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration(); HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities(); Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
Tuple<String, String> tuple = new Tuple<String, String>(); Tuple<String, String> tuple = new Tuple<String, String>();
@ -84,7 +84,7 @@ public class QueriedClientTest extends ScopedTest {
} }
@Test @Test
public void testWithMultipleRighConditions() throws Exception { public void testWithMultipleRightConditions() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration(); HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities(); Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();