zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1240954 - in /zookeeper/trunk: CHANGES.txt src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
Date Mon, 06 Feb 2012 09:58:27 GMT
Author: mahadev
Date: Mon Feb  6 09:58:27 2012
New Revision: 1240954

URL: http://svn.apache.org/viewvc?rev=1240954&view=rev
Log:
ZOOKEEPER-1337. multi's "Transaction" class is missing tests. (camille and phunt via mahadev)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1240954&r1=1240953&r2=1240954&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Feb  6 09:58:27 2012
@@ -127,6 +127,9 @@ BUGFIXES:
 
   ZOOKEEPER-1374. C client multi-threaded test suite fails to compile 
   on ARM architectures. (James Page via mahadev)
+
+  ZOOKEEPER-1337. multi's "Transaction" class is missing tests. (camille
+  and phunt via mahadev)
  
 IMPROVEMENTS:
 

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java?rev=1240954&r1=1240953&r2=1240954&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/test/MultiTransactionTest.java Mon
Feb  6 09:58:27 2012
@@ -17,9 +17,7 @@
 
 package org.apache.zookeeper.test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -33,11 +31,14 @@ import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Op;
 import org.apache.zookeeper.OpResult;
-import org.apache.zookeeper.OpResult.ErrorResult;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.OpResult.CheckResult;
+import org.apache.zookeeper.OpResult.CreateResult;
+import org.apache.zookeeper.OpResult.DeleteResult;
+import org.apache.zookeeper.OpResult.ErrorResult;
+import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.server.SyncRequestProcessor;
 import org.junit.Assert;
 import org.junit.Before;
@@ -236,6 +237,85 @@ public class MultiTransactionTest extend
         cb.done.await(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
         assertEquals(1, watcher.triggered.getCount());
     }
+    
+    @Test
+    public void testTransactionBuilder() throws Exception {
+        List<OpResult> results = zk.transaction()
+                .create("/t1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
+                .create("/t1/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
+                .create("/t2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL)
+                .commit();
+        assertEquals(3, results.size());
+        for (OpResult r : results) {
+            CreateResult c = (CreateResult)r;
+            assertTrue(c.getPath().startsWith("/t"));
+            assertNotNull(c.toString());
+        }
+        assertNotNull(zk.exists("/t1", false));
+        assertNotNull(zk.exists("/t1/child", false));
+        assertNotNull(zk.exists("/t2", false));
+        
+        results = zk.transaction()
+                .check("/t1", 0)
+                .check("/t1/child", 0)
+                .check("/t2", 0)
+                .commit();
+        assertEquals(3, results.size());
+        for (OpResult r : results) {
+            CheckResult c = (CheckResult)r;
+            assertNotNull(c.toString());
+        }
+        
+        try {
+            results = zk.transaction()
+                    .check("/t1", 0)
+                    .check("/t1/child", 0)
+                    .check("/t2", 1)
+                    .commit();
+            fail();
+        } catch (KeeperException.BadVersionException e) {
+            // expected
+        }
+        
+        results = zk.transaction()
+                .check("/t1", 0)
+                .setData("/t1", new byte[0], 0)
+                .commit();
+        assertEquals(2, results.size());
+        for (OpResult r : results) {
+            assertNotNull(r.toString());
+        }
+
+        try {
+            results = zk.transaction()
+                    .check("/t1", 1)
+                    .setData("/t1", new byte[0], 2)
+                    .commit();
+            fail();
+        } catch (KeeperException.BadVersionException e) {
+            // expected
+        }
+        
+        results = zk.transaction()
+                .check("/t1", 1)
+                .check("/t1/child", 0)
+                .check("/t2", 0)
+                .commit();
+        assertEquals(3, results.size());
+
+        results = zk.transaction()
+                .delete("/t2", -1)
+                .delete("/t1/child", -1)
+                .commit();
+        assertEquals(2, results.size());
+        for (OpResult r : results) {
+            DeleteResult d = (DeleteResult)r;
+            assertNotNull(d.toString());
+        }
+        assertNotNull(zk.exists("/t1", false));
+        assertNull(zk.exists("/t1/child", false));
+        assertNull(zk.exists("/t2", false));
+    }
 
     private static class HasTriggeredWatcher implements Watcher {
         private final CountDownLatch triggered = new CountDownLatch(1);



Mime
View raw message