Author: tpalsulich
Date: Thu Jan 22 00:14:55 2015
New Revision: 1653721
URL: http://svn.apache.org/r1653721
Log:
OODT-762. Migrate workflow test resources.
Added:
oodt/trunk/workflow/src/test/java/
oodt/trunk/workflow/src/test/java/org/
oodt/trunk/workflow/src/test/java/org/apache/
oodt/trunk/workflow/src/test/java/org/apache/oodt/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/TestWorkflowCli.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/UseMockClientCmdLineActionStore.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MetSetterTaskQuerier.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MockProcessorQueue.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/QuerierAndRunnerUtils.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/SimpleTester.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestAsynchronousLocalEngineRunner.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskQuerier.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskRunner.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestThreadPoolWorkflowEngine.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestExternScriptTaskInstance.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/instrepo/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/lifecycle/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/lifecycle/TestWorkflowLifecycleManager.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/repository/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/repository/MockWorkflowRepository.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/repository/TestPackagedWorkflowRepository.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/repository/TestWorkflowDataSourceRepository.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/repository/TestWorkflowRepository.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/structs/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/structs/TestFILOPrioritySorter.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/structs/TestHighestFIFOPrioritySorter.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/structs/TestHighestPrioritySorter.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/structs/TestWorkflowInstance.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/system/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/system/MockXmlRpcWorkflowManagerClient.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManager.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/system/TestXmlRpcWorkflowManagerClient.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/tools/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/tools/TestInstanceRepoCleaner.java
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/util/
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/util/TestGenericWorkflowObjectFactory.java
oodt/trunk/workflow/src/test/resources/
oodt/trunk/workflow/src/test/resources/myScript-Output.txt
oodt/trunk/workflow/src/test/resources/myScript.sh
oodt/trunk/workflow/src/test/resources/test.logging.properties
oodt/trunk/workflow/src/test/resources/testinstrepo/
oodt/trunk/workflow/src/test/resources/testinstrepo/_43.cfs (with props)
oodt/trunk/workflow/src/test/resources/testinstrepo/deletable (with props)
oodt/trunk/workflow/src/test/resources/testinstrepo/segments (with props)
oodt/trunk/workflow/src/test/resources/workflow.sql
Removed:
oodt/trunk/workflow/src/test/org/
oodt/trunk/workflow/src/testdata/
Modified:
oodt/trunk/workflow/pom.xml
Modified: oodt/trunk/workflow/pom.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/pom.xml?rev=1653721&r1=1653720&r2=1653721&view=diff
==============================================================================
--- oodt/trunk/workflow/pom.xml (original)
+++ oodt/trunk/workflow/pom.xml Thu Jan 22 00:14:55 2015
@@ -42,7 +42,7 @@ the License.
<systemProperties>
<property>
<name>java.util.logging.config.file</name>
- <value>${basedir}/src/testdata/test.logging.properties</value>
+
<value>${basedir}/src/test/resources/test.logging.properties</value>
</property>
</systemProperties>
<forkedProcessTimeoutInSeconds>0</forkedProcessTimeoutInSeconds>
@@ -90,7 +90,7 @@ the License.
<artifactId>rat-maven-plugin</artifactId>
<configuration>
<excludes>
- <exclude>**/src/testdata/*</exclude>
+ <exclude>**/src/test/resources/*</exclude>
</excludes>
</configuration>
<executions>
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/TestWorkflowCli.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/TestWorkflowCli.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/TestWorkflowCli.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/TestWorkflowCli.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,299 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.workflow.cli;
+
+//OODT imports
+import org.apache.oodt.cas.cli.CmdLineUtility;
+import org.apache.oodt.cas.cli.util.OptionPropertyRegister;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.repository.MockWorkflowRepository;
+import org.apache.oodt.cas.workflow.system.MockXmlRpcWorkflowManagerClient;
+import
org.apache.oodt.cas.workflow.system.MockXmlRpcWorkflowManagerClient.MethodCallDetails;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Tests Workflow Manager Clients Command-line interface.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestWorkflowCli extends TestCase {
+
+ static {
+ System.setProperty("org.apache.oodt.cas.cli.debug", "true");
+ System.setProperty("org.apache.oodt.cas.cli.action.spring.config",
"src/main/resources/cmd-line-actions.xml");
+ System.setProperty("org.apache.oodt.cas.cli.option.spring.config",
"src/main/resources/cmd-line-options.xml");
+ System.setProperty("workflow.engine.factory",
"org.apache.oodt.cas.workflow.engine.MockWorkflowEngineFactory");
+ System.setProperty("workflow.engine.instanceRep.factory",
"org.apache.oodt.cas.workflow.instrepo.MemoryWorkflowInstanceRepositoryFactory");
+ System.setProperty("workflow.repo.factory",
"org.apache.oodt.cas.workflow.repository.MockWorkflowRepositoryFactory");
+ }
+
+ private CmdLineUtility cmdLineUtility;
+ private MockXmlRpcWorkflowManagerClient client;
+
+ @Override
+ public void setUp() throws Exception {
+ cmdLineUtility = new CmdLineUtility();
+ UseMockClientCmdLineActionStore actionStore = new
UseMockClientCmdLineActionStore();
+ client = actionStore.getClient();
+ cmdLineUtility.setActionStore(actionStore);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ OptionPropertyRegister.clearRegister();
+ }
+
+ public void testDynWorkflow() throws Exception {
+ cmdLineUtility
+ .run(("--url http://localhost:9000"
+ + " --operation --dynWorkflow --taskIds "
+ + MockWorkflowRepository.TASK1_ID + " "
+ + MockWorkflowRepository.TASK2_ID + " "
+ + MockWorkflowRepository.TASK3_ID
+ + " --metaData --key Filename data.dat --key NominalDate
2001-02-20")
+ .split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("executeDynamicWorkflow",
methodCallDetails.getMethodName());
+ assertEquals(Lists.newArrayList(MockWorkflowRepository.TASK1_ID,
+ MockWorkflowRepository.TASK2_ID, MockWorkflowRepository.TASK3_ID),
+ methodCallDetails.getArgs().get(0));
+ Metadata m = new Metadata();
+ m.addMetadata("NominalDate", Lists.newArrayList("2001-02-20"));
+ m.addMetadata("Filename", Lists.newArrayList("data.dat"));
+ assertEquals(m, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testGetConditionById() {
+ cmdLineUtility
+ .run(("--url http://localhost:9000"
+ + " --operation --getConditionById --id "
+ + MockWorkflowRepository.CONDITION1_ID)
+ .split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getConditionById", methodCallDetails.getMethodName());
+ assertEquals(MockWorkflowRepository.CONDITION1_ID,
methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetFirstPage() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getFirstPage").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getFirstPage", methodCallDetails.getMethodName());
+
+ OptionPropertyRegister.clearRegister();
+
+ String status = "DONE";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getFirstPage --status " + status).split(" "));
+ methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("paginateWorkflowInstances",
methodCallDetails.getMethodName());
+ assertEquals(1, methodCallDetails.getArgs().get(0));
+ assertEquals(status, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testGetLastPage() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getLastPage").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getLastPage", methodCallDetails.getMethodName());
+
+ OptionPropertyRegister.clearRegister();
+
+ String status = "DONE";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getLastPage --status " + status).split(" "));
+ methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("paginateWorkflowInstances",
methodCallDetails.getMethodName());
+ assertEquals(0, methodCallDetails.getArgs().get(0));
+ assertEquals(status, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testGetNextPage() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getNextPage --pageNum 1").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("paginateWorkflowInstances",
methodCallDetails.getMethodName());
+
+ OptionPropertyRegister.clearRegister();
+
+ String status = "DONE";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getNextPage --pageNum 1 --status " +
status).split(" "));
+ methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("paginateWorkflowInstances",
methodCallDetails.getMethodName());
+ assertEquals(2, methodCallDetails.getArgs().get(0));
+ assertEquals(status, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testGetPrevPage() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getPrevPage --pageNum 1").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("paginateWorkflowInstances",
methodCallDetails.getMethodName());
+
+ OptionPropertyRegister.clearRegister();
+
+ String status = "DONE";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getPrevPage --pageNum 1 --status " +
status).split(" "));
+ methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("paginateWorkflowInstances",
methodCallDetails.getMethodName());
+ assertEquals(0, methodCallDetails.getArgs().get(0));
+ assertEquals(status, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testGetRegisteredEvents() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getRegisteredEvents").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getRegisteredEvents", methodCallDetails.getMethodName());
+ assertTrue(methodCallDetails.getArgs().isEmpty());
+ }
+
+ public void testGetTaskById() {
+ String taskId = MockWorkflowRepository.TASK1_ID;
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getTaskById --id " + taskId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getTaskById", methodCallDetails.getMethodName());
+ assertEquals(taskId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetTaskWallClockTime() {
+ String taskId = MockWorkflowRepository.TASK1_ID;
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getTaskWallClockTime --id " + taskId).split("
"));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowCurrentTaskWallClockMinutes",
methodCallDetails.getMethodName());
+ assertEquals(taskId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetWallClockTime() {
+ String taskId = MockWorkflowRepository.TASK1_ID;
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWallClockTime --id " + taskId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowWallClockMinutes",
methodCallDetails.getMethodName());
+ assertEquals(taskId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetWorkflowById() {
+ String workflowId = MockWorkflowRepository.WORKFLOW1_ID;
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWorkflowById --id " + workflowId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowById", methodCallDetails.getMethodName());
+ assertEquals(workflowId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetWorkflowInst() {
+ String instId = "TestId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWorkflowInst --id " + instId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowCurrentTaskWallClockMinutes",
methodCallDetails.getMethodName());
+ assertEquals(instId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetWorkflowInstMet() {
+ String instId = "TestId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWorkflowInstMet --id " + instId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowInstanceMetadata",
methodCallDetails.getMethodName());
+ assertEquals(instId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetWorkflowInsts() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWorkflowInsts").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowInstances", methodCallDetails.getMethodName());
+ assertTrue(methodCallDetails.getArgs().isEmpty());
+ }
+
+ public void testGetWorkflowsByEvent() {
+ String eventName = "TestEventName";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWorkflowsByEvent --eventName " +
eventName).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflowsByEvent", methodCallDetails.getMethodName());
+ assertEquals(eventName, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetWorkflows() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getWorkflows").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getWorkflows", methodCallDetails.getMethodName());
+ assertTrue(methodCallDetails.getArgs().isEmpty());
+ }
+
+ public void testPauseWorkflowInst() {
+ String instId = "TestId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --pauseWorkflowInst --id " + instId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("pauseWorkflowInstance", methodCallDetails.getMethodName());
+ assertEquals(instId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testResumeWorkflowInst() {
+ String instId = "TestId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --resumeWorkflowInst --id " + instId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("resumeWorkflowInstance",
methodCallDetails.getMethodName());
+ assertEquals(instId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testSendEvent() {
+ String eventName = "TestEventName";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --sendEvent --eventName " + eventName).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("sendEvent", methodCallDetails.getMethodName());
+ assertEquals(eventName, methodCallDetails.getArgs().get(0));
+
+ OptionPropertyRegister.clearRegister();
+
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --sendEvent --eventName " + eventName
+ + " --metaData --key Filename data.dat --key NominalDate
2001-02-20").split(" "));
+ methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("sendEvent", methodCallDetails.getMethodName());
+ assertEquals(eventName, methodCallDetails.getArgs().get(0));
+ Metadata m = new Metadata();
+ m.addMetadata("Filename", Lists.newArrayList("data.dat"));
+ m.addMetadata("NominalDate", Lists.newArrayList("2001-02-20"));
+ assertEquals(m, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testStopWorkflowInstance() {
+ String instId = "TestId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --stopWorkflowInst --id " + instId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("stopWorkflowInstance", methodCallDetails.getMethodName());
+ assertEquals(instId, methodCallDetails.getArgs().get(0));
+ }
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/UseMockClientCmdLineActionStore.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/UseMockClientCmdLineActionStore.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/UseMockClientCmdLineActionStore.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/cli/UseMockClientCmdLineActionStore.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.workflow.cli;
+
+//JDK imports
+import java.util.Set;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction;
+import org.apache.oodt.cas.cli.action.store.spring.SpringCmdLineActionStore;
+import org.apache.oodt.cas.cli.exception.CmdLineActionStoreException;
+import org.apache.oodt.cas.workflow.cli.action.WorkflowCliAction;
+import org.apache.oodt.cas.workflow.system.MockXmlRpcWorkflowManagerClient;
+
+/**
+ * A {@link SpringCmdLineActionStore} which sets {@link WorkflowCliAction}s
+ * to use a {@link MockXmlRpcWorkflowManagerClient}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class UseMockClientCmdLineActionStore extends SpringCmdLineActionStore {
+
+ private MockXmlRpcWorkflowManagerClient client;
+
+ public UseMockClientCmdLineActionStore() {
+
super(System.getProperty("org.apache.oodt.cas.cli.action.spring.config"));
+ try {
+ client = new MockXmlRpcWorkflowManagerClient();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Set<CmdLineAction> loadSupportedActions() throws
CmdLineActionStoreException {
+ Set<CmdLineAction> actions = super.loadSupportedActions();
+ for (CmdLineAction action : actions) {
+ if (action instanceof WorkflowCliAction) {
+ ((WorkflowCliAction) action).setClient(client);
+ }
+ }
+ return actions;
+ }
+
+ public MockXmlRpcWorkflowManagerClient getClient() {
+ return client;
+ }
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MetSetterTaskQuerier.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MetSetterTaskQuerier.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MetSetterTaskQuerier.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MetSetterTaskQuerier.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//JDK imports
+import java.util.Calendar;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.engine.processor.TaskProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessorQueue;
+import org.apache.oodt.cas.workflow.structs.PrioritySorter;
+import org.apache.oodt.commons.date.DateUtils;
+
+/**
+ *
+ * Intercepts the calls to {@link TaskQuerier#getNext()} and injects
+ * StartDateTime (and potentially other met fields into the
+ * {@link TaskProcessor#getDynamicMetadata()}.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class MetSetterTaskQuerier extends TaskQuerier {
+
+ private static final long WAIT_SECS=1;
+
+ /**
+ * @param processorQueue
+ * @param prioritizer
+ */
+ public MetSetterTaskQuerier(WorkflowProcessorQueue processorQueue,
+ PrioritySorter prioritizer) {
+ super(processorQueue, prioritizer, null, WAIT_SECS);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oodt.cas.workflow.engine.TaskQuerier#getNext()
+ */
+ @Override
+ public TaskProcessor getNext() {
+ TaskProcessor taskProcessor = super.getNext();
+ if(taskProcessor == null) return null;
+ Metadata met = new Metadata();
+ met.addMetadata("StartDateTime",
DateUtils.toString(Calendar.getInstance()));
+ taskProcessor.getWorkflowInstance().setSharedContext(met);
+ return taskProcessor;
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MockProcessorQueue.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MockProcessorQueue.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MockProcessorQueue.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/MockProcessorQueue.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//JDK imports
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessorQueue;
+
+/**
+ *
+ * A mock {@link WorkflowProcessorQueue} object for use in testing.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class MockProcessorQueue extends WorkflowProcessorQueue {
+
+ private QuerierAndRunnerUtils utils;
+
+ private boolean consumed;
+
+ public MockProcessorQueue() {
+ super(null,null,null);
+ this.utils = new QuerierAndRunnerUtils();
+ this.consumed = false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.oodt.cas.workflow.engine.WorkflowProcessorQueue#getProcessors
()
+ */
+ @Override
+ public synchronized List<WorkflowProcessor> getProcessors() {
+ List<WorkflowProcessor> processors = new Vector<WorkflowProcessor>();
+ try {
+ if (!consumed) {
+ processors.add(utils.getProcessor(10.0, "Success", "done"));
+ processors.add(utils.getProcessor(2.0, "Loaded", "initial"));
+ processors.add(utils.getProcessor(7.0, "Loaded", "initial"));
+ this.consumed = true;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ return processors;
+ }
+
+}
\ No newline at end of file
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/QuerierAndRunnerUtils.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/QuerierAndRunnerUtils.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/QuerierAndRunnerUtils.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/QuerierAndRunnerUtils.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//JDK imports
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Vector;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.engine.processor.SequentialProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.TaskProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessorBuilder;
+import org.apache.oodt.cas.workflow.lifecycle.WorkflowLifecycleManager;
+import org.apache.oodt.cas.workflow.structs.Graph;
+import org.apache.oodt.cas.workflow.structs.ParentChildWorkflow;
+import org.apache.oodt.cas.workflow.structs.Priority;
+import org.apache.oodt.cas.workflow.structs.WorkflowInstance;
+import org.apache.oodt.cas.workflow.structs.WorkflowTask;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+
+/**
+ *
+ * Utilities for testing the {@link TaskQuerier} and {@link TaskRunner} thread
+ * classes.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class QuerierAndRunnerUtils {
+
+ private int dateGen;
+
+ public QuerierAndRunnerUtils() {
+ this.dateGen = 0;
+ }
+
+ public WorkflowTask getTask(File testDir){
+ WorkflowTask task = new WorkflowTask();
+ task.setConditions(Collections.emptyList());
+ task.setRequiredMetFields(Collections.emptyList());
+ task.setTaskId("urn:cas:workflow:tester");
+ task.setTaskInstanceClassName(SimpleTester.class.getName());
+ task.setTaskName("Tester");
+ WorkflowTaskConfiguration config = new WorkflowTaskConfiguration();
+ config.addConfigProperty("TestDirPath",
+ testDir.getAbsolutePath().endsWith("/") ? testDir.getAbsolutePath()
+ : testDir.getAbsolutePath() + "/");
+ task.setTaskConfig(config);
+ return task;
+ }
+
+ public WorkflowProcessor getProcessor(double priority, String stateName,
+ String categoryName) throws InstantiationException,
+ IllegalAccessException, IOException, IllegalArgumentException,
SecurityException, InvocationTargetException, NoSuchMethodException {
+ WorkflowLifecycleManager lifecycleManager = new WorkflowLifecycleManager(
+ "./src/main/resources/examples/wengine/wengine-lifecycle.xml");
+ WorkflowInstance inst = new WorkflowInstance();
+ Date sd = new Date();
+ sd.setTime(sd.getTime() + (this.dateGen * 5000));
+ this.dateGen++;
+ inst.setStartDate(sd);
+ inst.setId("task-winst-" + priority);
+ ParentChildWorkflow workflow = new ParentChildWorkflow(new Graph());
+ workflow.getTasks().add(getTask(getTmpPath()));
+ inst.setParentChildWorkflow(workflow);
+ inst.setPriority(Priority.getPriority(priority));
+ inst.setCurrentTaskId(workflow.getTasks().get(0).getTaskId());
+ inst.setParentChildWorkflow(workflow);
+ WorkflowProcessorBuilder builder = WorkflowProcessorBuilder
+ .aWorkflowProcessor().withLifecycleManager(lifecycleManager)
+ .withPriority(priority).withInstance(inst);
+ TaskProcessor taskProcessor = (TaskProcessor) builder
+ .build(TaskProcessor.class);
+
taskProcessor.getWorkflowInstance().setState(lifecycleManager.getDefaultLifecycle().createState(
+ stateName, categoryName, ""));
+ return taskProcessor;
+ }
+
+ private File getTmpPath() throws IOException{
+ File testDir = null;
+ String parentPath = File.createTempFile("test",
"txt").getParentFile().getAbsolutePath();
+ parentPath = parentPath.endsWith("/") ? parentPath:parentPath + "/";
+ String testJobDirPath = parentPath + "jobs";
+ testDir = new File(testJobDirPath);
+ testDir.mkdirs();
+ return testDir;
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/SimpleTester.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/SimpleTester.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/SimpleTester.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/SimpleTester.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//JDK imports
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskInstance;
+import
org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
+
+/**
+ *
+ * A simple workflow task instance that writes its start date time to a file.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class SimpleTester implements WorkflowTaskInstance {
+
+ private static final Logger LOG = Logger.getLogger(SimpleTester.class
+ .getName());
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.oodt.cas.workflow.structs.WorkflowTaskInstance#run(org.apache
+ * .oodt.cas.metadata.Metadata,
+ * org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration)
+ */
+ @Override
+ public void run(Metadata metadata, WorkflowTaskConfiguration config)
+ throws WorkflowTaskInstanceException {
+ PrintWriter pw = null;
+ try {
+ String jobFilePath = config.getProperty("TestDirPath") + "task-"
+ + metadata.getMetadata("StartDateTime") + ".job";
+ int n=0;
+ while(new File(jobFilePath).exists()){
+ jobFilePath = config.getProperty("TestDirPath") + "task-"
+ + n + metadata.getMetadata("StartDateTime") + ".job";
+ n++;
+ }
+ LOG.log(Level.INFO, "Creating job file: [" + jobFilePath + "]");
+ pw = new PrintWriter(new FileOutputStream(jobFilePath));
+ pw.println("StartDateTime=" + metadata.getMetadata("StartDateTime"));
+ } catch (FileNotFoundException e) {
+ throw new WorkflowTaskInstanceException(e.getMessage());
+ } finally {
+ if (pw != null) {
+ try {
+ pw.close();
+ } catch (Exception ignore) {
+ }
+ pw = null;
+ }
+ }
+
+ }
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestAsynchronousLocalEngineRunner.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestAsynchronousLocalEngineRunner.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestAsynchronousLocalEngineRunner.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestAsynchronousLocalEngineRunner.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,172 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//JDK imports
+import java.io.BufferedReader;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+
+//APACHE imports
+import org.apache.commons.io.FileUtils;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.engine.processor.TaskProcessor;
+import
org.apache.oodt.cas.workflow.engine.runner.AsynchronousLocalEngineRunner;
+import org.apache.oodt.cas.workflow.structs.Priority;
+import org.apache.oodt.commons.date.DateUtils;
+import org.apache.oodt.commons.util.DateConvert;
+
+//JODA imports
+import org.joda.time.DateTime;
+import org.joda.time.Seconds;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ *
+ * A test case for the {@link AsynchronousLocalEngineRunner}.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class TestAsynchronousLocalEngineRunner extends TestCase {
+
+ private AsynchronousLocalEngineRunner runner;
+
+ protected File testDir;
+
+ private QuerierAndRunnerUtils utils;
+
+ public void testRun() {
+ TaskProcessor taskProcessor1 = null;
+ TaskProcessor taskProcessor2 = null;
+
+ try {
+ taskProcessor1 = (TaskProcessor) utils.getProcessor(Priority.getDefault()
+ .getValue(), "Executing", "running");
+ taskProcessor2 = (TaskProcessor) utils.getProcessor(Priority.getDefault()
+ .getValue(), "Executing", "running");
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ Metadata met = new Metadata();
+ met.addMetadata("StartDateTime",
DateUtils.toString(Calendar.getInstance()));
+
+ taskProcessor1.getWorkflowInstance().getSharedContext().addMetadata(met);
+ taskProcessor2.getWorkflowInstance().getSharedContext().addMetadata(met);
+
+ try {
+ runner.execute(taskProcessor1);
+ runner.execute(taskProcessor2);
+ assertTrue(ranFast());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ private boolean ranFast() {
+ boolean ranFast = true;
+ int jobNum = 1;
+ for (File f : this.testDir.listFiles()) {
+ BufferedReader br = null;
+ try {
+ String line = FileUtils.readFileToString(f);
+ String[] toks = line.split(",");
+ assertEquals("Toks not equal to 2: toks=[" + Arrays.asList(toks) + "]",
+ 2, toks.length);
+ Date dateTime = DateConvert.isoParse(toks[1]);
+ Seconds seconds = Seconds.secondsBetween(new DateTime(dateTime),
+ new DateTime());
+ if (seconds.getSeconds() > 30) {
+ fail("More than 30 seconds elapsed now and running job " + jobNum
+ + ": seconds elapsed: [" + seconds.getSeconds() + "]");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ ranFast = false;
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (Exception ignore) {
+ }
+
+ br = null;
+ }
+ }
+ }
+
+ return ranFast;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ String parentPath = File.createTempFile("test", "txt").getParentFile()
+ .getAbsolutePath();
+ parentPath = parentPath.endsWith("/") ? parentPath : parentPath + "/";
+ String testJobDirPath = parentPath + "jobs";
+ testDir = new File(testJobDirPath);
+ testDir.mkdirs();
+ this.runner = new AsynchronousLocalEngineRunner();
+ this.utils = new QuerierAndRunnerUtils();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+
+ // blow away test file
+ deleteAllFiles(testDir.getAbsolutePath());
+ testDir.delete();
+ testDir = null;
+ this.runner = null;
+ }
+
+ private void deleteAllFiles(String startDir) {
+ File startDirFile = new File(startDir);
+ File[] delFiles = startDirFile.listFiles();
+
+ if (delFiles != null && delFiles.length > 0) {
+ for (int i = 0; i < delFiles.length; i++) {
+ delFiles[i].delete();
+ }
+ }
+
+ startDirFile.delete();
+
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskQuerier.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskQuerier.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskQuerier.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskQuerier.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//OODT imports
+import java.util.List;
+
+import org.apache.oodt.cas.workflow.engine.processor.TaskProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessor;
+import org.apache.oodt.cas.workflow.structs.FILOPrioritySorter;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test harness for the {@link TestTaskQuerier}.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class TestTaskQuerier extends TestCase {
+
+ private int dateGen;
+
+ private static final long WAIT_SECS = 1;
+
+ public TestTaskQuerier() {
+ this.dateGen = 0;
+ }
+
+ public void testGetNext(){
+ FILOPrioritySorter prioritizer = new FILOPrioritySorter();
+ MockProcessorQueue processorQueue = new MockProcessorQueue();
+ List<WorkflowProcessor> queued = null;
+ assertNotNull(queued = processorQueue.getProcessors());
+ assertEquals(3, queued.size());
+ processorQueue = new MockProcessorQueue();
+ TaskQuerier querier = new TaskQuerier(processorQueue, prioritizer, null,
WAIT_SECS);
+ Thread querierThread = new Thread(querier);
+ querierThread.start();
+ List<WorkflowProcessor> runnables = null;
+ while ((runnables = querier.getRunnableProcessors()) != null &&
+ runnables.size() < 2) {
+ assertNotNull(runnables);
+ }
+
+ querier.setRunning(false);
+ assertNotNull(runnables);
+ assertEquals(2, runnables.size());
+ TaskProcessor next = querier.getNext();
+ assertNotNull(next);
+ assertEquals(1, querier.getRunnableProcessors().size());
+ }
+
+ public void testGetRunnableProcessors() {
+ FILOPrioritySorter prioritizer = new FILOPrioritySorter();
+ MockProcessorQueue processorQueue = new MockProcessorQueue();
+ List<WorkflowProcessor> queued = null;
+ assertNotNull(queued = processorQueue.getProcessors());
+ assertEquals(3, queued.size());
+ processorQueue = new MockProcessorQueue();
+ TaskQuerier querier = new TaskQuerier(processorQueue, prioritizer, null,
WAIT_SECS);
+ Thread querierThread = new Thread(querier);
+ querierThread.start();
+ List<WorkflowProcessor> runnables = null;
+ while ((runnables = querier.getRunnableProcessors()) != null &&
+ runnables.size() < 2) {
+ assertNotNull(runnables);
+ }
+
+ querier.setRunning(false);
+ assertNotNull(runnables);
+ assertEquals(2, runnables.size());
+ assertNotNull(runnables.get(0));
+ assertNotNull(runnables.get(0).getWorkflowInstance().getPriority());
+ assertEquals(2.1, runnables.get(0).getWorkflowInstance().getPriority()
+ .getValue()); // extra .1 since it's a task
+ assertEquals(7.1, runnables.get(1).getWorkflowInstance().getPriority()
+ .getValue()); // extra .1 since it's a task
+ try{
+ querierThread.join();
+ }
+ catch(InterruptedException ignore){}
+
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskRunner.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskRunner.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskRunner.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestTaskRunner.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.engine;
+
+//JDK imports
+import java.io.File;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.engine.processor.TaskProcessor;
+import org.apache.oodt.cas.workflow.engine.processor.WorkflowProcessor;
+import
org.apache.oodt.cas.workflow.engine.runner.AsynchronousLocalEngineRunner;
+import org.apache.oodt.cas.workflow.engine.runner.EngineRunner;
+import org.apache.oodt.cas.workflow.structs.FILOPrioritySorter;
+import org.apache.oodt.cas.workflow.structs.WorkflowTask;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ *
+ * Exercises the {@link TaskRunner}.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class TestTaskRunner extends TestCase {
+
+ private File testDir;
+
+ private EngineRunner runner;
+
+ private TaskRunner taskRunner;
+
+ private TaskQuerier querier;
+
+ public void testExecuteTasks() {
+ FILOPrioritySorter prioritizer = new FILOPrioritySorter();
+ MockProcessorQueue processorQueue = new MockProcessorQueue();
+ querier = new MetSetterTaskQuerier(processorQueue, prioritizer);
+ Thread querierThread = new Thread(querier);
+ querierThread.start();
+ while (querier.getRunnableProcessors().size() != 2) {
+ assertNotNull(querier.getRunnableProcessors());
+ }
+ List<WorkflowProcessor> runnables = querier.getRunnableProcessors();
+ assertNotNull(runnables);
+ assertEquals(2, runnables.size());
+ runner = new AsynchronousLocalEngineRunner();
+ taskRunner = new TaskRunner(querier, runner);
+ assertNotNull(taskRunner);
+ Thread runnerThread = new Thread(taskRunner);
+ WorkflowTask task = taskRunner
+ .extractTaskFromProcessor((TaskProcessor) runnables.get(0));
+ assertNotNull(task);
+ testDir = new File(task.getTaskConfig().getProperty("TestDirPath"));
+ assertNotNull(testDir);
+ runnerThread.start();
+
+ while (!testDir.exists()
+ || (testDir.exists() && testDir.listFiles().length != 2)) {
+ }
+
+ querier.setRunning(false);
+ runnerThread.interrupt();
+
+ // get the test dir path
+ assertTrue(testDir.exists());
+ assertNotNull(testDir.listFiles());
+ assertEquals(2, testDir.listFiles().length);
+ taskRunner.setRunning(false);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ // blow away test file
+ deleteAllFiles(testDir.getAbsolutePath());
+ testDir.delete();
+ testDir = null;
+ this.runner = null;
+ this.querier = null;
+ this.taskRunner = null;
+ }
+
+ private void deleteAllFiles(String startDir) {
+ File startDirFile = new File(startDir);
+ File[] delFiles = startDirFile.listFiles();
+
+ if (delFiles != null && delFiles.length > 0) {
+ for (int i = 0; i < delFiles.length; i++) {
+ delFiles[i].delete();
+ }
+ }
+
+ startDirFile.delete();
+
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestThreadPoolWorkflowEngine.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestThreadPoolWorkflowEngine.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestThreadPoolWorkflowEngine.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/engine/TestThreadPoolWorkflowEngine.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.cas.workflow.engine;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.structs.Graph;
+import org.apache.oodt.cas.workflow.structs.ParentChildWorkflow;
+import org.apache.oodt.cas.workflow.structs.WorkflowInstance;
+import org.apache.oodt.cas.workflow.structs.WorkflowTask;
+import org.apache.oodt.commons.util.DateConvert;
+
+//JDK imports
+import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>
+ * Test suite for the ThreadPoolWorkflowEngine.
+ * </p>.
+ */
+public class TestThreadPoolWorkflowEngine extends TestCase {
+
+ public TestThreadPoolWorkflowEngine() {
+ // suppress WARNING level and below because we don't want
+ // the warning message where we test if start date time is AFTER
+ // end date time below
+ LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE);
+ }
+
+ public void testCurrentTaskWallClockTime() {
+ // at first, there is no start date time
+ WorkflowInstance inst = new WorkflowInstance();
+ WorkflowTask task = new WorkflowTask();
+ task.setTaskId("urn:oodt:testTask");
+ ParentChildWorkflow workflow = new ParentChildWorkflow(new Graph());
+ workflow.getTasks().add(task);
+ inst.setParentChildWorkflow(workflow);
+ inst.setCurrentTaskId("urn:oodt:testTask");
+ assertEquals(Double.valueOf(0.0), Double
+ .valueOf(ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst)));
+
+ // now set start date time, and assert that wall clock minutes > 0
+ inst.setCurrentTaskStartDateTimeIsoStr(DateConvert
+ .isoFormat(new Date()));
+
System.out.println(ThreadPoolWorkflowEngine.getCurrentTaskWallClockMinutes(inst));
+ assertTrue(ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst) > 0.0);
+
+ // set end date time to "" and make sure wall clock mins still greater
+ // than 0
+ inst.setCurrentTaskEndDateTimeIsoStr("");
+ assertTrue(ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst) > 0.0);
+
+ // set the end date time, compute it, and make sure it stays the same
+ String endDateTimeIsoStr = DateConvert.isoFormat(new Date());
+ inst.setCurrentTaskEndDateTimeIsoStr(endDateTimeIsoStr);
+ double wallClockMins = ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst);
+ assertEquals(Double.valueOf(wallClockMins), Double
+ .valueOf(ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst)));
+ assertEquals(Double.valueOf(wallClockMins), Double
+ .valueOf(ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst)));
+
+ // set the start date time after the end date time
+ // make sure that the wall cock time is 0.0
+ inst.setCurrentTaskStartDateTimeIsoStr(DateConvert
+ .isoFormat(new Date()));
+ assertEquals(Double.valueOf(0.0), Double
+ .valueOf(ThreadPoolWorkflowEngine
+ .getCurrentTaskWallClockMinutes(inst)));
+
+ }
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestExternScriptTaskInstance.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestExternScriptTaskInstance.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestExternScriptTaskInstance.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestExternScriptTaskInstance.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.cas.workflow.examples;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import org.apache.oodt.cas.workflow.structs.exceptions.RepositoryException;
+
+//JDK imports
+import java.io.File;
+import junit.framework.TestCase;
+import java.io.IOException;
+
+//APACHE imports
+import org.apache.commons.io.FileUtils;
+
+/**
+ * @author davoodi
+ * @version $Revision$
+ * @since OODT-226
+ *
+ * <p>
+ * Unit test for running an external script as a task instance.
+ * </p>.
+ */
+public class TestExternScriptTaskInstance extends TestCase {
+
+ private static final String testScriptPath = new File(
+ "./src/test/resources/myScript.sh").getAbsolutePath();
+
+ private ExternScriptTaskInstance myIns;
+
+ private Metadata myMet;
+
+ /**
+ * <p>
+ * Default Constructor
+ * </p>
+ */
+ public TestExternScriptTaskInstance() {
+ myIns = new ExternScriptTaskInstance();
+ }
+
+ public void testExternsalScript() throws RepositoryException {
+
+ myMet = new Metadata();
+ myMet.addMetadata("Args", "Faranak");
+ myMet.addMetadata("Args", "Davoodi");
+ assertNotNull(myMet);
+ WorkflowTaskConfiguration myConfig = new WorkflowTaskConfiguration();
+ myConfig.addConfigProperty("PathToScript", testScriptPath);
+ myConfig.addConfigProperty("ShellType", "/bin/bash");
+ assertNotNull(myConfig);
+ myIns.run(myMet, myConfig);
+ String outputFileStr = null;
+ try {
+ outputFileStr = FileUtils.readFileToString(new File(
+ "./src/test/resources/myScript-Output.txt"),
outputFileStr);
+ String expectedStr = "Hi my first name is Faranak and my last name
is Davoodi.";
+ assertEquals(expectedStr.trim(), outputFileStr.trim());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestFilterTask.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/examples/TestFilterTask.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,172 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.examples;
+
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import
org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test harness for FilterTask.
+ *
+ */
+public class TestFilterTask extends TestCase {
+
+ private FilterTask task;
+ private Metadata dynMet;
+ private WorkflowTaskConfiguration config;
+ private static final String prodDateTime = "2014-04-07T00:00:00.000Z";
+ private static final String filename = "foo.txt";
+ private static final String fileLocation = "/tmp/somedir";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ task = new FilterTask();
+ dynMet = new Metadata();
+ dynMet.addMetadata("Filename", filename);
+ dynMet.addMetadata("ProductionDateTime", prodDateTime);
+ config = new WorkflowTaskConfiguration();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ task = null;
+ dynMet = null;
+ config = null;
+ }
+
+ public void testRemove() {
+ config.addConfigProperty("Remove_Key", "Filename");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("Filename"));
+ }
+
+ public void testRename() {
+ config.addConfigProperty("Rename_ProductionDateTime",
+ "Prior_ProductionDateTime");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("ProductionDateTime"));
+ assertTrue(dynMet.containsKey("Prior_ProductionDateTime"));
+ assertEquals(
+ "Value: [" +
dynMet.getMetadata("Prior_ProductionDateTime")
+ + "] was not equal to: [" +
prodDateTime + "]",
+ prodDateTime,
dynMet.getMetadata("Prior_ProductionDateTime"));
+ }
+
+ public void testRemoveAfterRename() {
+ config.addConfigProperty("Rename_Filename", "FooName");
+ config.addConfigProperty("Remove_Key", "FooName");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("Filename"));
+ assertFalse(dynMet.containsKey("FooName"));
+ }
+
+ public void testRemoveMultipleKeys() {
+ config.addConfigProperty("Remove_Key", "Filename,
ProductionDateTime");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("Filename"));
+ assertFalse(dynMet.containsKey("ProductionDateTime"));
+
+ }
+
+ public void testRemoveKeyThatDoesNotExist() {
+ config.addConfigProperty("Remove_Key", "FileLocation");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("FileLocation"));
+ }
+
+ public void testRenameKeyThatDoesNotExist() {
+ config.addConfigProperty("Rename_FileLocation", "FooLocation");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("FileLocation"));
+ assertFalse(dynMet.containsKey("FooLocation"));
+ }
+
+ public void testRenameToKeyWithExistingValues() {
+ dynMet.addMetadata("Prior_FileLocation", fileLocation);
+ dynMet.addMetadata("FileLocation", fileLocation +
"/someotherdir");
+ config.addConfigProperty("Rename_FileLocation",
"Prior_FileLocation");
+ try {
+ task.run(dynMet, config);
+ } catch (WorkflowTaskInstanceException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(dynMet);
+ assertFalse(dynMet.containsKey("FileLocation"));
+ assertTrue(dynMet.containsKey("Prior_FileLocation"));
+ assertEquals("Expected: [1] value, actual was : ["
+ +
dynMet.getAllMetadata("Prior_FileLocation").size() + "]", 1,
+
dynMet.getAllMetadata("Prior_FileLocation").size());
+ assertEquals("Expected: [" + fileLocation + "/someotherdir"
+ + "]: got: [" +
dynMet.getMetadata("Prior_FileLocation") + "]",
+ fileLocation + "/someotherdir",
+ dynMet.getMetadata("Prior_FileLocation"));
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.cas.workflow.instrepo;
+
+//OODT imports
+import org.apache.oodt.cas.metadata.Metadata;
+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.WorkflowStatus;
+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;
+
+//JDK imports
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+//Apache Imports
+import org.apache.commons.io.FileUtils;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ * @since OODT-55
+ *
+ * <p>
+ * Test Case for the {@link LuceneWorkflowInstaceRepository}
+ * </p>.
+ */
+public class TestLuceneWorkflowInstanceRepository extends TestCase implements
+ WorkflowStatus {
+
+ private LuceneWorkflowInstanceRepository repo = null;
+
+ private WorkflowInstance testInst = null;
+
+ private Workflow testWkflw;
+
+ private WorkflowTask testTask;
+
+ private WorkflowCondition testCond;
+
+ private String tmpDirPath = null;
+
+ public TestLuceneWorkflowInstanceRepository() {
+ testInst = new WorkflowInstance();
+ testWkflw = new Workflow();
+ testTask = new WorkflowTask();
+ testCond = new WorkflowCondition();
+ testWkflw.setName("test.workflow");
+ testWkflw.setId("test.id");
+ List tasks = new Vector();
+ List conds = new Vector();
+
+ testCond.setConditionId("test.cond.id");
+ testCond.setConditionInstanceClassName("test.class");
+ testCond.setConditionName("test.cond.name");
+ testCond.setOrder(1);
+ conds.add(testCond);
+
+ testTask.setTaskConfig(new WorkflowTaskConfiguration());
+ testTask.setTaskId("test.task.id");
+ testTask.setConditions(conds);
+ testTask.setOrder(1);
+ testTask.setTaskInstanceClassName("test.class");
+ testTask.setTaskName("test.task.name");
+ tasks.add(testTask);
+ testWkflw.setTasks(tasks);
+
+ testInst = new WorkflowInstance();
+ testInst.setCurrentTaskId("test.task");
+ testInst.setStatus(STARTED);
+ testInst.setWorkflow(testWkflw);
+
+ Metadata sharedContext = new Metadata();
+ sharedContext.addMetadata("TestKey1", "TestVal1");
+ sharedContext.addMetadata("TestKey1", "TestVal2");
+ sharedContext.addMetadata("TestKey2", "TestVal3");
+ testInst.setSharedContext(sharedContext);
+
+ // first load the example configuration
+ try {
+ System.getProperties().load(
+ new
FileInputStream("./src/main/resources/workflow.properties"));
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // get a temp directory
+
+ File tempDir = null;
+ File tempFile = null;
+
+ try {
+ tempFile = File.createTempFile("foo", "bar");
+ tempFile.deleteOnExit();
+ tempDir = tempFile.getParentFile();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ tmpDirPath = tempDir.getAbsolutePath();
+ if (!tmpDirPath.endsWith("/")) {
+ tmpDirPath += "/";
+ }
+
+ tmpDirPath += "testInstRepo/";
+
+ // now override the catalog ones
+ System.setProperty(
+ "org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath",
+ tmpDirPath);
+
+ System.setProperty(
+ "org.apache.oodt.cas.workflow.instanceRep.pageSize", "20");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ repo = (LuceneWorkflowInstanceRepository) new
LuceneWorkflowInstanceRepositoryFactory().createInstanceRepository();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ // now remove the temporary directory used
+ if (tmpDirPath != null) {
+ FileUtils.forceDelete(new File(tmpDirPath));
+ }
+ if (repo != null) {
+ repo = null;
+ }
+
+ }
+
+ /**
+ * @since OODT-389
+ **/
+ public void testInstanceRepoInitialization() {
+ // Getting the number of workflow instances should not fail even on an
empty index
+ try {
+ int count = repo.getNumWorkflowInstances();
+ // There should be no instances in the index at this point
+ assertEquals(0, count);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ public void testUpdateDocumentAndPreserveId() {
+ try {
+ repo.addWorkflowInstance(testInst);
+ } catch (InstanceRepositoryException e) {
+ fail(e.getMessage());
+ }
+
+ // preserve its id
+ String wInstId = testInst.getId();
+
+ // modify it
+ try {
+ repo.updateWorkflowInstance(testInst);
+ } catch (InstanceRepositoryException e) {
+ fail(e.getMessage());
+ }
+
+ // make sure that the new id is the same
+ assertEquals(wInstId, testInst.getId());
+
+ // make sure that there is only 1 workflow instance
+ List wInsts = null;
+ try {
+ wInsts = repo.getWorkflowInstances();
+ } catch (InstanceRepositoryException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(wInsts);
+ assertEquals(1, wInsts.size());
+
+ // make sure that we can look up that workflow inst by its id
+ WorkflowInstance foundInst = null;
+ try {
+ foundInst = repo.getWorkflowInstanceById(wInstId);
+ } catch (InstanceRepositoryException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(foundInst);
+ assertEquals(foundInst.getId(), wInstId);
+ assertNotNull(foundInst.getSharedContext());
+ assertNotNull(foundInst.getSharedContext().getHashtable());
+ assertEquals(2, foundInst.getSharedContext().getHashtable().keySet()
+ .size());
+ assertNotNull(foundInst.getSharedContext().getAllMetadata("TestKey1"));
+ assertEquals(2, foundInst.getSharedContext().getAllMetadata("TestKey1")
+ .size());
+
+ boolean gotVal1 = false, gotVal2 = false;
+
+ for (Iterator i = foundInst.getSharedContext().getAllMetadata(
+ "TestKey1").iterator(); i.hasNext();) {
+ String val = (String) i.next();
+ if (val.equals("TestVal1")) {
+ gotVal1 = true;
+ } else if (val.equals("TestVal2")) {
+ gotVal2 = true;
+ }
+ }
+
+ assert (gotVal1 && gotVal2);
+
+ assertNotNull(foundInst.getSharedContext().getMetadata("TestKey2"));
+ assertEquals("TestVal3", foundInst.getSharedContext().getMetadata(
+ "TestKey2"));
+ }
+
+}
Added:
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/lifecycle/TestWorkflowLifecycleManager.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/lifecycle/TestWorkflowLifecycleManager.java?rev=1653721&view=auto
==============================================================================
---
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/lifecycle/TestWorkflowLifecycleManager.java
(added)
+++
oodt/trunk/workflow/src/test/java/org/apache/oodt/cas/workflow/lifecycle/TestWorkflowLifecycleManager.java
Thu Jan 22 00:14:55 2015
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.oodt.cas.workflow.lifecycle;
+
+//JDK imports
+import java.io.File;
+import java.util.List;
+
+import org.apache.oodt.cas.workflow.structs.Graph;
+import org.apache.oodt.cas.workflow.structs.ParentChildWorkflow;
+import org.apache.oodt.cas.workflow.structs.WorkflowInstance;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test harness for {@link WorkflowLifecycleManager}.
+ *
+ * @author mattmann
+ * @version $Revision$
+ *
+ */
+public class TestWorkflowLifecycleManager extends TestCase {
+
+ private WorkflowLifecycleManager lifecycle;
+
+ public void testPctCompleteWengineStages(){
+ ParentChildWorkflow workflow = new ParentChildWorkflow(new Graph());
+ WorkflowState successState =
lifecycle.getDefaultLifecycle().createState("Success", "done", "All done.");
+ WorkflowInstance instance = new WorkflowInstance();
+ instance.setState(successState);
+ instance.setParentChildWorkflow(workflow);
+ double pct = lifecycle.getPercentageComplete(instance);
+ assertNotNull(pct);
+ assertEquals(1.0, pct);
+ }
+
+ public void testPctCompleteWorkflow1Stages() throws InstantiationException{
+ this.lifecycle = new WorkflowLifecycleManager("./src/main/resources"
+ + "/examples/workflow-lifecycle.xml");
+ assertNotNull(this.lifecycle);
+ assertNotNull(this.lifecycle.getDefaultLifecycle());
+ assertNotNull(this.lifecycle.getDefaultLifecycle().getStages());
+ ParentChildWorkflow workflow = new ParentChildWorkflow(new Graph());
+ WorkflowState successState =
lifecycle.getDefaultLifecycle().createState("FINISHED", "done", "All done.");
+ WorkflowInstance instance = new WorkflowInstance();
+ instance.setState(successState);
+ instance.setParentChildWorkflow(workflow);
+ double pct = lifecycle.getPercentageComplete(instance);
+ assertNotNull(pct);
+ assertEquals(1.0, pct);
+
+
+ }
+
+
+ public void testStages() {
+ assertNotNull(this.lifecycle.getDefaultLifecycle());
+ assertNotNull(this.lifecycle.getDefaultLifecycle().getStages());
+ assertEquals(this.lifecycle.getDefaultLifecycle().getStages().size(), 7);
+ }
+
+ public void testReadNewStateFormat() {
+ assertNotNull(this.lifecycle.getDefaultLifecycle());
+ assertNotNull(this.lifecycle.getDefaultLifecycle().getStages());
+ boolean gotNull = false, gotLoaded = false;
+ WorkflowLifecycleStage category = this.lifecycle.getDefaultLifecycle()
+ .getCategoryByName("initial");
+ assertNotNull(category);
+ assertEquals("initial", category.getName());
+ for (WorkflowState state : (List<WorkflowState>) category.getStates()) {
+ if (state.getName().equals("Null")) {
+ gotNull = true;
+ assertEquals(state.getDescription(), "Uninitialized State");
+ }
+
+ if (state.getName().equals("Loaded")) {
+ gotLoaded = true;
+ assertEquals(state.getDescription(), "Loading Complete");
+ }
+ }
+
+ assertTrue(gotNull && gotLoaded);
+ }
+
+ public void testReadOldStateFormat() throws InstantiationException {
+ this.lifecycle = new WorkflowLifecycleManager("./src/main/resources"
+ + "/examples/workflow-lifecycle.xml");
+ assertNotNull(this.lifecycle);
+ assertNotNull(this.lifecycle.getDefaultLifecycle());
+ assertNotNull(this.lifecycle.getDefaultLifecycle().getStages());
+ assertEquals(this.lifecycle.getDefaultLifecycle().getStages().size(), 5);
+ assertNotNull(this.lifecycle.getDefaultLifecycle().getCategoryByName(
+ "workflow_start"));
+ assertNotNull(this.lifecycle.getDefaultLifecycle()
+ .getCategoryByName("workflow_start").getStates());
+ assertEquals(
+ this.lifecycle.getDefaultLifecycle()
+ .getCategoryByName("workflow_start").getStates().size(), 2);
+ boolean gotRsubmit = false, gotStarted = false;
+
+ for (WorkflowState state : this.lifecycle.getDefaultLifecycle()
+ .getCategoryByName("workflow_start").getStates()) {
+ if (state.getName().equals("RSUBMIT")) {
+ gotRsubmit = true;
+ }
+
+ if (state.getName().equals("STARTED")) {
+ gotStarted = true;
+ }
+ }
+
+ assertTrue(gotRsubmit && gotStarted);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ this.lifecycle = new WorkflowLifecycleManager(
+ new File("./src/main/resources/examples/wengine/wengine-lifecycle.xml")
+ .getAbsolutePath());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ this.lifecycle = null;
+ }
+
+}