Author: tpalsulich
Date: Wed Jan 21 23:21:27 2015
New Revision: 1653695
URL: http://svn.apache.org/r1653695
Log:
OODT-762. Migrate resource test resources.
Added:
oodt/trunk/resource/src/test/java/
oodt/trunk/resource/src/test/java/org/
oodt/trunk/resource/src/test/java/org/apache/
oodt/trunk/resource/src/test/java/org/apache/oodt/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/TestResourceCli.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/UseMockClientCmdLineActionStore.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/jobqueue/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/jobqueue/TestJobStack.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxBatchmgr.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxMonitor.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockMonitor.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/queuerepo/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/queuerepo/TestXmlQueueRepository.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/schedule/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/schedule/MockScheduler.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/MockXmlRpcResourceManagerClient.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/TestMesosUtilities.java
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/TestUlimit.java
oodt/trunk/resource/src/test/resources/
oodt/trunk/resource/src/test/resources/policy/
oodt/trunk/resource/src/test/resources/policy/node-to-queue-mapping.xml
oodt/trunk/resource/src/test/resources/policy/nodes.xml
oodt/trunk/resource/src/test/resources/resourcemon/
oodt/trunk/resource/src/test/resources/resourcemon/gangliaXMLdump.xml
oodt/trunk/resource/src/test/resources/test.logging.properties
oodt/trunk/resource/src/test/resources/test.resource.properties
Removed:
oodt/trunk/resource/src/test/org/
oodt/trunk/resource/src/testdata/
Modified:
oodt/trunk/resource/pom.xml
Modified: oodt/trunk/resource/pom.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/pom.xml?rev=1653695&r1=1653694&r2=1653695&view=diff
==============================================================================
--- oodt/trunk/resource/pom.xml (original)
+++ oodt/trunk/resource/pom.xml Wed Jan 21 23:21:27 2015
@@ -44,7 +44,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>
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/TestResourceCli.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/TestResourceCli.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/TestResourceCli.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/TestResourceCli.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,265 @@
+/*
+ * 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.resource.cli;
+
+//JDK imports
+import java.net.MalformedURLException;
+import java.net.URL;
+
+//OODT imports
+import org.apache.oodt.cas.cli.CmdLineUtility;
+import org.apache.oodt.cas.cli.util.OptionPropertyRegister;
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.JobInput;
+import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.system.MockXmlRpcResourceManagerClient;
+import
org.apache.oodt.cas.resource.system.MockXmlRpcResourceManagerClient.MethodCallDetails;
+import org.apache.oodt.cas.resource.util.JobBuilder;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for cas-cli command line for resource manager.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestResourceCli 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("resource.scheduler.factory",
"org.apache.oodt.cas.resource.MockScheduler");
+ }
+
+ private CmdLineUtility cmdLineUtility;
+ private MockXmlRpcResourceManagerClient 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 testAddNode() throws MalformedURLException {
+ int capacity = 10;
+ String nodeId = "TestNodeId";
+ String ipAddr = "http://localhost:9999";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --addNode --capacity " + capacity + " --nodeId "
+ + nodeId + " --ipAddr " + ipAddr).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("addNode", methodCallDetails.getMethodName());
+ ResourceNode actualNode = (ResourceNode)
methodCallDetails.getArgs().get(0);
+ ResourceNode expectedNode = new ResourceNode(nodeId, new URL(ipAddr),
capacity);
+ assertEquals(expectedNode.getIpAddr(), actualNode.getIpAddr());
+ assertEquals(expectedNode.getCapacity(), actualNode.getCapacity());
+ assertEquals(expectedNode.getNodeId(), actualNode.getNodeId());
+ }
+
+ public void testAddNodeToQueue() {
+ String queueName = "TestQueueName";
+ String nodeId = "TestNodeId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --addNodeToQueue --queueName " + queueName + "
--nodeId "
+ + nodeId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("addNodeToQueue", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ assertEquals(queueName, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testAddQueue() {
+ String queueName = "TestQueueName";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --addQueue --queueName " + queueName).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("addQueue", methodCallDetails.getMethodName());
+ assertEquals(queueName, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetExecNode() {
+ String jobId = "TestJobId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getExecNode --jobId " + jobId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getExecutionNode", methodCallDetails.getMethodName());
+ assertEquals(jobId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetJobInfo() {
+ String jobId ="TestJobId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getJobInfo --jobId " + jobId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getJobInfo", methodCallDetails.getMethodName());
+ assertEquals(jobId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetNodeById() {
+ String nodeId = "TestNodeId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getNodeById --nodeId " + nodeId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getNodeById", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetNodeLoad() {
+ String nodeId = "TestNodeId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getNodeLoad --nodeId " + nodeId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getNodeLoad", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetNodes() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getNodes").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getNodes", methodCallDetails.getMethodName());
+ assertEquals(0, methodCallDetails.getArgs().size());
+ }
+
+ public void testGetNodesInQueue() {
+ String queueName = "TestQueueName";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getNodesInQueue --queueName "
+ + queueName).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getNodesInQueue", methodCallDetails.getMethodName());
+ assertEquals(queueName, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testGetQueues() {
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getQueues").split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getQueues", methodCallDetails.getMethodName());
+ assertEquals(0, methodCallDetails.getArgs().size());
+ }
+
+ public void testGetQueuesWithNode() {
+ String nodeId = "TestNodeId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --getQueuesWithNode --nodeId "
+ + nodeId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("getQueuesWithNode", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testKill() {
+ String jobId = "TestJobId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --kill --jobId "
+ + jobId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("killJob", methodCallDetails.getMethodName());
+ assertEquals(jobId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testRemoveNode() {
+ String nodeId = "TestNodeId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --removeNode --nodeId "
+ + nodeId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("removeNode", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testRemoveNodeFromQueue() {
+ String nodeId = "TestNodeId";
+ String queueName = "TestQueueNames";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --removeNodeFromQueue --nodeId "
+ + nodeId + " --queueName " + queueName).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("removeNodeFromQueue", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ assertEquals(queueName, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testRemoveQueue() {
+ String queueName = "TestQueueName";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --removeQueue --queueName "
+ + queueName).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("removeQueue", methodCallDetails.getMethodName());
+ assertEquals(queueName, methodCallDetails.getArgs().get(0));
+ }
+
+ public void testSetNodeCapacity() {
+ int capacity = 4;
+ String nodeId = "TestNodeId";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --setNodeCapacity --capacity "
+ + capacity + " --nodeId " + nodeId).split(" "));
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("setNodeCapacity", methodCallDetails.getMethodName());
+ assertEquals(nodeId, methodCallDetails.getArgs().get(0));
+ assertEquals(capacity, methodCallDetails.getArgs().get(1));
+ }
+
+ public void testSubmitJob() throws MalformedURLException {
+ String jobDefinitionFile = "src/main/resources/examples/jobs/exJob.xml";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --submitJob --def "
+ + jobDefinitionFile).split(" "));
+ JobSpec spec = JobBuilder.buildJobSpec(jobDefinitionFile);
+ MethodCallDetails methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("submitJob", methodCallDetails.getMethodName());
+ Job actualJob = (Job) methodCallDetails.getArgs().get(0);
+ assertEquals(spec.getJob().getJobInstanceClassName(),
actualJob.getJobInstanceClassName());
+ assertEquals(spec.getJob().getJobInputClassName(),
actualJob.getJobInputClassName());
+ assertEquals(spec.getJob().getQueueName(), actualJob.getQueueName());
+ assertEquals(spec.getJob().getLoadValue(), actualJob.getLoadValue());
+ JobInput actualJobInput = (JobInput) methodCallDetails.getArgs().get(1);
+ assertEquals(spec.getIn().getClass(), actualJobInput.getClass());
+ assertEquals(2, methodCallDetails.getArgs().size());
+
+ OptionPropertyRegister.clearRegister();
+
+ String url = "http://localhost:9000";
+ cmdLineUtility.run(("--url http://localhost:9000"
+ + " --operation --submitJob --def "
+ + jobDefinitionFile + " --nodeUrl " + url).split(" "));
+ methodCallDetails = client.getLastMethodCallDetails();
+ assertEquals("submitJob", methodCallDetails.getMethodName());
+ actualJob = (Job) methodCallDetails.getArgs().get(0);
+ assertEquals(spec.getJob().getJobInstanceClassName(),
actualJob.getJobInstanceClassName());
+ assertEquals(spec.getJob().getJobInputClassName(),
actualJob.getJobInputClassName());
+ assertEquals(spec.getJob().getQueueName(), actualJob.getQueueName());
+ assertEquals(spec.getJob().getLoadValue(), actualJob.getLoadValue());
+ actualJobInput = (JobInput) methodCallDetails.getArgs().get(1);
+ assertEquals(spec.getIn().getClass(), actualJobInput.getClass());
+ assertEquals(new URL(url), methodCallDetails.getArgs().get(2));
+ assertEquals(3, methodCallDetails.getArgs().size());
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/UseMockClientCmdLineActionStore.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/UseMockClientCmdLineActionStore.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/UseMockClientCmdLineActionStore.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/cli/UseMockClientCmdLineActionStore.java
Wed Jan 21 23:21:27 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.resource.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.resource.cli.action.ResourceCliAction;
+import org.apache.oodt.cas.resource.system.MockXmlRpcResourceManagerClient;
+
+/**
+ * A {@link SpringCmdLineActionStore} which sets {@link WorkflowCliAction}s
+ * to use a {@link MockXmlRpcWorkflowManagerClient}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class UseMockClientCmdLineActionStore extends SpringCmdLineActionStore {
+
+ private MockXmlRpcResourceManagerClient client;
+
+ public UseMockClientCmdLineActionStore() {
+
super(System.getProperty("org.apache.oodt.cas.cli.action.spring.config"));
+ try {
+ client = new MockXmlRpcResourceManagerClient();
+ } 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 ResourceCliAction) {
+ ((ResourceCliAction) action).setClient(client);
+ }
+ }
+ return actions;
+ }
+
+ public MockXmlRpcResourceManagerClient getClient() {
+ return client;
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/jobqueue/TestJobStack.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/jobqueue/TestJobStack.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/jobqueue/TestJobStack.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/jobqueue/TestJobStack.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,166 @@
+/*
+ * 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.resource.jobqueue;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.resource.jobrepo.JobRepository;
+import org.apache.oodt.cas.resource.jobrepo.MemoryJobRepository;
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.JobInput;
+import org.apache.oodt.cas.resource.structs.JobSpec;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>
+ * Test Suite for the {@link JobStack} class.
+ * </p>.
+ */
+public class TestJobStack extends TestCase {
+
+ private JobSpec job1 = null;
+
+ private JobSpec job2 = null;
+
+ private final static int waitTime = 20;
+
+ private final static JobRepository repo = new MemoryJobRepository();
+
+ public TestJobStack() {
+ Job j1 = new Job();
+ j1.setId("booger");
+ j1.setName("pick it");
+
+ JobInput in = null;
+
+ job1 = new JobSpec(in, j1);
+
+ Job j2 = new Job();
+ j2.setId("booger2");
+ j2.setName("pick some more");
+ job2 = new JobSpec(in, j2);
+ }
+
+ protected void setUp() {
+
+ }
+
+ public void testAddJob() {
+ JobStack stack = new JobStack(waitTime, repo);
+
+ List queuedJobs = null;
+
+ try {
+ queuedJobs = stack.getQueuedJobs();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(queuedJobs);
+ assertEquals(0, queuedJobs.size());
+
+ try {
+ stack.addJob(job1);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ assertEquals(1, queuedJobs.size());
+ }
+
+ public void testIsEmpty() {
+ JobStack stack = new JobStack(waitTime, repo);
+ assertTrue(stack.isEmpty());
+ }
+
+ public void testPurge() {
+ JobStack stack = new JobStack(waitTime, repo);
+ assertNotNull(stack);
+
+ try {
+ stack.addJob(job1);
+ stack.addJob(job2);
+ stack.addJob(job2);
+
+ List queuedJobs = stack.getQueuedJobs();
+ assertNotNull(queuedJobs);
+ assertEquals(3, queuedJobs.size());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ try {
+ stack.purge();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ assertTrue(stack.isEmpty());
+
+ }
+
+ public void testQueuedJobs() {
+ JobStack stack = new JobStack(waitTime, repo);
+ List queuedJobs = null;
+
+ try {
+ stack.addJob(job1);
+ queuedJobs = stack.getQueuedJobs();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(queuedJobs);
+ assertEquals(1, queuedJobs.size());
+
+ }
+
+ public void testGetNextJob() {
+ JobStack stack = new JobStack(waitTime, repo);
+ JobSpec nextJob = null;
+
+ try {
+ stack.addJob(job1);
+ stack.addJob(job2);
+ stack.addJob(job2);
+
+ List queuedJobs = stack.getQueuedJobs();
+
+ nextJob = stack.getNextJob();
+ assertEquals(nextJob.getJob().getId(), job1.getJob().getId());
+ assertEquals(queuedJobs.size(), 2);
+ nextJob = stack.getNextJob();
+ assertEquals(nextJob.getJob().getId(), job2.getJob().getId());
+ assertEquals(queuedJobs.size(), 1);
+ nextJob = stack.getNextJob();
+ assertEquals(nextJob.getJob().getId(), job2.getJob().getId());
+ assertEquals(queuedJobs.size(), 0);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestAssignmentMonitor.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,150 @@
+/*
+ * 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.resource.monitor;
+
+//OODT imports
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+
+//JDK imports
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * @author mattmann
+ * @author bfoster
+ * @author rajith
+ * @version $Revision$
+ *
+ * <p>
+ * Test Suite for the {@link AssignmentMonitor} service
+ * </p>.
+ */
+public class TestAssignmentMonitor extends TestCase {
+
+ private AssignmentMonitor assgnMon = null;
+
+ protected void setUp() throws IOException {
+ generateTestConfig();
+ assgnMon = new AssignmentMonitorFactory().createMonitor();
+ }
+
+ public void testGetNodes() {
+ List resNodes = null;
+
+ try {
+ resNodes = assgnMon.getNodes();
+ } catch (MonitorException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(resNodes);
+ assertEquals(1, resNodes.size());
+ }
+
+ public void testGetNodeById() {
+ ResourceNode node = null;
+
+ try {
+ node = assgnMon.getNodeById("localhost");
+ } catch (MonitorException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(node);
+ assertEquals("localhost", node.getNodeId());
+ }
+
+ public void testGetNodeInfo() {
+ List resNodes = null;
+
+ try {
+ resNodes = assgnMon.getNodes();
+ } catch (MonitorException e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(resNodes);
+
+ boolean hasNode1 = false;
+
+ for (Iterator i = resNodes.iterator(); i.hasNext();) {
+ ResourceNode node = (ResourceNode) i.next();
+ assertNotNull(node);
+ if (node.getNodeId().equals("localhost")) {
+ hasNode1 = true;
+ assertEquals(node.getIpAddr().toExternalForm(),
+ "http://localhost:2001");
+ }
+ assertEquals(node.getCapacity(), 8);
+ }
+
+ assertTrue(hasNode1);
+ }
+
+ public void testNodeModification() throws MonitorException,
+ MalformedURLException {
+ List<ResourceNode> nodes = new Vector<ResourceNode>(this.assgnMon
+ .getNodes());
+ ResourceNode test1 = new ResourceNode("Test1", new URL(
+ "http://localhost:1111"), 9);
+ ResourceNode test2 = new ResourceNode("Test2", new URL(
+ "http://localhost:2222"), 9);
+ ResourceNode test3 = new ResourceNode("Test3", new URL(
+ "http://localhost:3333"), 9);
+ this.assgnMon.addNode(test1);
+ nodes.add(test1);
+ this.assgnMon.addNode(test2);
+ nodes.add(test2);
+ this.assgnMon.addNode(test3);
+ nodes.add(test3);
+
+ assertTrue(nodes.containsAll(this.assgnMon.getNodes())
+ && this.assgnMon.getNodes().containsAll(nodes));
+
+ this.assgnMon.removeNodeById(test1.getNodeId());
+ nodes.remove(test1);
+
+ assertTrue(nodes.containsAll(this.assgnMon.getNodes())
+ && this.assgnMon.getNodes().containsAll(nodes));
+ }
+
+
+ private void generateTestConfig() throws IOException {
+ String propertiesFile = "." + File.separator + "src" + File.separator +
+ "test" + File.separator + "resources" + File.separator +
"test.resource.properties";
+
+ System.getProperties().load(new FileInputStream(new
File(propertiesFile)));
+
+ System.setProperty("org.apache.oodt.cas.resource.nodes.dirs",
+ "file:" + new File("." + File.separator + "src" +
File.separator +
+ "main" + File.separator + "resources" + File.separator
+
+ "examples").getAbsolutePath());
+ }
+
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaResourceMonitor.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,147 @@
+/*
+ * 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.resource.monitor;
+
+//Junit imports
+import junit.framework.TestCase;
+
+
+//OODT imports
+import org.apache.oodt.cas.resource.monitor.ganglia.GangliaResourceMonitor;
+import
org.apache.oodt.cas.resource.monitor.ganglia.GangliaResourceMonitorFactory;
+import org.apache.oodt.cas.resource.monitor.utils.MockGmetad;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+
+
+//JDK imports
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author rajith
+ * @author mattmann
+ * @version $Revision$
+ *
+ * Test Suite for the {@link
org.apache.oodt.cas.resource.monitor.ganglia.GangliaResourceMonitor}
+ */
+public class TestGangliaResourceMonitor extends TestCase {
+
+ private GangliaResourceMonitor gangliaResourceMonitor;
+ private ThreadLocal<MockGmetad> mockGmetad = new ThreadLocal<MockGmetad>();
+
+ @Override
+ protected void setUp() throws IOException {
+ generateTestConfig();
+ runMockGmetad();
+
+ gangliaResourceMonitor = (GangliaResourceMonitor)
+ new GangliaResourceMonitorFactory().createMonitor();
+ }
+
+ @Override
+ protected void tearDown(){
+ mockGmetad.remove();
+ }
+
+ public void testGetLoad() {
+ try {
+ ResourceNode resourceNode = new ResourceNode();
+ resourceNode.setId("localhost");
+ assertEquals(1, gangliaResourceMonitor.getLoad(resourceNode));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testRemoveNodeById(){
+ try {
+ gangliaResourceMonitor.removeNodeById("localhost");
+ assertNull(gangliaResourceMonitor.getNodeById("remotenode"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testGetNodes(){
+ try{
+ List<ResourceNode> nodes = gangliaResourceMonitor.getNodes();
+ assertNotNull(nodes);
+ assertEquals(3, nodes.size());
+ boolean hasLocal = false;
+ boolean hasLocal2 = false;
+ boolean hasRemote = false;
+
+ for(ResourceNode node: nodes){
+ if(node.getNodeId().equals("localhost")){
+ hasLocal = true;
+ }
+ else if(node.getNodeId().equals("localhost2")){
+ hasLocal2 = true;
+ }
+ else if(node.getNodeId().equals("remotenode")){
+ hasRemote = true;
+ }
+
+ }
+ assertTrue(hasLocal&&hasLocal2&&hasRemote);
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public void testGetNodeById(){
+ try{
+ ResourceNode node =
gangliaResourceMonitor.getNodeById("localhost");
+ assertNotNull(node);
+ assertEquals("localhost", node.getNodeId());
+ node = gangliaResourceMonitor.getNodeById("localhost2");
+ assertNotNull(node);
+ assertEquals("localhost2", node.getNodeId());
+ node = gangliaResourceMonitor.getNodeById("remotenode");
+ assertNotNull(node);
+ assertEquals("remotenode", node.getNodeId());
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ private void runMockGmetad() {
+ int port = Integer.valueOf(System
+
.getProperty("org.apache.oodt.cas.resource.monitor.ganglia.gemtad.host.port"));
+ String sampleXMLfilePath = "." + File.separator + "src" +
File.separator +
+ "test" + File.separator + "resources" + File.separator +
"resourcemon" + File.separator + "gangliaXMLdump.xml";
+ mockGmetad.set(new MockGmetad(port, sampleXMLfilePath));
+ Thread mockGmetadServer = new Thread(mockGmetad.get());
+ mockGmetadServer.start();
+ }
+
+ private void generateTestConfig() throws IOException {
+ String propertiesFile = "." + File.separator + "src" + File.separator +
+ "test" + File.separator + "resources" + File.separator +
"test.resource.properties";
+ System.getProperties().load(new FileInputStream(new
File(propertiesFile)));
+ }
+
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/monitor/TestGangliaXMLParser.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,158 @@
+/*
+ * 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.resource.monitor;
+
+//Junit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+import org.apache.oodt.cas.resource.monitor.ganglia.GangliaMetKeys;
+import org.apache.oodt.cas.resource.monitor.ganglia.GangliaXMLParser;
+import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Cluster;
+import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Host;
+import org.apache.oodt.cas.resource.monitor.ganglia.configuration.Metric;
+
+//JDK imports
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author rajith
+ * @author mattmann
+ * @version $Revision$
+ *
+ * Test Suite for the {@link GangliaXMLParser}
+ */
+public class TestGangliaXMLParser extends TestCase {
+
+ private List<Cluster> gridConfiguration;
+
+ /**
+ * {@inheritDoc}
+ * Read gangliaXMLdump.xml and build the grid configuration
+ */
+ protected void setUp() throws MonitorException, IOException {
+ StringBuilder stringBuffer = new StringBuilder();
+
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader("." +
File.separator +
+ "src" + File.separator + "test" + File.separator +
"resources" + File.separator + "resourcemon"
+ + File.separator + "gangliaXMLdump.xml"));
+ String line = reader.readLine();
+ while (line != null) {
+ stringBuffer.append(line);
+ line = reader.readLine();
+ }
+ reader.close();
+ } catch (IOException e) {
+ throw new IOException("Unable to read the sample monitoring report
from the file: "
+ + e.getMessage());
+ }
+
+ String buffer = stringBuffer.toString().trim();
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ javax.xml.parsers.SAXParser parser;
+ GangliaXMLParser gangliaXMLParser;
+ try {
+ parser = factory.newSAXParser();
+ gangliaXMLParser = new GangliaXMLParser();
+ parser.parse(new InputSource(new StringReader(buffer)),
gangliaXMLParser);
+ gridConfiguration = gangliaXMLParser.getGridConfiguration();
+ } catch (ParserConfigurationException e) {
+ throw new MonitorException("Error while parsing: " +
e.getMessage());
+ } catch (SAXException e) {
+ throw new MonitorException("Error while parsing the XML: " +
e.getMessage());
+ } catch (IOException e) {
+ throw new MonitorException("I/O error: " + e.getMessage());
+ }
+ }
+
+ /**
+ * test the "<CLUSTER>" tag data
+ * <CLUSTER NAME="" LOCALTIME="" OWNER="" LATLONG="" URL="">
+ */
+ public void testClusterTag() {
+ Cluster cluster = gridConfiguration.get(0);
+ assertEquals("localcluster", cluster.getName());
+ assertEquals("1370187645", cluster.getLocaltime());
+ assertEquals("oodt", cluster.getOwner());
+ assertEquals("N32.87 W117.22", cluster.getLatLong());
+ assertEquals("http://www.mycluster.org/", cluster.getUrl());
+ }
+
+ /**
+ * test the "<HOST>" tag data
+ * <HOST NAME="" IP="" REPORTED="" TN="" TMAX="" DMAX="" LOCATION=""
GMOND_STARTED="">
+ */
+ public void testHostTag() {
+ Host host = ((gridConfiguration.get(0)).getHosts()).get(0);
+ assertEquals("localhost", host.getName());
+ assertEquals("127.0.0.1", host.getIp());
+ assertEquals("1370187637", host.getReported());
+ assertEquals("10", host.getTn());
+ assertEquals("20", host.getTmax());
+ assertEquals("0", host.getDmax());
+ assertEquals("0,0,0", host.getLocation());
+ assertEquals("1370186237", host.getGmondstarted());
+ }
+
+ /**
+ * test the "<METRIC>" tag data
+ * <METRIC NAME="" VAL="" TYPE="" UNITS="" TN="" TMAX="" DMAX="" SLOPE=""
SOURCE="">
+ * <EXTRA_DATA>
+ * <EXTRA_ELEMENT NAME="" VAL=""/>
+ * <EXTRA_ELEMENT NAME="" VAL=""/>
+ * ........
+ * </EXTRA_DATA>
+ * </METRIC>
+ */
+ public void testMetricTag() {
+ Metric metric =
((((gridConfiguration.get(0)).getHosts()).get(0)).getMetrics()).get(0);
+ assertEquals("disk_free", metric.getName());
+ assertEquals("307.790", metric.getValue());
+ assertEquals("double", metric.getType());
+ assertEquals("GB", metric.getUnits());
+ assertEquals("143", metric.getTn());
+ assertEquals("180", metric.getTmax());
+ assertEquals("0", metric.getDmax());
+ assertEquals("both", metric.getSlope());
+ assertEquals("gmond", metric.getSource());
+
+ //extra data of the metric
+ HashMap<String, String> extraData = metric.getExtraData();
+ assertEquals("disk", extraData.get(GangliaMetKeys.GROUP));
+ assertEquals("Total free disk space",
extraData.get(GangliaMetKeys.DESC));
+ assertEquals("Disk Space Available",
extraData.get(GangliaMetKeys.TITLE));
+ }
+
+ /**
+ * test the clusters in the grid
+ */
+ public void testGridClusters(){
+ Cluster localCluster = gridConfiguration.get(0);
+ Cluster remoteCluster = gridConfiguration.get(1);
+ assertEquals("localcluster", localCluster.getName());
+ assertEquals("remotecluster", remoteCluster.getName());
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxBatchmgr.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxBatchmgr.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxBatchmgr.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxBatchmgr.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,129 @@
+/*
+ * 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.resource.mux;
+
+//OODT imports
+import org.apache.oodt.cas.resource.mux.mocks.MockBatchManager;
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.JobExecutionException;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * @author starchmd
+ * @version $Revision$
+ *
+ * <p>
+ * Test Suite for the {@link QueueBatchMonitor} service
+ * </p>.
+ */
+public class TestQueueMuxBatchmgr extends TestCase {
+
+ private QueueMuxBatchManager queue;
+ private MockBatchManager mock1;
+ private MockBatchManager mock2;
+
+ protected void setUp() {
+ BackendManager back = new StandardBackendManager();
+ back.addSet("queue-1", null,(mock1 = new MockBatchManager()), null);
+ back.addSet("queue-2", null,(mock2 = new MockBatchManager()), null);
+ queue = new QueueMuxBatchManager(back);
+ }
+
+ public void testExecuteRemotely() {
+ try {
+
+ //Test that the jobs are put in seperate mock-backends based on
queues
+ ResourceNode node1 = new ResourceNode();
+ ResourceNode node2 = new ResourceNode();
+
+ JobSpec spec1 = this.getSpecFromQueue("queue-1");
+ queue.executeRemotely(spec1, node1);
+
+ JobSpec spec2 = this.getSpecFromQueue("queue-2");
+ queue.executeRemotely(spec2, node2);
+ //Yes...use reference equality, as these must be the exact same
object
+ TestCase.assertEquals(spec1,mock1.getCurrentJobSpec());
+ TestCase.assertEquals(spec2,mock2.getCurrentJobSpec());
+ TestCase.assertEquals(node1,mock1.getCurrentResourceNode());
+ TestCase.assertEquals(node2,mock2.getCurrentResourceNode());
+ //Throws exception on bad queue
+ try {
+ queue.executeRemotely(this.getSpecFromQueue("queue-3"),node1);
+ TestCase.fail("Failed to throw JobExecutionException on
unknown queue.");
+ } catch(JobExecutionException e) {}
+ } catch (JobExecutionException e) {
+ TestCase.fail("Unexpected Exception: "+e.getMessage());
+ }
+ }
+
+ public void testKillJob() {
+ try {
+ ResourceNode node1 = new ResourceNode();
+ ResourceNode node2 = new ResourceNode();
+
+ JobSpec spec1 = this.getSpecFromQueue("queue-1");
+ queue.executeRemotely(spec1, node1);
+
+ JobSpec spec2 = this.getSpecFromQueue("queue-2");
+ queue.executeRemotely(spec2, node2);
+ //Make sure that one can kill a job, and the other job is running
+ TestCase.assertTrue(queue.killJob(spec1.getJob().getId(), node1));
+ TestCase.assertEquals(mock1.getCurrentJobSpec(),null);
+ TestCase.assertEquals(mock2.getCurrentJobSpec(),spec2);
+ //Make sure kill fails with bad queue
+
TestCase.assertFalse(queue.killJob(this.getSpecFromQueue("queue-3").getJob().getId(),
node1));
+ } catch (JobExecutionException e) {
+ TestCase.fail("Unexpected Exception: "+e.getMessage());
+ }
+ }
+
+ public void testGetExecNode() {
+ try {
+ ResourceNode node1 = new ResourceNode();
+ ResourceNode node2 = new ResourceNode();
+ node1.setId("Node1-ID");
+ node2.setId("Node2-ID");
+ JobSpec spec1 = this.getSpecFromQueue("queue-1");
+ queue.executeRemotely(spec1, node1);
+
+ JobSpec spec2 = this.getSpecFromQueue("queue-2");
+ queue.executeRemotely(spec2, node2);
+ //Make that the execution node is same
+
TestCase.assertEquals(node1.getNodeId(),queue.getExecutionNode(spec1.getJob().getId()));
+
TestCase.assertEquals(node2.getNodeId(),queue.getExecutionNode(spec2.getJob().getId()));
+ //Returns null, if bad-queue
+
TestCase.assertNull(queue.getExecutionNode(this.getSpecFromQueue("queue-3").getJob().getId()));
+ } catch (JobExecutionException e) {
+ TestCase.fail("Unexpected Exception: "+e.getMessage());
+ }
+ }
+
+ private JobSpec getSpecFromQueue(String queue) {
+ JobSpec spec1 = new JobSpec();
+ Job job1 = new Job();
+ job1.setId("000000100000011-"+queue);
+ job1.setQueueName(queue);
+ spec1.setJob(job1);
+ return spec1;
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxMonitor.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxMonitor.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxMonitor.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/TestQueueMuxMonitor.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,204 @@
+/*
+ * 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.resource.mux;
+
+//OODT imports
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.oodt.cas.resource.mux.mocks.MockMonitor;
+import org.apache.oodt.cas.resource.scheduler.QueueManager;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+
+import org.apache.oodt.cas.resource.structs.exceptions.QueueManagerException;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * @author starchmd
+ * @version $Revision$
+ *
+ * <p>
+ * Test Suite for the {@link QueueBatchMonitor} service
+ * </p>.
+ */
+public class TestQueueMuxMonitor extends TestCase {
+
+ private QueueMuxMonitor monitor;
+ private MockMonitor mock1;
+ private MockMonitor mock2;
+ private ResourceNode superfluous;
+ private QueueManager qm;
+ Map<MockMonitor,List<ResourceNode>> map;
+
+ protected void setUp() {
+ try {
+ //Map monitor to nodes list
+ map = new HashMap<MockMonitor,List<ResourceNode>>();
+ List<ResourceNode> nodes1 = getNodesList("mock-1");
+ List<ResourceNode> nodes2 = getNodesList("mock-2");
+ //Backend Manager setup
+ BackendManager back = new StandardBackendManager();
+ back.addSet("queue-1",(mock1 = addMonitor(0,map,nodes1)), null,
null);
+ back.addSet("queue-2",(mock2 = addMonitor(5,map,nodes2)), null,
null);
+ //Make sure the queue manager is setup
+ qm = new QueueManager();
+ qm.addQueue("queue-1");
+ qm.addQueue("queue-2");
+ qm.addQueue("queue-3");
+ for (ResourceNode rn : nodes1)
+ qm.addNodeToQueue(rn.getNodeId(), "queue-1");
+ for (ResourceNode rn : nodes2)
+ qm.addNodeToQueue(rn.getNodeId(), "queue-2");
+ //Add an extra node to test "unknown queue"
+ qm.addNodeToQueue((superfluous = new
ResourceNode("superfluous-1",new URL("http://superfluous-1"),-2)).getNodeId(),
"queue-3");
+ monitor = new QueueMuxMonitor(back, qm);
+ } catch (QueueManagerException e) {
+ TestCase.fail("Unanticipated queue manager exception caught:
"+e.getMessage());
+ } catch (MalformedURLException e) {
+ TestCase.fail("Unanticipated URL exception caught:
"+e.getMessage());
+ }
+ }
+
+ public void testGetLoad() {
+ try {
+
TestCase.assertEquals(mock1.load,monitor.getLoad(map.get(mock1).get(0)));
+
TestCase.assertEquals(mock2.load,monitor.getLoad(map.get(mock2).get(0)));
+
+ /*try {
+ monitor.getLoad(superfluous);
+ TestCase.fail("Exception not thrown for unknown queue.");
+ } catch (MonitorException e) {
+ }*/
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ }
+ }
+
+ public void testGetNodes() {
+ try {
+ List<ResourceNode> nodes = monitor.getNodes();
+ for (ResourceNode rn :map.get(mock1))
+ TestCase.assertTrue("Node: "+rn.getNodeId()+ " not found.",
nodes.contains(rn));
+ for (ResourceNode rn :map.get(mock2))
+ TestCase.assertTrue("Node: "+rn.getNodeId()+ " not found.",
nodes.contains(rn));
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ }
+ }
+
+ public void testGetNodeById() {
+ try {
+
TestCase.assertEquals(map.get(mock1).get(0),monitor.getNodeById("mock-1-1"));
+
TestCase.assertEquals(map.get(mock2).get(0),monitor.getNodeById("mock-2-1"));
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ }
+ }
+ public void testGetNodeByURL() {
+ try {
+
TestCase.assertEquals(map.get(mock1).get(1),monitor.getNodeByURL(new
URL("http://mock-1-2")));
+
TestCase.assertEquals(map.get(mock2).get(1),monitor.getNodeByURL(new
URL("http://mock-2-2")));
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ } catch (MalformedURLException e1) {
+ TestCase.fail("Unanticipated URL exception caught:
"+e1.getMessage());
+ }
+ }
+
+ public void testReduceLoad() {
+ try {
+ TestCase.assertTrue(monitor.reduceLoad(map.get(mock1).get(2), 5));
+ TestCase.assertTrue(monitor.reduceLoad(map.get(mock2).get(2), 3));
+ TestCase.assertEquals(map.get(mock1).get(2).getCapacity(),25);
+ TestCase.assertEquals(map.get(mock2).get(2).getCapacity(),27);
+ try {
+ monitor.reduceLoad(superfluous, 2);
+ TestCase.fail("Exception not thrown for unknown queue.");
+ } catch (MonitorException e) {}
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ }
+ }
+
+ public void testAssignLoad() {
+ try {
+ TestCase.assertTrue(monitor.assignLoad(map.get(mock1).get(2), 5));
+ TestCase.assertTrue(monitor.assignLoad(map.get(mock2).get(2), 3));
+ TestCase.assertEquals(map.get(mock1).get(2).getCapacity(),5);
+ TestCase.assertEquals(map.get(mock2).get(2).getCapacity(),3);
+ try {
+ monitor.assignLoad(superfluous, 2);
+ TestCase.fail("Exception not thrown for unknown queue.");
+ } catch (MonitorException e) {}
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ }
+ }
+
+ public void testAddNode() {
+ try {
+ ResourceNode node = new ResourceNode("a-new-node",null,2);
+ qm.addNodeToQueue(node.getNodeId(), "queue-1");
+ monitor.addNode(node);
+ TestCase.assertEquals(node,mock1.getAdded());
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ } catch (QueueManagerException e1) {
+ TestCase.fail("Unanticipated queue manager exception caught:
"+e1.getMessage());
+ }
+ }
+ public void removeNodeById() {
+ try {
+ ResourceNode node = new ResourceNode("a-new-node",null,2);
+ qm.addNodeToQueue(node.getNodeId(), "queue-1");
+ monitor.addNode(node);
+ TestCase.assertEquals(node,mock1.getAdded());
+ monitor.removeNodeById(node.getNodeId());
+ TestCase.assertEquals(null,mock1.getAdded());
+ } catch(MonitorException e) {
+ TestCase.fail("Unanticipated monitor exception caught:
"+e.getMessage());
+ } catch (QueueManagerException e1) {
+ TestCase.fail("Unanticipated queue manager exception caught:
"+e1.getMessage());
+ }
+ }
+
+ private MockMonitor addMonitor(int load,Map<MockMonitor,
List<ResourceNode>> map, List<ResourceNode> list) {
+ MockMonitor mon = new MockMonitor(load, list, list.get(0),
list.get(1), list.get(2));
+ map.put(mon, list);
+ return mon;
+ }
+ private List<ResourceNode> getNodesList(String prefix) {
+ List<ResourceNode> nodes = new LinkedList<ResourceNode>();
+ try {
+ nodes.add(new ResourceNode(prefix+"-1",new
URL("http://"+prefix+"-1"),10));
+ nodes.add(new ResourceNode(prefix+"-2",new
URL("http://"+prefix+"-2"),20));
+ nodes.add(new ResourceNode(prefix+"-3",new
URL("http://"+prefix+"-3"),30));
+ nodes.add(new ResourceNode(prefix+"-4",new
URL("http://"+prefix+"-4"),40));
+ } catch (MalformedURLException e) {
+ TestCase.fail("Unanticipated URL exception caught:
"+e.getMessage());
+ }
+ return nodes;
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockBatchManager.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,82 @@
+/*
+ * 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.resource.mux.mocks;
+
+import org.apache.oodt.cas.resource.batchmgr.Batchmgr;
+import org.apache.oodt.cas.resource.jobrepo.JobRepository;
+import org.apache.oodt.cas.resource.monitor.Monitor;
+import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.JobExecutionException;
+/**
+ * This is a mock version of the batch manager. It SHOULD NOT, and
+ * CAN NOT be used as a normal class.
+ *
+ * @author starchmd
+ */
+public class MockBatchManager implements Batchmgr {
+
+ private JobSpec execJobSpec;
+ private ResourceNode execResNode;
+
+ @Override
+ public boolean executeRemotely(JobSpec job, ResourceNode resNode)
+ throws JobExecutionException {
+ this.execJobSpec = job;
+ this.execResNode = resNode;
+ return true;
+ }
+
+ @Override
+ public void setMonitor(Monitor monitor) {}
+
+ @Override
+ public void setJobRepository(JobRepository repository) {}
+
+ @Override
+ public boolean killJob(String jobId, ResourceNode node) {
+ if (this.execJobSpec.getJob().getId().equals(jobId))
+ {
+ this.execJobSpec = null;
+ this.execResNode = null;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String getExecutionNode(String jobId) {
+ return execResNode.getNodeId();
+ }
+ /*****
+ * The following are test methods to report what jobs are here.
+ *****/
+ /**
+ * Return the current jobspec, for testing purposes
+ * @return
+ */
+ public JobSpec getCurrentJobSpec() {
+ return this.execJobSpec;
+ }
+ /**
+ * Return the current resource node, for testing purposes
+ * @return
+ */
+ public ResourceNode getCurrentResourceNode() {
+ return execResNode;
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockMonitor.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockMonitor.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockMonitor.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/mux/mocks/MockMonitor.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,91 @@
+/*
+ * 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.resource.mux.mocks;
+
+import java.net.URL;
+import java.util.List;
+
+import org.apache.oodt.cas.resource.monitor.Monitor;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+
+public class MockMonitor implements Monitor {
+
+ public int load = -1;
+ List<ResourceNode> nodes;
+ ResourceNode id;
+ ResourceNode url;
+ ResourceNode add;
+ ResourceNode reduce;
+
+ public MockMonitor(int load,List<ResourceNode> nodes, ResourceNode id,
ResourceNode url, ResourceNode reduce) {
+ this.load = load;
+ this.nodes = nodes;
+ this.id = id;
+ this.url = url;
+ this.reduce = reduce;
+ }
+
+ @Override
+ public int getLoad(ResourceNode node) throws MonitorException {
+ return load;
+ }
+ @Override
+ public List getNodes() throws MonitorException {
+ return nodes;
+ }
+
+ @Override
+ public ResourceNode getNodeById(String nodeId) throws MonitorException {
+ return id.getNodeId().equals(nodeId)?id:null;
+ }
+
+ @Override
+ public ResourceNode getNodeByURL(URL ipAddr) throws MonitorException {
+ return url.getIpAddr().equals(ipAddr)?url:null;
+ }
+
+ @Override
+ public boolean reduceLoad(ResourceNode node, int loadValue)
+ throws MonitorException {
+ reduce.setCapacity(reduce.getCapacity() - loadValue);
+ return true;
+ }
+
+ @Override
+ public boolean assignLoad(ResourceNode node, int loadValue)
+ throws MonitorException {
+ reduce.setCapacity(loadValue);
+ return true;
+ }
+
+ @Override
+ public void addNode(ResourceNode node) throws MonitorException {
+ this.add = node;
+
+ }
+
+ @Override
+ public void removeNodeById(String nodeId) throws MonitorException {
+ if (this.add.getNodeId().equals(nodeId))
+ this.add = null;
+ }
+
+ public ResourceNode getAdded() {
+ return this.add;
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/queuerepo/TestXmlQueueRepository.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/queuerepo/TestXmlQueueRepository.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/queuerepo/TestXmlQueueRepository.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/queuerepo/TestXmlQueueRepository.java
Wed Jan 21 23:21:27 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.resource.queuerepo;
+
+//JDK imports
+import java.io.File;
+import java.util.Arrays;
+
+//OODT imports
+import org.apache.oodt.cas.resource.scheduler.QueueManager;
+import org.apache.oodt.cas.resource.structs.exceptions.QueueManagerException;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Test Suite for the {@link XmlQueueRepository} service
+ * </p>.
+ */
+public class TestXmlQueueRepository extends TestCase {
+
+ private QueueManager queueManager;
+
+ protected void setUp() {
+
System.setProperty("org.apache.oodt.cas.resource.nodetoqueues.dirs",
+ "file:"
+ + new
File("./src/main/resources/examples")
+
.getAbsolutePath());
+ this.queueManager = new
XmlQueueRepositoryFactory().createQueueRepository().loadQueues();
+ }
+
+ public void testMapping() throws QueueManagerException {
+
assertTrue(this.queueManager.getQueues().containsAll(Arrays.asList("quick",
"high", "long")));
+ assertEquals(this.queueManager.getNodes("quick"),
Arrays.asList("localhost"));
+ assertEquals(this.queueManager.getNodes("high"),
Arrays.asList("localhost"));
+ assertEquals(this.queueManager.getNodes("long"),
Arrays.asList("localhost"));
+
assertTrue(this.queueManager.getQueues("localhost").containsAll(Arrays.asList("quick",
"high", "long")));
+
+ this.queueManager.addQueue("test-queue-1");
+ this.queueManager.addNodeToQueue("test-node-1", "test-queue-1");
+
+ assertEquals(this.queueManager.getQueues("test-node-1"),
Arrays.asList("test-queue-1"));
+
+ this.queueManager.addNodeToQueue("test-node-1","quick");
+ assertEquals(this.queueManager.getQueues("test-node-1"),
Arrays.asList("quick", "test-queue-1"));
+
+ this.queueManager.removeQueue("quick");
+ assertEquals(this.queueManager.getQueues("test-node-1"),
Arrays.asList("test-queue-1"));
+ assertEquals(this.queueManager.getQueues("localhost"),
Arrays.asList("high", "long"));
+ }
+
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/schedule/MockScheduler.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/schedule/MockScheduler.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/schedule/MockScheduler.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/schedule/MockScheduler.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,63 @@
+/*
+ * 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.resource.schedule;
+
+//OODT imports
+import org.apache.oodt.cas.resource.batchmgr.Batchmgr;
+import org.apache.oodt.cas.resource.jobqueue.JobQueue;
+import org.apache.oodt.cas.resource.monitor.Monitor;
+import org.apache.oodt.cas.resource.scheduler.QueueManager;
+import org.apache.oodt.cas.resource.scheduler.Scheduler;
+import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.SchedulerException;
+
+/**
+ * A Mock {@link Scheduler}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class MockScheduler implements Scheduler {
+
+ public void run() {
+ // Do nothing.
+ }
+
+ public boolean schedule(JobSpec spec) throws SchedulerException {
+ return false;
+ }
+
+ public ResourceNode nodeAvailable(JobSpec spec) throws SchedulerException {
+ return null;
+ }
+
+ public Monitor getMonitor() {
+ return null;
+ }
+
+ public Batchmgr getBatchmgr() {
+ return null;
+ }
+
+ public JobQueue getJobQueue() {
+ return null;
+ }
+
+ public QueueManager getQueueManager() {
+ return null;
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/MockXmlRpcResourceManagerClient.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/MockXmlRpcResourceManagerClient.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/MockXmlRpcResourceManagerClient.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/MockXmlRpcResourceManagerClient.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,188 @@
+/*
+ * 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.resource.system;
+
+//JDK imports
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.resource.examples.HelloWorldJob;
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.JobInput;
+import org.apache.oodt.cas.resource.structs.NameValueJobInput;
+import org.apache.oodt.cas.resource.structs.ResourceNode;
+import org.apache.oodt.cas.resource.structs.exceptions.JobExecutionException;
+import org.apache.oodt.cas.resource.structs.exceptions.JobRepositoryException;
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+import org.apache.oodt.cas.resource.structs.exceptions.QueueManagerException;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+/**
+ * Mock implementation of {@link XmlRpcResourceManagerClient}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class MockXmlRpcResourceManagerClient extends
+ XmlRpcResourceManagerClient {
+
+ private MethodCallDetails lastMethodCallDetails;
+
+ public MockXmlRpcResourceManagerClient() throws MalformedURLException {
+ super(new URL("http://localhost:9000"));
+ }
+
+ public MethodCallDetails getLastMethodCallDetails() {
+ return lastMethodCallDetails;
+ }
+
+ public void addNode(ResourceNode node) throws MonitorException {
+ lastMethodCallDetails = new MethodCallDetails("addNode",
+ Lists.newArrayList((Object) node));
+ }
+
+ public void addNodeToQueue(String nodeId, String queueName)
+ throws QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("addNodeToQueue",
+ Lists.newArrayList((Object) nodeId, queueName));
+ }
+
+ public void addQueue(String queueName) throws QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("addQueue",
+ Lists.newArrayList((Object) queueName));
+ }
+
+ public String getExecutionNode(String jobId) {
+ lastMethodCallDetails = new MethodCallDetails("getExecutionNode",
+ Lists.newArrayList((Object) jobId));
+ return "TestNodeId";
+ }
+
+ public Job getJobInfo(String jobId) throws JobRepositoryException {
+ lastMethodCallDetails = new MethodCallDetails("getJobInfo",
+ Lists.newArrayList((Object) jobId));
+ Job job = new Job();
+ job.setId(jobId);
+ job.setName("TestJobName");
+ job.setJobInputClassName(NameValueJobInput.class.getCanonicalName());
+ job.setJobInstanceClassName(HelloWorldJob.class.getCanonicalName());
+ job.setLoadValue(4);
+ job.setQueueName("TestQueueName");
+ job.setStatus("DONE");
+ return job;
+ }
+
+ public ResourceNode getNodeById(String nodeId) throws MonitorException {
+ lastMethodCallDetails = new MethodCallDetails("getNodeById",
+ Lists.newArrayList((Object) nodeId));
+ try {
+ return new ResourceNode(nodeId, new URL("http://localhost:9999"), 5);
+ } catch (Exception e) {
+ throw new MonitorException(e);
+ }
+ }
+
+ public String getNodeLoad(String nodeId) throws MonitorException {
+ lastMethodCallDetails = new MethodCallDetails("getNodeLoad",
+ Lists.newArrayList((Object) nodeId));
+ return "10";
+ }
+
+ public List<ResourceNode> getNodes() throws MonitorException {
+ lastMethodCallDetails = new MethodCallDetails("getNodes",
+ Lists.newArrayList());
+ return Lists.newArrayList();
+ }
+
+ public List<String> getNodesInQueue(String queueName)
+ throws QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("getNodesInQueue",
+ Lists.newArrayList((Object) queueName));
+ return Lists.newArrayList();
+ }
+
+ public List<String> getQueues() throws QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("getQueues",
+ Lists.newArrayList());
+ return Lists.newArrayList();
+ }
+
+ public List<String> getQueuesWithNode(String nodeId) throws
QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("getQueuesWithNode",
+ Lists.newArrayList((Object) nodeId));
+ return Lists.newArrayList();
+ }
+
+ public boolean killJob(String jobId) {
+ lastMethodCallDetails = new MethodCallDetails("killJob",
+ Lists.newArrayList((Object) jobId));
+ return true;
+ }
+
+ public void removeNode(String nodeId) throws MonitorException {
+ lastMethodCallDetails = new MethodCallDetails("removeNode",
+ Lists.newArrayList((Object) nodeId));
+ }
+
+ public void removeNodeFromQueue(String nodeId, String queueName) throws
QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("removeNodeFromQueue",
+ Lists.newArrayList((Object) nodeId, queueName));
+ }
+
+ public void removeQueue(String queueName) throws QueueManagerException {
+ lastMethodCallDetails = new MethodCallDetails("removeQueue",
+ Lists.newArrayList((Object) queueName));
+ }
+
+ public void setNodeCapacity(String nodeId, int capacity) throws
MonitorException{
+ lastMethodCallDetails = new MethodCallDetails("setNodeCapacity",
+ Lists.newArrayList((Object) nodeId, capacity));
+ }
+
+ public String submitJob(Job exec, JobInput in) throws JobExecutionException
{
+ lastMethodCallDetails = new MethodCallDetails("submitJob",
+ Lists.newArrayList((Object) exec, in));
+ return "TestJobId";
+ }
+
+ public boolean submitJob(Job exec, JobInput in, URL url) throws
JobExecutionException {
+ lastMethodCallDetails = new MethodCallDetails("submitJob",
+ Lists.newArrayList((Object) exec, in, url));
+ return true;
+ }
+
+ public class MethodCallDetails {
+ private String methodName;
+ private List<Object> args;
+
+ public MethodCallDetails(String methodName, List<Object> args) {
+ this.methodName = methodName;
+ this.args = args;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ public List<Object> getArgs() {
+ return args;
+ }
+ }
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManager.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,157 @@
+/**
+ * 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.resource.system;
+
+//JDK imports
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+//Apache imports
+import org.apache.commons.io.FileUtils;
+
+//OODT imports
+import org.apache.oodt.cas.resource.structs.exceptions.MonitorException;
+
+//Junit imports
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test harness for the {@link XmlRpcResourceManager}.
+ *
+ * @author mattmann
+ * @author rajith
+ * @version $Revision$
+ *
+ */
+public class TestXmlRpcResourceManager extends TestCase {
+
+ private File tmpPolicyDir;
+
+ private XmlRpcResourceManager rm;
+
+ private static final int RM_PORT = 50001;
+
+ /**
+ * @since OODT-182
+ */
+ public void testDynSetNodeCapacity() {
+ XmlRpcResourceManagerClient rmc = null;
+ try {
+ rmc = new XmlRpcResourceManagerClient(new URL("http://localhost:"
+ + RM_PORT));
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ assertNotNull(rmc);
+ try {
+ rmc.setNodeCapacity("localhost", 8);
+ } catch (MonitorException e) {
+ fail(e.getMessage());
+ }
+
+ int setCapacity = -1;
+ try {
+ setCapacity = rmc.getNodeById("localhost").getCapacity();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ assertEquals(8, setCapacity);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ generateTestConfiguration();
+ this.rm = new XmlRpcResourceManager(RM_PORT);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ this.rm.shutdown();
+ deleteAllFiles(this.tmpPolicyDir.getAbsolutePath());
+ }
+
+ 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();
+
+ }
+
+ private void generateTestConfiguration() throws IOException {
+ Properties config = new Properties();
+
+ String propertiesFile = "." + File.separator + "src" + File.separator +
+ "test" + File.separator + "resources" + File.separator +
"test.resource.properties";
+ System.getProperties().load(new FileInputStream(new File(propertiesFile)));
+
+ // stage policy
+ File tmpPolicyDir = null;
+ try {
+ tmpPolicyDir = File.createTempFile("test", "ignore").getParentFile();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ for (File policyFile : new File("./src/test/resources/policy")
+ .listFiles(new FileFilter() {
+
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.isFile() && pathname.getName().endsWith(".xml");
+ }
+ })) {
+ try {
+ FileUtils.copyFileToDirectory(policyFile, tmpPolicyDir);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+ config.setProperty("org.apache.oodt.cas.resource.nodes.dirs", tmpPolicyDir
+ .toURI().toString());
+ config.setProperty("org.apache.oodt.cas.resource.nodetoqueues.dirs",
+ tmpPolicyDir.toURI().toString());
+
+ System.getProperties().putAll(config);
+ this.tmpPolicyDir = tmpPolicyDir;
+ }
+
+}
Added:
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/TestMesosUtilities.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/TestMesosUtilities.java?rev=1653695&view=auto
==============================================================================
---
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/TestMesosUtilities.java
(added)
+++
oodt/trunk/resource/src/test/java/org/apache/oodt/cas/resource/util/TestMesosUtilities.java
Wed Jan 21 23:21:27 2015
@@ -0,0 +1,82 @@
+/*
+ * 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.resource.util;
+
+import org.apache.oodt.cas.resource.structs.Job;
+import org.apache.oodt.cas.resource.structs.JobSpec;
+import org.apache.oodt.cas.resource.structs.NameValueJobInput;
+
+
+import org.apache.oodt.cas.resource.util.MesosUtilities;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * @author starchmd
+ * @version $Revision$
+ *
+ * <p>
+ * Test Suite for the {@link MesosUtilities} class
+ * </p>.
+ */
+public class TestMesosUtilities extends TestCase {
+
+ public void testSerialization() {
+ JobSpec js = new JobSpec();
+
+ Job job = new Job();
+ job.setId("crazy-id");
+ job.setJobInputClassName(NameValueJobInput.class.getCanonicalName());
+ job.setJobInstanceClassName("Instance Class");
+ job.setLoadValue(new Integer(352));
+ job.setName("A Name");
+ job.setQueueName("Queue");
+ job.setStatus("Status");
+
+ String[] props = {"prop-1","prop-2","prop-3"};
+ NameValueJobInput nvji = new NameValueJobInput();
+ for (String str : props)
+ nvji.setNameValuePair(str, str+"val");
+
+ js.setIn(nvji);
+ js.setJob(job);
+
+ JobSpec ns;
+ try {
+ ns =
MesosUtilities.byteStringToJobSpec(MesosUtilities.jobSpecToByteString(js));
+ TestCase.assertEquals(js.getJob().getId(),ns.getJob().getId());
+
TestCase.assertEquals(js.getJob().getJobInputClassName(),ns.getJob().getJobInputClassName());
+
TestCase.assertEquals(js.getJob().getJobInstanceClassName(),ns.getJob().getJobInstanceClassName());
+
TestCase.assertEquals(js.getJob().getLoadValue(),ns.getJob().getLoadValue());
+ TestCase.assertEquals(js.getJob().getName(),ns.getJob().getName());
+
TestCase.assertEquals(js.getJob().getQueueName(),ns.getJob().getQueueName());
+
TestCase.assertEquals(js.getJob().getStatus(),ns.getJob().getStatus());
+ TestCase.assertEquals(js.getIn().getId(),ns.getIn().getId());
+ for (String str : props)
+
TestCase.assertEquals(nvji.getValue(str),((NameValueJobInput)ns.getIn()).getValue(str));
+ } catch (ClassNotFoundException e) {
+ TestCase.fail("Unexpected exception:"+e.getLocalizedMessage());
+ } catch (InstantiationException e) {
+ TestCase.fail("Unexpected exception:"+e.getLocalizedMessage());
+ } catch (IllegalAccessException e) {
+ TestCase.fail("Unexpected exception:"+e.getLocalizedMessage());
+ }
+
+ }
+
+}