Added test

This commit is contained in:
Luca Frosini 2019-09-26 12:53:25 +02:00
parent 8eecba49d4
commit dde826073e
1 changed files with 46 additions and 18 deletions

View File

@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.client.query.Discover;
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
import org.gcube.vremanagement.executor.plugin.PluginStateEvolution;
import org.gcube.vremanagement.executor.plugin.ScheduledTask;
@ -46,10 +47,10 @@ public class SmartExecutorClientTest extends ContextTest {
private LaunchParameter getLaunchParameter() {
Scheduling scheduling = new Scheduling(20);
Map<String, Object> inputs = new HashMap<String, Object>();
Map<String,Object> inputs = new HashMap<String,Object>();
inputs.put(HelloWorldPlugin.SLEEP_TIME, TimeUnit.SECONDS.toMillis(10));
inputs.put("TestUUID", UUID.randomUUID());
LaunchParameter launchParameter = new LaunchParameter(HelloWorldPluginDeclaration.NAME, inputs);
launchParameter.setScheduling(scheduling);
@ -60,20 +61,21 @@ public class SmartExecutorClientTest extends ContextTest {
public void testServiceInteraction() throws IOException {
HelloWorldPluginDeclaration helloWorldPluginDeclaration = new HelloWorldPluginDeclaration();
logger.debug("Going to test smart executor using {} plugin", helloWorldPluginDeclaration.getName());
SmartExecutorClient smartExecutorClient = SmartExecutorClientFactory.getClient(helloWorldPluginDeclaration.getName());
SmartExecutorClient smartExecutorClient = SmartExecutorClientFactory
.getClient(helloWorldPluginDeclaration.getName());
String host = smartExecutorClient.getHost();
Assert.assertTrue(host.contains("pc-frosini.isti.cnr.it"));
List<PluginDeclaration> plugins = smartExecutorClient.getPlugins();
Assert.assertTrue(plugins.size()==1);
Assert.assertTrue(plugins.size() == 1);
PluginDeclaration pluginDeclaration = plugins.get(0);
Assert.assertTrue(pluginDeclaration.getName().compareTo(helloWorldPluginDeclaration.getName())==0);
Assert.assertTrue(pluginDeclaration.getDescription().compareTo(helloWorldPluginDeclaration.getDescription())==0);
Assert.assertTrue(pluginDeclaration.getVersion().compareTo(helloWorldPluginDeclaration.getVersion())==0);
Assert.assertTrue(pluginDeclaration.getSupportedCapabilities().equals(helloWorldPluginDeclaration.getSupportedCapabilities()));
Assert.assertTrue(pluginDeclaration.getName().compareTo(helloWorldPluginDeclaration.getName()) == 0);
Assert.assertTrue(
pluginDeclaration.getDescription().compareTo(helloWorldPluginDeclaration.getDescription()) == 0);
Assert.assertTrue(pluginDeclaration.getVersion().compareTo(helloWorldPluginDeclaration.getVersion()) == 0);
Assert.assertTrue(pluginDeclaration.getSupportedCapabilities()
.equals(helloWorldPluginDeclaration.getSupportedCapabilities()));
List<ScheduledTask> orphans = smartExecutorClient.getOrphanScheduledLaunches();
for(ScheduledTask orphan : orphans) {
@ -81,31 +83,57 @@ public class SmartExecutorClientTest extends ContextTest {
Assert.assertTrue(removed);
}
orphans = smartExecutorClient.getOrphanScheduledLaunches();
Assert.assertTrue(orphans.size()==0);
Assert.assertTrue(orphans.size() == 0);
LaunchParameter launchParameter = getLaunchParameter();
UUID executionIdentifier = smartExecutorClient.launch(launchParameter);
List<ScheduledTask> launches = smartExecutorClient.getScheduledLaunches();
Assert.assertTrue(launches.size()==1);
Assert.assertTrue(launches.size() == 1);
ScheduledTask scheduledTask = launches.get(0);
Assert.assertTrue(scheduledTask.getUUID().compareTo(executionIdentifier)==0);
Assert.assertTrue(scheduledTask.getUUID().compareTo(executionIdentifier) == 0);
PluginStateEvolution pluginStateEvolution = smartExecutorClient.getPluginStateEvolution(executionIdentifier);
Assert.assertTrue(pluginStateEvolution.getUUID().compareTo(executionIdentifier)==0);
Assert.assertTrue(pluginStateEvolution.getUUID().compareTo(executionIdentifier) == 0);
pluginStateEvolution = smartExecutorClient.getPluginStateEvolution(executionIdentifier, 1);
Assert.assertTrue(pluginStateEvolution.getUUID().compareTo(executionIdentifier)==0);
Assert.assertTrue(pluginStateEvolution.getUUID().compareTo(executionIdentifier) == 0);
boolean removed = smartExecutorClient.delete(executionIdentifier, true);
Assert.assertTrue(removed);
orphans = smartExecutorClient.getOrphanScheduledLaunches();
Assert.assertTrue(orphans.size()==0);
Assert.assertTrue(orphans.size() == 0);
}
@Test
public void uiTest() throws IOException {
List<String> hosts2Contect = Discover.getInstancesAddress();
boolean first = true;
for(String host : hosts2Contect) {
logger.debug("Host {}", SmartExecutorClientImpl.getHostFromCompleteURL(host));
SmartExecutorClientImpl client = new SmartExecutorClientImpl();
client.setAddress(host);
List<PluginDeclaration> plugins = client.getPlugins();
for(PluginDeclaration p : plugins) {
logger.debug("\tPlugin {}", p);
client.setPluginName(p.getName());
List<ScheduledTask> tasks = client.getScheduledLaunches();
for(ScheduledTask t : tasks) {
logger.debug("\t\tTask {}", t);
}
}
if(first) {
first = false;
List<ScheduledTask> orphansTasks = client.getOrphanScheduledLaunches();
for(ScheduledTask t : orphansTasks) {
logger.debug("Orphan Tasks {}" + t);
}
}
}
}
}