refs #2222: Move infrastructure tests outside of components junit tests
https://support.d4science.org/issues/2222 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124075 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d0487f0ae0
commit
865713b709
15
pom.xml
15
pom.xml
|
@ -93,6 +93,21 @@
|
|||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.acme</groupId>
|
||||
<artifactId>HelloWorldPlugin</artifactId>
|
||||
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>org.gcube.dataanalysis</groupId>
|
||||
<artifactId>smart-generic-worker</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.acme.HelloWorldPlugin;
|
||||
import org.acme.HelloWorldPluginDeclaration;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.utils.TestUtility;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.api.types.Scheduling;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
||||
import org.gcube.vremanagement.executor.exception.PluginInstanceNotFoundException;
|
||||
import org.gcube.vremanagement.executor.exception.PluginNotFoundException;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginState;
|
||||
import org.junit.After;
|
||||
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) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class DefaultExecutorTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DefaultExecutorTest.class);
|
||||
|
||||
private SmartExecutorProxy proxy;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
proxy = ExecutorPlugin.getExecutorProxy().build();
|
||||
Assert.assertNotNull(proxy);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launch() {
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
LaunchParameter launchParameter = new LaunchParameter("Test", inputs);
|
||||
try {
|
||||
proxy.launch(launchParameter);
|
||||
} catch (Exception e) {
|
||||
Assert.assertEquals(PluginNotFoundException.class, e.getCause().getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getState() {
|
||||
String executionIdentifier = UUID.randomUUID().toString();
|
||||
try {
|
||||
proxy.getState(executionIdentifier);
|
||||
} 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 = 10000; // 1000 millisec * 10 = 10 sec
|
||||
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
|
||||
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
|
||||
try {
|
||||
String executionIdentifier = proxy.launch(launchParameter);
|
||||
|
||||
Thread.sleep(1000);
|
||||
Assert.assertEquals(PluginState.RUNNING, proxy.getState(executionIdentifier));
|
||||
|
||||
Thread.sleep(4000);
|
||||
Assert.assertEquals(PluginState.RUNNING, proxy.getState(executionIdentifier));
|
||||
|
||||
Thread.sleep(6000);
|
||||
Assert.assertEquals(PluginState.DONE, proxy.getState(executionIdentifier));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("testOk Exception", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testScheduledTaskNotPersisted() throws Exception {
|
||||
proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put("Hello", "World");
|
||||
long sleepTime = 10000; // 1000 millisec * 10 = 10 sec
|
||||
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
|
||||
// Every 5 minutes, for 12 times (one hour totally).
|
||||
Scheduling scheduling = new Scheduling(60*5,12,false);
|
||||
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
|
||||
|
||||
try {
|
||||
String executionIdentifier = proxy.launch(launchParameter);
|
||||
|
||||
Thread.sleep(1000);
|
||||
Assert.assertEquals(PluginState.RUNNING, proxy.getState(executionIdentifier));
|
||||
|
||||
Thread.sleep(4000);
|
||||
Assert.assertEquals(PluginState.RUNNING, proxy.getState(executionIdentifier));
|
||||
|
||||
Thread.sleep(6000);
|
||||
Assert.assertEquals(PluginState.DONE, proxy.getState(executionIdentifier));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("testOk Exception", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScheduledTaskPersisted() throws Exception {
|
||||
proxy = ExecutorPlugin.getExecutorProxy((new HelloWorldPluginDeclaration()).getName()).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
inputs.put("Hello", "World");
|
||||
long sleepTime = 10000; // 1000 millisec * 10 = 10 sec
|
||||
inputs.put(HelloWorldPlugin.SLEEP_TIME, sleepTime);
|
||||
// Every 5 minutes, for 12 times (one hour totally).
|
||||
Scheduling scheduling = new Scheduling(60*5,12,true);
|
||||
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs, scheduling);
|
||||
|
||||
try {
|
||||
String executionIdentifier = proxy.launch(launchParameter);
|
||||
|
||||
Thread.sleep(1000);
|
||||
Assert.assertEquals(PluginState.RUNNING, proxy.getState(executionIdentifier));
|
||||
|
||||
Thread.sleep(4000);
|
||||
Assert.assertEquals(PluginState.RUNNING, proxy.getState(executionIdentifier));
|
||||
|
||||
Thread.sleep(6000);
|
||||
Assert.assertEquals(PluginState.DONE, proxy.getState(executionIdentifier));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("testOk Exception", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,252 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.acme.HelloWorldPlugin;
|
||||
import org.acme.HelloWorldPluginDeclaration;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.clients.ProxyBuilderImpl;
|
||||
import org.gcube.common.clients.exceptions.DiscoveryException;
|
||||
import org.gcube.utils.TestUtility;
|
||||
import org.gcube.vremanagement.executor.api.SmartExecutor;
|
||||
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.SmartExecutorPluginQuery;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.ListEndpointDiscoveryFilter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.RandomEndpointDiscoveryFilter;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.SpecificEndpointDiscoveryFilter;
|
||||
import org.gcube.vremanagement.executor.client.proxies.SmartExecutorProxy;
|
||||
import org.gcube.vremanagement.executor.client.util.Tuple;
|
||||
import org.junit.After;
|
||||
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) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class QueriedClientTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(QueriedClientTest.class);
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
private void launchTest(SmartExecutorProxy proxy) 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 {
|
||||
String executionIdentifier = proxy.launch(launchParameter);
|
||||
proxy.getState(executionIdentifier);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoConditions() throws Exception {
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testNoConditions Exception", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSingleRighConditions() throws Exception {
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
Tuple<String, String> tuple = new Tuple<String, String>();
|
||||
for(String key : map.keySet()){
|
||||
tuple = new Tuple<String, String>(key, map.get(key));
|
||||
break; // Get only the first
|
||||
}
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuple).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testWithSingleRighConditions Exception", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMultipleRighConditions() throws Exception {
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Tuple<String, String>[] tuples = new Tuple[map.size()+1];
|
||||
int i = 0;
|
||||
for(String key : map.keySet()){
|
||||
tuples[i] = new Tuple<String, String>(key, map.get(key));
|
||||
++i;
|
||||
}
|
||||
|
||||
tuples[i] = new Tuple<String, String>("Version", helloWorldPluginDeclaration.getVersion());
|
||||
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuples).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testWithMultipleRighConditions Exception", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithUnsatisfiedConditions() {
|
||||
Tuple<String, String> tuple = new Tuple<String, String>("Unsatisfied", "Condition");
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuple).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
Assert.assertEquals(DiscoveryException.class, e.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testWithPersonalfilters() throws Exception {
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery query = new SmartExecutorPluginQuery(executorPlugin);
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
Tuple<String, String> tuple = new Tuple<String, String>();
|
||||
for(String key : map.keySet()){
|
||||
tuple = new Tuple<String, String>(key, map.get(key));
|
||||
break; // Get only the first
|
||||
}
|
||||
|
||||
query.addConditions(HelloWorldPluginDeclaration.NAME, tuple);
|
||||
query.setServiceEndpointQueryFilter(null);
|
||||
query.setEndpointDiscoveryFilter(null);
|
||||
|
||||
SmartExecutorProxy proxy = new ProxyBuilderImpl<SmartExecutor, SmartExecutorProxy>(executorPlugin, query).build();
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testWithPersonalfilters Exception", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagedPersonalfilters() throws Exception {
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
@SuppressWarnings("unchecked")
|
||||
Tuple<String, String>[] tuples = new Tuple[map.size()];
|
||||
int i = 0;
|
||||
for(String key : map.keySet()){
|
||||
tuples[i] = new Tuple<String, String>(key, map.get(key));
|
||||
++i;
|
||||
}
|
||||
|
||||
SmartExecutorProxy proxy = ExecutorPlugin.getExecutorProxy(HelloWorldPluginDeclaration.NAME, tuples, null, new RandomEndpointDiscoveryFilter()).build();
|
||||
Assert.assertNotNull(proxy);
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testManagedPersonalfilters Exception", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testWithListfilters() throws Exception {
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery query = new SmartExecutorPluginQuery(executorPlugin);
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
Tuple<String, String> tuple = new Tuple<String, String>();
|
||||
for(String key : map.keySet()){
|
||||
tuple = new Tuple<String, String>(key, map.get(key));
|
||||
break; // Get only the first
|
||||
}
|
||||
|
||||
query.addConditions(HelloWorldPluginDeclaration.NAME, tuple);
|
||||
query.setServiceEndpointQueryFilter(null);
|
||||
query.setEndpointDiscoveryFilter(new ListEndpointDiscoveryFilter());
|
||||
|
||||
SmartExecutorProxy proxy = new ProxyBuilderImpl<SmartExecutor, SmartExecutorProxy>(executorPlugin, query).build();
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testWithListfilters Exception", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testWithSpecificSelection() throws Exception {
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery query = new SmartExecutorPluginQuery(executorPlugin);
|
||||
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
|
||||
Map<String,String> map = helloWorldPluginDeclaration.getSupportedCapabilities();
|
||||
Tuple<String, String> tuple = new Tuple<String, String>();
|
||||
for(String key : map.keySet()){
|
||||
tuple = new Tuple<String, String>(key, map.get(key));
|
||||
break; // Get only the first
|
||||
}
|
||||
|
||||
query.addConditions(HelloWorldPluginDeclaration.NAME, tuple);
|
||||
query.setServiceEndpointQueryFilter(null);
|
||||
List<String> endpoints = query.discoverEndpoints(new ListEndpointDiscoveryFilter());
|
||||
|
||||
for(String endpoint : endpoints){
|
||||
|
||||
ExecutorPlugin runExecutorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery runQuery = new SmartExecutorPluginQuery(runExecutorPlugin);
|
||||
runQuery.addConditions(HelloWorldPluginDeclaration.NAME, tuple);
|
||||
|
||||
SpecificEndpointDiscoveryFilter sedf = new SpecificEndpointDiscoveryFilter(endpoint);
|
||||
runQuery.setEndpointDiscoveryFilter(sedf);
|
||||
SmartExecutorProxy proxy = new ProxyBuilderImpl<SmartExecutor, SmartExecutorProxy>(runExecutorPlugin, runQuery).build();
|
||||
|
||||
try {
|
||||
launchTest(proxy);
|
||||
} catch (Exception e) {
|
||||
logger.error("testWithSpecificSelection Exception", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.vremanagement.executor.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.utils.TestUtility;
|
||||
//import org.gcube.dataanalysis.executor.plugin.GenericWorkerPluginDeclaration;
|
||||
import org.gcube.vremanagement.executor.client.plugins.ExecutorPlugin;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.SmartExecutorPluginQuery;
|
||||
import org.gcube.vremanagement.executor.client.plugins.query.filter.ListEndpointDiscoveryFilter;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class SmartGenericWorkerDiscoveryQuery {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SmartGenericWorkerDiscoveryQuery.class);
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
SecurityTokenProvider.instance.set(TestUtility.TOKEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericWorkerDiscoveryQuery() throws Exception {
|
||||
|
||||
//GenericWorkerPluginDeclaration gwpd = new GenericWorkerPluginDeclaration();
|
||||
|
||||
ExecutorPlugin executorPlugin = new ExecutorPlugin();
|
||||
SmartExecutorPluginQuery query = new SmartExecutorPluginQuery(executorPlugin);
|
||||
|
||||
/*
|
||||
add key_value filter here
|
||||
* Tuple<String, String>[] tuples = new Tuple[n];
|
||||
*
|
||||
* runQuery.addConditions(pluginName, tuples);
|
||||
*/
|
||||
|
||||
//query.addConditions(gwpd.getName());
|
||||
|
||||
/* Used to add extra filter to ServiceEndpoint discovery */
|
||||
query.setServiceEndpointQueryFilter(null);
|
||||
List<String> nodes = query.discoverEndpoints(new ListEndpointDiscoveryFilter());
|
||||
logger.debug("Found the following nodes: {}", nodes);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue