Commits

Erik Hetzner committed d4f6e98

add some testing

Comments (0)

Files changed (2)

         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <version>6.0.1</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   
   <build>

src/test/java/org/cdlib/mrt/queueTest/QueueTest.java

+package org.cdlib.mrt.queueTest;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.KeeperException;
+
+import org.cdlib.mrt.queue.*;
+
+import org.testng.annotations.*;
+
+public class QueueTest {
+
+    ZooKeeper zk;
+
+    DistributedQueue q;
+    @BeforeClass
+    public void setUp() {
+        try {
+            this.zk = new ZooKeeper("localhost:2181", 10000, new DistributedQueue.Ignorer());
+            this.q = new DistributedQueue(zk, "/queueTest", null);
+        } catch (IOException ex) {
+            assert(false);
+        }
+    }
+    
+    @Test(groups = { "functional" },
+          dependsOnMethods = { "emptyQueueShouldRaiseEx" })
+    public void canAddToQueue() {
+        try {
+            assert(q.submit("hello world".getBytes("UTF-8")));
+            Item item = q.consume();
+            q.complete(item.getId());
+
+        } catch (IOException ex) {
+            assert(false);
+        } catch (InterruptedException ex) {
+            assert(false);
+        } catch (KeeperException ex) {
+            assert(false);
+        }
+    }
+
+    @Test(groups = { "functional" })
+    public void canCleanup() {
+        try {
+            /* cleanup throws an exception when it is done */
+            q.cleanup(Item.COMPLETED);
+            assert(false);
+        } catch (NoSuchElementException ex) {
+            assert(true);
+        } catch (KeeperException ex) {
+            assert(false);
+        } catch (InterruptedException ex) {
+            assert(false);
+        }
+    }
+
+    @Test(groups = { "functional" },
+          dependsOnMethods = { "canCleanup"})
+    public void queueShouldBeEmpty() {
+        try {
+            List<String> children = this.zk.getChildren("/queueTest", false);
+            assert(children.size() == 0);
+        } catch (KeeperException ex) {
+            assert(false);
+        } catch (InterruptedException ex) {
+            assert(false);
+        }
+    }
+
+    @Test(groups = { "functional" })
+    public void emptyQueueShouldRaiseEx() {
+        try {
+            q.consume();
+            assert(false);
+        } catch (NoSuchElementException ex) {
+            assert(true);
+        } catch (KeeperException ex) {
+            assert(false);
+        } catch (InterruptedException ex) {
+            assert(false);
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.