Repository: oodt Updated Branches: refs/heads/master c60174f5e -> 4c8109b34
OODT-917 tests for WF to validate xMLRPC layer: Tests run: 12, Failures: 0, Errors: 0, Skipped: 1 Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/4c8109b3 Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/4c8109b3 Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/4c8109b3 Branch: refs/heads/master Commit: 4c8109b3426cc69736c98a248528c72bebf686f3 Parents: c60174f Author: Tom Barber <[email protected]> Authored: Thu Nov 5 15:45:59 2015 +0000 Committer: Tom Barber <[email protected]> Committed: Thu Nov 5 15:45:59 2015 +0000 ---------------------------------------------------------------------- .../LuceneWorkflowInstanceRepository.java | 3 - .../workflow/system/XmlRpcWorkflowManager.java | 2 +- .../cas/workflow/util/XmlRpcStructFactory.java | 8 +- .../cas/workflow/util/XmlStructFactory.java | 21 +- .../system/TestXmlRpcWorkflowManagerClient.java | 352 ++++++++++++++++++- 5 files changed, 359 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/4c8109b3/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepository.java ---------------------------------------------------------------------- diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepository.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepository.java index 0e29502..b6c8447 100644 --- a/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepository.java +++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepository.java @@ -53,9 +53,6 @@ import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; -//JDK imports -//Lucene imports -//JUG imports /** * @author mattmann http://git-wip-us.apache.org/repos/asf/oodt/blob/4c8109b3/workflow/src/main/java/org/apache/oodt/cas/workflow/system/XmlRpcWorkflowManager.java ---------------------------------------------------------------------- diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/XmlRpcWorkflowManager.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/XmlRpcWorkflowManager.java index fdf58ca..a733204 100644 --- a/workflow/src/main/java/org/apache/oodt/cas/workflow/system/XmlRpcWorkflowManager.java +++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/system/XmlRpcWorkflowManager.java @@ -264,7 +264,7 @@ public class XmlRpcWorkflowManager { public Map getWorkflowInstanceMetadata(String wInstId) { Metadata met = engine.getWorkflowInstanceMetadata(wInstId); - return met.getMap(); + return met.getHashTable(); } public List getWorkflowsByEvent(String eventName) http://git-wip-us.apache.org/repos/asf/oodt/blob/4c8109b3/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlRpcStructFactory.java ---------------------------------------------------------------------- diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlRpcStructFactory.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlRpcStructFactory.java index 86c2892..303dfde 100644 --- a/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlRpcStructFactory.java +++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlRpcStructFactory.java @@ -129,7 +129,7 @@ public final class XmlRpcStructFactory { .getCurrentTaskEndDateTimeIsoStr() : ""); workflowInstance.put("sharedContext", wInst.getSharedContext() != null ? wInst.getSharedContext() - .getMap() : new Hashtable()); + .getHashTable() : new Hashtable()); workflowInstance.put( "priority", wInst.getPriority() != null ? String.valueOf(wInst.getPriority() @@ -197,12 +197,12 @@ public final class XmlRpcStructFactory { * @return A XML-RPC serializable {@link Vector} of {@link HashMap} * representations of {@link WorkflowInstance}s. */ - public static Vector getXmlRpcWorkflowInstances(List wInsts) { + public static Vector getXmlRpcWorkflowInstances(List<WorkflowInstance> wInsts) { Vector instsVector = new Vector(); if (wInsts != null && wInsts.size() > 0) { - for (Object wInst : wInsts) { - WorkflowInstance inst = (WorkflowInstance) wInst; + for (WorkflowInstance wInst : wInsts) { + WorkflowInstance inst = wInst; instsVector.add(getXmlRpcWorkflowInstance(inst)); } } http://git-wip-us.apache.org/repos/asf/oodt/blob/4c8109b3/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java ---------------------------------------------------------------------- diff --git a/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java b/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java index 3b22d1c..05dec81 100644 --- a/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java +++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java @@ -26,6 +26,7 @@ import org.apache.oodt.cas.workflow.structs.WorkflowConditionConfiguration; import org.apache.oodt.cas.workflow.structs.WorkflowTask; import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration; import org.apache.oodt.commons.exceptions.CommonsException; + import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -33,8 +34,8 @@ import org.w3c.dom.Text; import java.text.ParseException; import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Vector; import java.util.logging.Logger; @@ -66,15 +67,15 @@ public final class XmlStructFactory { * @param node * The XML node to construct the Workflow from. * @param tasks - * The {@link ConcurrentHashMap} of existing {@link WorkflowTask}s. + * The {@link Map} of existing {@link WorkflowTask}s. * * @param conditions - * The {@link ConcurrentHashMap} of existing {@link WorkflowCondition}s. + * The {@link Map} of existing {@link WorkflowCondition}s. * * @return A new {@link Workflow} created from the XML node. */ - public static Workflow getWorkflow(Node node, ConcurrentHashMap tasks, - ConcurrentHashMap conditions) { + public static Workflow getWorkflow(Node node, Map tasks, + Map conditions) { Element workflowRoot = (Element) node; String id = workflowRoot.getAttribute("id"); @@ -100,17 +101,17 @@ public final class XmlStructFactory { /** * <p> * Constructs a new {@link WorkflowTask} from the given XML node and - * {@link ConcurrentHashMap} of {@link WorkflowCondition}s. + * {@link Map} of {@link WorkflowCondition}s. * </p> * * @param node * The XML node to construct the {@link WorkflowTask} from. * @param conditions - * The {@link ConcurrentHashMap} of {@link WorkflowCondition}s to use when + * The {@link Map} of {@link WorkflowCondition}s to use when * constructing the WorkflowTask. * @return A new {@link WorkflowTask} created from the given XML node. */ - public static WorkflowTask getWorkflowTask(Node node, ConcurrentHashMap conditions) { + public static WorkflowTask getWorkflowTask(Node node, Map conditions) { Element taskNode = (Element) node; String taskClassName = taskNode.getAttribute("class"); @@ -257,7 +258,7 @@ public final class XmlStructFactory { return curMetadata; } - private static List<WorkflowTask> getTasks(Element rootNode, ConcurrentHashMap tasks) { + private static List<WorkflowTask> getTasks(Element rootNode, Map tasks) { NodeList taskList = rootNode.getElementsByTagName("task"); List<WorkflowTask> workflowTasks = null; @@ -289,7 +290,7 @@ public final class XmlStructFactory { } private static List<WorkflowCondition> getConditions(Element rootNode, - ConcurrentHashMap conditions) { + Map conditions) { List<WorkflowCondition> conditionList = new Vector<WorkflowCondition>(); NodeList conditionNodes = rootNode.getElementsByTagName("condition"); http://git-wip-us.apache.org/repos/asf/oodt/blob/4c8109b3/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManagerClient.java ---------------------------------------------------------------------- diff --git a/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManagerClient.java b/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManagerClient.java index 95aae66..fe09127 100644 --- a/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManagerClient.java +++ b/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManagerClient.java @@ -18,45 +18,83 @@ package org.apache.oodt.cas.workflow.system; //OODT imports + import org.apache.commons.io.FileUtils; import org.apache.oodt.cas.metadata.Metadata; import org.apache.oodt.cas.workflow.instrepo.LuceneWorkflowInstanceRepository; import org.apache.oodt.cas.workflow.structs.Workflow; import org.apache.oodt.cas.workflow.structs.WorkflowCondition; import org.apache.oodt.cas.workflow.structs.WorkflowInstance; +import org.apache.oodt.cas.workflow.structs.WorkflowInstancePage; import org.apache.oodt.cas.workflow.structs.WorkflowTask; import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration; import org.apache.oodt.cas.workflow.structs.exceptions.InstanceRepositoryException; +import org.apache.oodt.cas.workflow.structs.exceptions.RepositoryException; +import org.apache.xmlrpc.XmlRpcException; + +import org.hamcrest.Matchers; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; -//JDK imports import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; import java.util.List; import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.*; +import static org.hamcrest.collection.IsEmptyCollection.empty; +import static org.junit.Assert.*; -//Junit imports -import junit.framework.TestCase; /** * * Test harness for the {@link XmlRpcWorkflowManagerClient}. * */ -public class TestXmlRpcWorkflowManagerClient extends TestCase { +public class TestXmlRpcWorkflowManagerClient { + + private static final int WM_PORT = 50002; + public static final int MILLIS = 1; + + private static XmlRpcWorkflowManager wmgr; + + private static String luceneCatLoc; + + private static final Logger LOG = Logger + .getLogger(TestXmlRpcWorkflowManager.class.getName()); private static final String catalogPath = new File("./target/instTestMetCat") .getAbsolutePath(); - private LuceneWorkflowInstanceRepository repo = null; - private WorkflowInstance testWrkInst = null; - private Workflow testWrkFlw; - private WorkflowTask testTask; - private WorkflowCondition testCond; + private static LuceneWorkflowInstanceRepository repo = null; + private static WorkflowInstance testWrkInst = null; + private static Workflow testWrkFlw; + private static WorkflowTask testTask; + private static WorkflowCondition testCond; private static final int stdPgSz = 20; public TestXmlRpcWorkflowManagerClient() { + + + } + + @BeforeClass + public static void setup(){ + testWrkInst = new WorkflowInstance(); testWrkFlw = new Workflow(); testTask = new WorkflowTask(); @@ -103,9 +141,189 @@ public class TestXmlRpcWorkflowManagerClient extends TestCase { sharedContext.addMetadata("key2", "val4"); sharedContext.addMetadata("key2", "val5"); testWrkInst.setSharedContext(sharedContext); + startXmlRpcWorkflowManager(); + startWorkflow(); + } + + + private static void startWorkflow() { + XmlRpcWorkflowManagerClient client = null; + try { + client = new XmlRpcWorkflowManagerClient(new URL("http://localhost:" + + WM_PORT)); + } catch (Exception e) { + fail(e.getMessage()); + } + + try { + client.sendEvent("long", new Metadata()); + } catch (Exception e) { + LOG.log(Level.SEVERE, e.getMessage()); + throw new RuntimeException(e); + } + + } + + @AfterClass + public static void cleandown(){ + + stopXmlRpcWorkflowManager(); } + @Test + public void testGetWorkflowInstanceMetadataActuallyUsingTheXmlRpcWorkflowManagerClient() + throws IOException, RepositoryException, XmlRpcException { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + List<Workflow> workflows = fmc.getWorkflows(); + assertThat(workflows, is(not(empty()))); + + + assertNotNull(workflows.get(0).getName()); + + } + + @Test + public void testGetPages() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + WorkflowInstancePage page = fmc.getFirstPage(); + + assertNotNull(page); + + WorkflowInstancePage lastpage = fmc.getLastPage(); + + assertNotNull(lastpage); + + + WorkflowInstancePage nextpage = fmc.getNextPage(page); + + assertNotNull(nextpage); + + WorkflowInstancePage prevpage = fmc.getPrevPage(nextpage); + + assertNotNull(prevpage); + + } + + @Test + public void testGetWorkflowsByEvent() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + List<Workflow> wflows = fmc.getWorkflowsByEvent("long"); + + assertNotNull(wflows); + + assertThat(wflows, hasSize(2)); + + assertThat(wflows.get(0).getName(), equalTo("Long Workflow")); + + + } + @Test + public void testGetWorkflowInstancesByStatus() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + List<WorkflowInstance> wflows = fmc.getWorkflowInstancesByStatus("QUEUED"); + + assertNotNull(wflows); + + } + @Test + public void testGetWorkflowInstanceMetadata2() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + WorkflowInstance wf = (WorkflowInstance) fmc.getFirstPage().getPageWorkflows().get(0); + + assertThat(wf, is(not(Matchers.nullValue()))); + + + + Metadata meta = fmc.getWorkflowInstanceMetadata(wf.getId()); + + assertNotNull(meta); + + } + @Test + public void testGetWorkflowCurrentTaskWallClockMinutes() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + //fmc.getWorkflowCurrentTaskWallClockMinutes(); + + } + @Test + public void testGetTaskById() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + WorkflowTask task = fmc.getTaskById("urn:oodt:HelloWorld"); + + assertThat(task, is(not(nullValue()))); + + assertThat(task.getTaskName(), equalTo("Hello World")); + + + + } + @Test + public void testGetRegisteredEvents() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + List<String> events = fmc.getRegisteredEvents(); + + assertThat(events, is(not(nullValue()))); + + assertThat(events, hasSize(12)); + + assertThat(events, hasItem("stuck")); + + } + + @Ignore + @Test + public void testGetNumWorkflowInstancesByStatus() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + int inst = fmc.getNumWorkflowInstancesByStatus("QUEUED"); + + fail(); + + } + @Test + public void testGetConditionById() throws Exception { + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + WorkflowCondition cond = fmc.getConditionById("urn:oodt:TrueCondition"); + + assertNotNull(cond); + + assertThat(cond.getConditionName(), equalTo("True Condition")); + + } + + @Test + public void testGetNumWorkflowInstances() throws Exception{ + XmlRpcWorkflowManagerClient fmc = new XmlRpcWorkflowManagerClient(new URL( + "http://localhost:" + WM_PORT)); + + int num = fmc.getNumWorkflowInstances(); + + assertThat(num, is(not(0))); + + + + } + + + @Test public void testGetWorkflowInstanceMetadata() { try { @@ -166,4 +384,120 @@ public class TestXmlRpcWorkflowManagerClient extends TestCase { assertTrue(checkVal4 && checkVal5); } + + + + + private static void startXmlRpcWorkflowManager() { + System.setProperty("java.util.logging.config.file", new File( + "./src/main/resources/logging.properties").getAbsolutePath()); + + try { + System.getProperties().load( + new FileInputStream("./src/main/resources/workflow.properties")); + } catch (Exception e) { + fail(e.getMessage()); + } + try { + luceneCatLoc = Files.createTempDirectory("repo").toString(); + LOG.log(Level.INFO, "Lucene instance repository: [" + luceneCatLoc + "]"); + } catch (Exception e) { + fail(e.getMessage()); + } + + + if (new File(luceneCatLoc).exists()) { + // blow away lucene cat + LOG.log(Level.INFO, "Removing workflow instance repository: [" + + luceneCatLoc + "]"); + try { + FileUtils.deleteDirectory(new File(luceneCatLoc)); + } catch (IOException e) { + fail(e.getMessage()); + } + } + + System + .setProperty("workflow.engine.instanceRep.factory", + "org.apache.oodt.cas.workflow.instrepo.LuceneWorkflowInstanceRepositoryFactory"); + System + .setProperty("org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath", + luceneCatLoc); + + try { + System.setProperty("org.apache.oodt.cas.workflow.repo.dirs", "file://" + + new File("./src/main/resources/examples").getCanonicalPath()); + System.setProperty("org.apache.oodt.cas.workflow.lifecycle.filePath", + new File("./src/main/resources/examples/workflow-lifecycle.xml") + .getCanonicalPath()); + } catch (Exception e) { + fail(e.getMessage()); + } + + try { + wmgr = new XmlRpcWorkflowManager(WM_PORT); + Thread.sleep(MILLIS); + } catch (Exception e) { + LOG.log(Level.SEVERE, e.getMessage()); + fail(e.getMessage()); + } + + } + + + private static void stopXmlRpcWorkflowManager() { + System.setProperty("java.util.logging.config.file", new File( + "./src/main/resources/logging.properties").getAbsolutePath()); + + try { + System.getProperties().load( + new FileInputStream("./src/main/resources/workflow.properties")); + } catch (Exception e) { + fail(e.getMessage()); + } + System + .setProperty("workflow.engine.instanceRep.factory", + "org.apache.oodt.cas.workflow.instrepo.LuceneWorkflowInstanceRepositoryFactory"); + System + .setProperty("org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath", + luceneCatLoc); + + try { + System.setProperty("org.apache.oodt.cas.workflow.repo.dirs", "file://" + + new File("./src/main/resources/examples").getCanonicalPath()); + System.setProperty("org.apache.oodt.cas.workflow.lifecycle.filePath", + new File("./src/main/resources/examples/workflow-lifecycle.xml") + .getCanonicalPath()); + } catch (Exception e) { + fail(e.getMessage()); + } + + try { + wmgr.shutdown(); + } catch (Exception e) { + LOG.log(Level.SEVERE, e.getMessage()); + fail(e.getMessage()); + } + + /** + * Sleep before removing to prevent file not found issues. + */ + + try { + Thread.sleep(MILLIS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (new File(luceneCatLoc).exists()) { + // blow away lucene cat + LOG.log(Level.INFO, "Removing workflow instance repository: [" + + luceneCatLoc + "]"); + try { + FileUtils.deleteDirectory(new File(luceneCatLoc)); + } catch (IOException e) { + fail(e.getMessage()); + } + } + } }
