Fixing tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@161998 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-01-08 16:12:25 +00:00
parent 92e0101d0f
commit ea1d23c46b
6 changed files with 391 additions and 17 deletions

View File

@ -6,9 +6,10 @@ import java.util.UUID;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.context.ContextElaborator;
import org.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.resourceregistry.context.ContextManagementImpl;
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
/**
* @author Luca Frosini (ISTI - CNR)
@ -17,12 +18,12 @@ public class ContextCreator extends ContextElaborator {
protected Map<String, UUID> contexts;
protected ContextManagementImpl contextManagement;
protected ContextManagement contextManagement;
public ContextCreator() {
super();
contexts = new HashMap<>();
contextManagement = new ContextManagementImpl();
contextManagement = new ContextManagement();
}
@Override
@ -38,9 +39,11 @@ public class ContextCreator extends ContextElaborator {
break;
}
String created = contextManagement.create(parentUUID, scopeBean.name());
Context context = ISMapper.unmarshal(Context.class, created);
Context context = new ContextImpl(scopeBean.name());
context.setParent(parentUUID);
contextManagement.setJSON(ISMapper.marshal(context));
String created = contextManagement.create();
context = ISMapper.unmarshal(Context.class, created);
contexts.put(scopeBean.toString(), context.getHeader().getUUID());
}

View File

@ -71,7 +71,7 @@ public class ScopedTest {
ROOT = properties.getProperty(ROOT_VARNAME);
DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT;
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC;
ALTERNATIVE_TEST_SCOPE = GCUBE_DEVNEXT_NEXTNEXT;
}
public static String getCurrentContext() throws Exception{

View File

@ -0,0 +1,216 @@
/**
*
*/
package org.gcube.vremanagement.executor.rest.client;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.acme.HWPluginStateNotification;
import org.acme.HelloWorldPlugin;
import org.acme.HelloWorldPluginDeclaration;
import org.gcube.testutility.ScopedTest;
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.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;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class DefaultExecutorTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(DefaultExecutorTest.class);
private SmartExecutor smartExecutor;
@Before
public void before() throws Exception{
smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME);
Assert.assertNotNull(smartExecutor);
}
@Test
public void launch() {
Map<String, Object> inputs = new HashMap<String, Object>();
LaunchParameter launchParameter = new LaunchParameter("Test", inputs);
try {
smartExecutor.launch(launchParameter);
} catch (Exception e) {
Assert.assertEquals(PluginNotFoundException.class, e.getCause().getClass());
}
}
@Test
public void getState() {
UUID executionIdentifier = UUID.randomUUID();
try {
smartExecutor.getPluginStateEvolution(executionIdentifier, null);
} catch (Exception e) {
Assert.assertEquals(PluginInstanceNotFoundException.class, e.getCause().getClass());
}
}
@Test
public void testOk() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World");
long sleepTime = TimeUnit.SECONDS.toMillis(10);
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
Map<String, String> notificationInputs = new HashMap<String, String>();
notificationInputs.put("Hello", "Hello World Notification:) :)");
launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs);
try {
UUID executionIdentifier = smartExecutor.launch(launchParameter);
logger.debug("Execution Identifier {}", executionIdentifier.toString());
Thread.sleep(TimeUnit.SECONDS.toMillis(1)); // 1 sec
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
//Thread.sleep(TimeUnit.SECONDS.toMillis(4)); // 1 + 4 sec (total : 5 sec)
//Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(HelloWorldPluginDeclaration.NAME, executionIdentifier, null).getPluginState());
Thread.sleep(TimeUnit.SECONDS.toMillis(6)); // 5 + 6 sec (total : 11 sec)
Assert.assertEquals(PluginState.DONE, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
} catch (Exception e) {
logger.error("testOk Exception", e);
throw e;
}
}
@Test
public void testSerilization() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World");
long sleepTime = TimeUnit.SECONDS.toMillis(20);
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.setGlobal(false);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
Map<String, String> notificationInputs = new HashMap<String, String>();
notificationInputs.put("Hello", "Hello World Notification:) :)");
launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs);
logger.debug(SEMapper.marshal(launchParameter));
}
@Test
public void testScheduledTaskNotPersisted() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World");
long sleepTime = TimeUnit.SECONDS.toMillis(20);
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.setGlobal(false);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
Map<String, String> notificationInputs = new HashMap<String, String>();
notificationInputs.put("Hello", "Hello World Notification:) :)");
launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs);
try {
UUID executionIdentifier = smartExecutor.launch(launchParameter);
Thread.sleep(1000); // 2 sec
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
Thread.sleep(4000); // 8 sec (total : 10 sec)
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
Thread.sleep(6000); // 12 sec (total : 22 sec)
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());
//logger.debug("Trying to stop scheduled task");
//proxy.unSchedule(executionIdentifier, true);
} catch (Exception e) {
logger.error("testOk Exception", e);
throw e;
}
}
@Test
public void testScheduledTaskPersisted() throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World");
long sleepTime = 20000; // 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.setGlobal(true);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
Map<String, String> notificationInputs = new HashMap<String, String>();
notificationInputs.put("Hello", "Hello World Notification:) :)");
launchParameter.addPluginStateNotifications(HWPluginStateNotification.class, notificationInputs);
try {
UUID executionIdentifier = smartExecutor.launch(launchParameter);
logger.debug("Task Lauched with ID : {}", executionIdentifier);
Thread.sleep(1000); // 2 sec
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
Thread.sleep(4000); // 8 sec (total : 10 sec)
Assert.assertEquals(PluginState.RUNNING, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
Thread.sleep(6000); // 12 sec (total : 22 sec)
Assert.assertEquals(PluginState.DONE, smartExecutor.getPluginStateEvolution(executionIdentifier, null).getPluginState());
Thread.sleep(1000*60*5); // 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());
smartExecutor.stop(executionIdentifier);
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));
Thread.sleep(1000*60);
Assert.assertTrue(smartExecutor.unSchedule(executionIdentifier, true));
} catch (Exception e) {
logger.error("testOk Exception", e);
throw e;
}
}
@Test
public void testUnschedule() throws Exception {
//proxy.unSchedule("542ddb03-d8d7-4913-8700-2acfa74c7485", true);
//proxy.unSchedule("37d8f020-cdeb-4b2c-b245-4deabc1fe149", false);
}
}

