You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2015/11/05 17:53:03 UTC

oodt git commit: OODT-917 tests for RM to validate XMLRPC interface

Repository: oodt
Updated Branches:
  refs/heads/master 4c8109b34 -> 773f78feb


OODT-917 tests for RM to validate XMLRPC interface


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/773f78fe
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/773f78fe
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/773f78fe

Branch: refs/heads/master
Commit: 773f78feb442a55629760c0eca252b9af7d4ec2c
Parents: 4c8109b
Author: Tom Barber <to...@analytical-labs.com>
Authored: Thu Nov 5 16:52:52 2015 +0000
Committer: Tom Barber <to...@analytical-labs.com>
Committed: Thu Nov 5 16:52:52 2015 +0000

----------------------------------------------------------------------
 resource/pom.xml                                |  18 +-
 .../system/TestXmlRpcResourceManagerClient.java | 190 +++++++++++++++++++
 2 files changed, 195 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/773f78fe/resource/pom.xml
----------------------------------------------------------------------
diff --git a/resource/pom.xml b/resource/pom.xml
index ef21585..9ae48e3 100644
--- a/resource/pom.xml
+++ b/resource/pom.xml
@@ -63,22 +63,18 @@ the License.
     <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>
-      <version>1.3</version>
     </dependency>
     <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
-      <version>3.2.1</version>
     </dependency>
     <dependency>
       <groupId>commons-dbcp</groupId>
       <artifactId>commons-dbcp</artifactId>
-      <version>1.2.1</version>
     </dependency>
     <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
-      <version>3.0</version>
     </dependency>
     <dependency>
       <groupId>commons-io</groupId>
@@ -87,49 +83,45 @@ the License.
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
-      <version>1.0.3</version>
     </dependency>
     <dependency>
       <groupId>commons-pool</groupId>
       <artifactId>commons-pool</artifactId>
-      <version>1.2</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.2</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
-      <version>4.2.1</version>
     </dependency>
     <dependency>
       <groupId>org.apache.lucene</groupId>
       <artifactId>lucene-core</artifactId>
-      <version>2.0.0</version>
     </dependency>
     <dependency>
       <groupId>org.apache.oodt</groupId>
       <artifactId>cas-cli</artifactId>
-      <version>${project.parent.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.oodt</groupId>
       <artifactId>cas-metadata</artifactId>
-      <version>${project.parent.version}</version>
     </dependency>
     <dependency>
       <groupId>org.safehaus.jug</groupId>
       <artifactId>jug</artifactId>
-      <version>2.0.0</version>
       <classifier>asl</classifier>
     </dependency>
     <dependency>
       <groupId>xmlrpc</groupId>
       <artifactId>xmlrpc</artifactId>
-      <version>2.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
+      <scope>test</scope>
     </dependency>
   </dependencies>
   <build>

http://git-wip-us.apache.org/repos/asf/oodt/blob/773f78fe/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManagerClient.java
----------------------------------------------------------------------
diff --git a/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManagerClient.java b/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManagerClient.java
new file mode 100644
index 0000000..a4a6852
--- /dev/null
+++ b/resource/src/test/java/org/apache/oodt/cas/resource/system/TestXmlRpcResourceManagerClient.java
@@ -0,0 +1,190 @@
+package org.apache.oodt.cas.resource.system;
+
+import org.apache.commons.io.FileUtils;
+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;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Created by bugg on 05/11/15.
+ */
+public class TestXmlRpcResourceManagerClient {
+
+  private static final int RM_PORT = 50001;
+
+  private static XmlRpcResourceManager rm;
+  private static File thetmpPolicyDir;
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    generateTestConfiguration();
+    rm = new XmlRpcResourceManager(RM_PORT);
+  }
+
+  private static 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);
+    thetmpPolicyDir = tmpPolicyDir;
+  }
+
+  @Test
+  public void testGetNodes() throws MonitorException {
+    List<Hashtable> nodes = rm.getNodes();
+
+    assertThat(nodes, is(not(nullValue())));
+    assertThat(nodes, hasSize(1));
+
+  }
+
+  @Test
+  public void testGetExecutionReport() throws JobRepositoryException {
+
+    String execreport = rm.getExecutionReport();
+
+
+    assertThat(execreport, is(not(nullValue())));
+    //TODO make it return more than an empty string;
+  }
+
+
+  @Test
+  public void testJobQueueCapacity() throws JobRepositoryException {
+    int capacity = rm.getJobQueueCapacity();
+
+    assertThat(capacity, equalTo(1000));
+
+  }
+
+  @Test
+  public void testGetJobQueueSize() throws JobRepositoryException {
+    int size = rm.getJobQueueSize();
+
+    assertThat(size, equalTo(0));
+
+    //TODO Make it change queue size
+
+  }
+
+  @Test
+  public void testGetNodeById() throws MonitorException {
+    List<Hashtable> nodelist = rm.getNodes();
+
+    Map node = rm.getNodeById((String) nodelist.get(0).get("node.id"));
+
+    assertThat(node, is(not(nullValue())));
+
+    assertThat((String)node.get("node.id"), equalTo("localhost"));
+  }
+
+
+  @Test
+  public void testGetNodeLoad() throws MonitorException {
+
+    List<Hashtable> nodelist = rm.getNodes();
+
+    String node = rm.getNodeLoad((String) nodelist.get(0).get("node.id"));
+
+    assertNotNull(node);
+
+    assertThat(node, equalTo("0/8"));
+
+  }
+
+  @Test
+  public void testNodeReport() throws MonitorException {
+    String report = rm.getNodeReport();
+
+    assertThat(report, is(not(nullValue())));
+  }
+
+  @Test
+  public void testGetNodesInQueue() throws QueueManagerException {
+    List<String> nodes = rm.getNodesInQueue("long");
+
+    assertThat(nodes, is(not(nullValue())));
+
+    assertThat(nodes, hasSize(1));
+
+  }
+
+
+  @Test
+  public void testQueuedJobs(){
+    List jobs = rm.getQueuedJobs();
+
+    assertThat(jobs, is(not(nullValue())));
+
+    //TODO queue a job
+  }
+
+  @Test
+  public void testQueuesWithNode() throws MonitorException {
+    List<Hashtable> nodelist = rm.getNodes();
+
+
+    List<String> queues = rm.getQueuesWithNode((String) nodelist.get(0).get("node.id"));
+    assertThat(queues, hasSize(3));
+
+    assertThat(queues, containsInAnyOrder("high", "quick", "long"));
+  }
+
+  @Test
+  public void testQueues(){
+    List<String> queues = rm.getQueues();
+
+    assertThat(queues, hasSize(3));
+
+    assertThat(queues, containsInAnyOrder("high", "quick", "long"));
+  }
+
+}