View File

@ -0,0 +1,154 @@
/**
*
*/
package org.gcube.vremanagement.executor.rest.client;
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.common.clients.exceptions.DiscoveryException;
import org.gcube.testutility.ScopedTest;
import org.gcube.vremanagement.executor.api.rest.SmartExecutor;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.client.Constants;
import org.gcube.vremanagement.executor.client.SmartExecutorClientFactory;
import org.gcube.vremanagement.executor.client.query.Discover;
import org.gcube.vremanagement.executor.client.query.filter.impl.RandomGCoreEndpointQueryFilter;
import org.gcube.vremanagement.executor.client.query.filter.impl.SpecificGCoreEndpointQueryFilter;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class QueriedClientTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(QueriedClientTest.class);
private void launchTest(SmartExecutor smartExecutor) throws Exception {
Map<String,Object> inputs = new HashMap<String,Object>();
inputs.put("Hello", "World");
long sleepTime = 10000;
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
try {
UUID executionIdentifier = smartExecutor.launch(launchParameter);
smartExecutor.getPluginStateEvolution(executionIdentifier, null);
} catch(Exception e) {
throw e;
}
}
@Test
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;
}
}
@Test
public void testWithSingleRighConditions() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
Map<String,String> capabilities = helloWorldPluginDeclaration.getSupportedCapabilities();
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities,
null, null);
Assert.assertNotNull(smartExecutor);
try {
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testWithSingleRighConditions Exception", e);
throw e;
}
}
@Test
public void testWithMultipleRighConditions() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
Map<String,String> capabilities = helloWorldPluginDeclaration.getSupportedCapabilities();
capabilities.put("Version", helloWorldPluginDeclaration.getVersion());
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities,
null, null);
Assert.assertNotNull(smartExecutor);
try {
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testWithMultipleRighConditions Exception", e);
throw e;
}
}
@Test
public void testWithUnsatisfiedConditions() {
Map<String,String> capabilities = new HashMap<>();
capabilities.put("Unsatisfied", "Condition");
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities,
null, null);
Assert.assertNotNull(smartExecutor);
try {
launchTest(smartExecutor);
} catch(Exception e) {
Assert.assertEquals(DiscoveryException.class, e.getClass());
}
}
@Test
public void testManagedPersonalfilters() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
Map<String,String> capabilities = helloWorldPluginDeclaration.getSupportedCapabilities();
SmartExecutor smartExecutor = SmartExecutorClientFactory.create(HelloWorldPluginDeclaration.NAME, capabilities,
null, new RandomGCoreEndpointQueryFilter());
Assert.assertNotNull(smartExecutor);
try {
launchTest(smartExecutor);
} catch(Exception e) {
logger.error("testManagedPersonalfilters Exception", e);
throw e;
}
}
@Test
public void testWithSpecificSelection() throws Exception {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
Map<String,String> capabilities = helloWorldPluginDeclaration.getSupportedCapabilities();
Discover discover = new Discover(Constants.SERVICE_ENTRY_NAME);
List<String> endpoints = discover.getAddresses();
for(String endpoint : endpoints) {
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;
}
}
}
}

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.vremanagement.executor.client;
package org.gcube.vremanagement.executor.soap.client;
import java.util.HashMap;
import java.util.Map;
@ -28,8 +28,8 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
@SuppressWarnings("deprecation")
public class DefaultExecutorTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(DefaultExecutorTest.class);
@ -38,7 +38,7 @@ public class DefaultExecutorTest extends ScopedTest {
@Before
public void before() throws Exception{
proxy = ExecutorPlugin.getExecutorProxy("HelloWorld").build();
proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME).build();
Assert.assertNotNull(proxy);
}
@ -51,7 +51,6 @@ public class DefaultExecutorTest extends ScopedTest {
} catch (Exception e) {
Assert.assertEquals(PluginNotFoundException.class, e.getCause().getClass());
}
}
@Test
@ -80,13 +79,14 @@ public class DefaultExecutorTest extends ScopedTest {
String executionIdentifier = proxy.launch(launchParameter);
logger.debug("Execution Identifier {}", executionIdentifier);
Thread.sleep(1000); // 1 sec
Thread.sleep(TimeUnit.SECONDS.toMillis(1)); // 1 sec
Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState());
Thread.sleep(4000); // 4 sec (total : 5 sec)
Assert.assertEquals(PluginState.RUNNING, proxy.getStateEvolution(executionIdentifier).getPluginState());
Thread.sleep(6000); // 6 sec (total : 11 sec)
//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());
} catch (Exception e) {

View File

@ -1,7 +1,7 @@
/**
*
*/
package org.gcube.vremanagement.executor.client;
package org.gcube.vremanagement.executor.soap.client;
import java.util.HashMap;
import java.util.List;
@ -30,10 +30,11 @@ import org.slf4j.LoggerFactory;
* @author Luca Frosini (ISTI - CNR)
*
*/
@SuppressWarnings("deprecation")
public class QueriedClientTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(QueriedClientTest.class);
private void launchTest(SmartExecutorProxy proxy) throws Exception {
Map<String, Object> inputs = new HashMap<String, Object>();
inputs.put("Hello", "World");