ソースを参照

fix for ZOOKEEPER-132, creation enum to replace createflag

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@693164 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt 16 年 前
コミット
931322a7c7

+ 89 - 0
src/java/main/org/apache/zookeeper/CreateMode.java

@@ -0,0 +1,89 @@
+/**
+ * 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.zookeeper;
+
+import org.apache.log4j.Logger;
+import org.apache.zookeeper.KeeperException;
+
+/***
+ *  CreateMode value determines how the znode is created on ZooKeeper.
+ */
+public enum CreateMode {
+    
+    /**
+     * The znode will not be automatically deleted upon client's disconnect.
+     */
+    PERSISTENT (0, false, false),
+    /**
+    * The znode will not be automatically deleted upon client's disconnect,
+    * and its name will be appended with a monotonically increasing number.
+    */
+    PERSISTENT_SEQUENTIAL (2, false, true),
+    /**
+     * The znode will be deleted upon the client's disconnect.
+     */
+    EPHEMERAL (1, true, false),
+    /**
+     * The znode will be deleted upon the client's disconnect, and its name
+     * will be appended with a monotonically increasing number.
+     */
+    EPHEMERAL_SEQUENTIAL (3, true, true);
+
+    private static final Logger LOG = Logger.getLogger(CreateMode.class);
+
+    private boolean ephemeral;
+    private boolean sequential;
+    private int flag;
+
+    CreateMode(int flag, boolean ephemeral, boolean sequential) {
+        this.flag = flag;
+        this.ephemeral = ephemeral;
+        this.sequential = sequential;
+    }
+
+    public boolean isEphemeral() { 
+        return ephemeral;
+    }
+
+    public boolean isSequential() { 
+        return sequential;
+    }
+
+    public int toFlag() {
+        return flag;
+    }
+
+    /**
+     * Map an integer value to a CreateMode value
+     */
+    static public CreateMode fromFlag(int flag) throws KeeperException {
+        switch(flag) {
+        case 0: return CreateMode.PERSISTENT;
+
+        case 1: return CreateMode.EPHEMERAL;
+
+        case 2: return CreateMode.PERSISTENT_SEQUENTIAL;
+
+        case 3: return CreateMode.EPHEMERAL_SEQUENTIAL ;
+
+        default:
+            LOG.error("Received an invalid flag value to convert to a CreateMode");
+            throw new KeeperException.BadArgumentsException(); 
+        }
+    }
+}

+ 0 - 6
src/java/main/org/apache/zookeeper/ZooDefs.java

@@ -57,12 +57,6 @@ public class ZooDefs {
         public final int error = -1;
         public final int error = -1;
     }
     }
 
 
-    public interface CreateFlags {
-        int EPHEMERAL = 1 << 0;
-
-        int SEQUENCE = 1 << 1;
-    }
-
     public interface Perms {
     public interface Perms {
         int READ = 1 << 0;
         int READ = 1 << 0;
 
 

+ 13 - 8
src/java/main/org/apache/zookeeper/ZooKeeper.java

@@ -377,14 +377,16 @@ public class ZooKeeper {
      * @throws org.apache.zookeeper.KeeperException.InvalidACLException if the ACL is invalid
      * @throws org.apache.zookeeper.KeeperException.InvalidACLException if the ACL is invalid
      * @throws InterruptedException if the transaction is interrrupted
      * @throws InterruptedException if the transaction is interrrupted
      */
      */
-    public String create(String path, byte data[], List<ACL> acl, int flags)
-            throws KeeperException, InterruptedException {
+    public String create(String path, byte data[], List<ACL> acl,
+            CreateMode createMode)
+        throws KeeperException, InterruptedException
+    {
         RequestHeader h = new RequestHeader();
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.create);
         h.setType(ZooDefs.OpCode.create);
         CreateRequest request = new CreateRequest();
         CreateRequest request = new CreateRequest();
         CreateResponse response = new CreateResponse();
         CreateResponse response = new CreateResponse();
         request.setData(data);
         request.setData(data);
-        request.setFlags(flags);
+        request.setFlags(createMode.toFlag());
         request.setPath(path);
         request.setPath(path);
         if (acl != null && acl.size() == 0) {
         if (acl != null && acl.size() == 0) {
             throw new KeeperException.InvalidACLException();
             throw new KeeperException.InvalidACLException();
@@ -397,22 +399,25 @@ public class ZooKeeper {
         return response.getPath();
         return response.getPath();
     }
     }
 
 
-    /**
+
+
+	/**
      * The Asynchronous version of create. The request doesn't actually until
      * The Asynchronous version of create. The request doesn't actually until
      * the asynchronous callback is called.
      * the asynchronous callback is called.
      *
      *
-     * @see #create(String, byte[], List, int)
+     * @see #create(String, byte[], List<ACL>, CreateMode)
      */
      */
 
 
-    public void create(String path, byte data[], List<ACL> acl, int flags,
-            StringCallback cb, Object ctx) {
+    public void create(String path, byte data[], List<ACL> acl,
+            CreateMode createMode,  StringCallback cb, Object ctx)
+    {
         RequestHeader h = new RequestHeader();
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.create);
         h.setType(ZooDefs.OpCode.create);
         CreateRequest request = new CreateRequest();
         CreateRequest request = new CreateRequest();
         CreateResponse response = new CreateResponse();
         CreateResponse response = new CreateResponse();
         ReplyHeader r = new ReplyHeader();
         ReplyHeader r = new ReplyHeader();
         request.setData(data);
         request.setData(data);
-        request.setFlags(flags);
+        request.setFlags(createMode.toFlag());
         request.setPath(path);
         request.setPath(path);
         request.setAcl(acl);
         request.setAcl(acl);
         cnxn.queuePacket(h, r, request, response, cb, path, ctx, null);
         cnxn.queuePacket(h, r, request, response, cb, path, ctx, null);

+ 4 - 4
src/java/main/org/apache/zookeeper/ZooKeeperMain.java

@@ -23,13 +23,13 @@ import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
-
-import org.apache.zookeeper.AsyncCallback.DataCallback;
-import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
+import org.apache.zookeeper.AsyncCallback.DataCallback;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.CreateMode;
 
 
 /**
 /**
  * The command line client to ZooKeeper.
  * The command line client to ZooKeeper.
@@ -147,7 +147,7 @@ public class ZooKeeperMain {
             if (args.length == 5) {
             if (args.length == 5) {
                 acl = parseACLs(args[4]);
                 acl = parseACLs(args[4]);
             }
             }
-            String newPath = zooKeeper.create(path, args[3].getBytes(), acl, 0);
+            String newPath = zooKeeper.create(path, args[3].getBytes(), acl, CreateMode.PERSISTENT);
             System.err.println("Created " + newPath);
             System.err.println("Created " + newPath);
         } else if (cmd.equals("delete") && args.length >= 3) {
         } else if (cmd.equals("delete") && args.length >= 3) {
             zooKeeper.delete(path, watch ? Integer.parseInt(args[3]) : -1);
             zooKeeper.delete(path, watch ? Integer.parseInt(args[3]) : -1);

+ 5 - 4
src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java

@@ -29,8 +29,8 @@ import org.apache.jute.Record;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.Id;
@@ -202,7 +202,8 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
                 checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE,
                 checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE,
                         request.authInfo);
                         request.authInfo);
                 int parentCVersion = parentRecord.stat.getCversion();
                 int parentCVersion = parentRecord.stat.getCversion();
-                if ((createRequest.getFlags() & CreateFlags.SEQUENCE) != 0) {
+                CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags());
+                if (createMode.isSequential()) {
                     path = path + String.format("%010d", parentCVersion);
                     path = path + String.format("%010d", parentCVersion);
                 }
                 }
                 try {
                 try {
@@ -218,9 +219,9 @@ public class PrepRequestProcessor extends Thread implements RequestProcessor {
                 }
                 }
                 txn = new CreateTxn(path, createRequest.getData(),
                 txn = new CreateTxn(path, createRequest.getData(),
                         createRequest.getAcl(),
                         createRequest.getAcl(),
-                        (createRequest.getFlags() & CreateFlags.EPHEMERAL) != 0);
+                        createMode.isEphemeral());
                 Stat s = new Stat();
                 Stat s = new Stat();
-                if ((createRequest.getFlags() & CreateFlags.EPHEMERAL) != 0) {
+                if (createMode.isEphemeral()) {
                     s.setEphemeralOwner(request.sessionId);
                     s.setEphemeralOwner(request.sessionId);
                 }
                 }
                 parentRecord = parentRecord.duplicate(txnHeader.getZxid());
                 parentRecord = parentRecord.duplicate(txnHeader.getZxid());

+ 2 - 1
src/java/test/org/apache/zookeeper/test/AsyncOps.java

@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.ACLCallback;
 import org.apache.zookeeper.AsyncCallback.ACLCallback;
@@ -133,7 +134,7 @@ public class AsyncOps {
     public static class StringCB extends AsyncCB implements StringCallback {
     public static class StringCB extends AsyncCB implements StringCallback {
         byte[] data = new byte[10];
         byte[] data = new byte[10];
         List<ACL> acl = Ids.CREATOR_ALL_ACL;
         List<ACL> acl = Ids.CREATOR_ALL_ACL;
-        int flags = 0;
+        CreateMode flags = CreateMode.PERSISTENT;
         String name = path;
         String name = path;
         
         
         StringCB(ZooKeeper zk) {
         StringCB(ZooKeeper zk) {

+ 5 - 5
src/java/test/org/apache/zookeeper/test/AsyncTest.java

@@ -36,8 +36,8 @@ import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.junit.After;
 import org.junit.After;
@@ -123,7 +123,7 @@ public class AsyncTest extends TestCase
                 while(bang) {
                 while(bang) {
                     incOutstanding(); // before create otw race
                     incOutstanding(); // before create otw race
                     zk.create("/test-", new byte[0], Ids.OPEN_ACL_UNSAFE,
                     zk.create("/test-", new byte[0], Ids.OPEN_ACL_UNSAFE,
-                            CreateFlags.SEQUENCE, this, null);
+                            CreateMode.PERSISTENT_SEQUENTIAL, this, null);
                 }
                 }
             } catch (InterruptedException e) {
             } catch (InterruptedException e) {
                 if (bang) {
                 if (bang) {
@@ -208,10 +208,10 @@ public class AsyncTest extends TestCase
         zk = createClient();
         zk = createClient();
         try {
         try {
             zk.addAuthInfo("digest", "ben:passwd".getBytes());
             zk.addAuthInfo("digest", "ben:passwd".getBytes());
-            zk.create("/ben", new byte[0], Ids.READ_ACL_UNSAFE, 0, this, results);
-            zk.create("/ben/2", new byte[0], Ids.CREATOR_ALL_ACL, 0, this, results);
+            zk.create("/ben", new byte[0], Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT, this, results);
+            zk.create("/ben/2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results);
             zk.delete("/ben", -1, this, results);
             zk.delete("/ben", -1, this, results);
-            zk.create("/ben2", new byte[0], Ids.CREATOR_ALL_ACL, 0, this, results);
+            zk.create("/ben2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results);
             zk.getData("/ben2", false, this, results);
             zk.getData("/ben2", false, this, results);
             synchronized (results) {
             synchronized (results) {
                 while (results.size() < 5) {
                 while (results.size() < 5) {

+ 27 - 27
src/java/test/org/apache/zookeeper/test/ClientTest.java

@@ -27,12 +27,12 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.KeeperException.InvalidACLException;
 import org.apache.zookeeper.KeeperException.InvalidACLException;
 import org.apache.zookeeper.Watcher.Event;
 import org.apache.zookeeper.Watcher.Event;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Perms;
 import org.apache.zookeeper.ZooDefs.Perms;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.ACL;
@@ -57,7 +57,7 @@ public class ClientTest extends ClientBase {
             zkIdle = createClient();
             zkIdle = createClient();
             zkWatchCreator = createClient();
             zkWatchCreator = createClient();
             for (int i = 0; i < 30; i++) {
             for (int i = 0; i < 30; i++) {
-                zkWatchCreator.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
+                zkWatchCreator.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             }
             }
             for (int i = 0; i < 30; i++) {
             for (int i = 0; i < 30; i++) {
                 zkIdle.exists("/" + i, true);
                 zkIdle.exists("/" + i, true);
@@ -98,7 +98,7 @@ public class ClientTest extends ClientBase {
         try {
         try {
             zk = createClient();
             zk = createClient();
             try {
             try {
-                zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, 0);
+                zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
                 fail("Should have received an invalid acl error");
                 fail("Should have received an invalid acl error");
             } catch(InvalidACLException e) {
             } catch(InvalidACLException e) {
                 LOG.info("Test successful, invalid acl received : "
                 LOG.info("Test successful, invalid acl received : "
@@ -108,14 +108,14 @@ public class ClientTest extends ClientBase {
                 ArrayList<ACL> testACL = new ArrayList<ACL>();
                 ArrayList<ACL> testACL = new ArrayList<ACL>();
                 testACL.add(new ACL(Perms.ALL | Perms.ADMIN, Ids.AUTH_IDS));
                 testACL.add(new ACL(Perms.ALL | Perms.ADMIN, Ids.AUTH_IDS));
                 testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id("ip", "127.0.0.1/8")));
                 testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id("ip", "127.0.0.1/8")));
-                zk.create("/acltest", new byte[0], testACL, 0);
+                zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
                 fail("Should have received an invalid acl error");
                 fail("Should have received an invalid acl error");
             } catch(InvalidACLException e) {
             } catch(InvalidACLException e) {
                 LOG.info("Test successful, invalid acl received : "
                 LOG.info("Test successful, invalid acl received : "
                         + e.getMessage());
                         + e.getMessage());
             }
             }
             zk.addAuthInfo("digest", "ben:passwd".getBytes());
             zk.addAuthInfo("digest", "ben:passwd".getBytes());
-            zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, 0);
+            zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
             zk.close();
             zk.close();
             zk = createClient();
             zk = createClient();
             zk.addAuthInfo("digest", "ben:passwd2".getBytes());
             zk.addAuthInfo("digest", "ben:passwd2".getBytes());
@@ -174,7 +174,7 @@ public class ClientTest extends ClientBase {
                 watchers[i] = new MyWatcher();
                 watchers[i] = new MyWatcher();
                 watchers2[i] = new MyWatcher();
                 watchers2[i] = new MyWatcher();
                 zk.create("/foo-" + i, ("foodata" + i).getBytes(),
                 zk.create("/foo-" + i, ("foodata" + i).getBytes(),
-                        Ids.OPEN_ACL_UNSAFE, 0);
+                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             }
             }
             Stat stat = new Stat();
             Stat stat = new Stat();
 
 
@@ -285,7 +285,7 @@ public class ClientTest extends ClientBase {
             zk = createClient(watcher, hostPort);
             zk = createClient(watcher, hostPort);
             //LOG.info("Created client: " + zk.describeCNXN());
             //LOG.info("Created client: " + zk.describeCNXN());
             LOG.info("Before create /benwashere");
             LOG.info("Before create /benwashere");
-            zk.create("/benwashere", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create("/benwashere", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             LOG.info("After create /benwashere");
             LOG.info("After create /benwashere");
             try {
             try {
                 zk.setData("/benwashere", "hi".getBytes(), 57);
                 zk.setData("/benwashere", "hi".getBytes(), 57);
@@ -315,7 +315,7 @@ public class ClientTest extends ClientBase {
             Stat stat = new Stat();
             Stat stat = new Stat();
             // Test basic create, ls, and getData
             // Test basic create, ls, and getData
             LOG.info("Before create /ben");
             LOG.info("Before create /ben");
-            zk.create("/ben", "Ben was here".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create("/ben", "Ben was here".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             LOG.info("Before getChildren /");
             LOG.info("Before getChildren /");
             List<String> children = zk.getChildren("/", false);
             List<String> children = zk.getChildren("/", false);
             assertEquals(1, children.size());
             assertEquals(1, children.size());
@@ -334,7 +334,8 @@ public class ClientTest extends ClientBase {
             } catch (KeeperException.NoNodeException e) {
             } catch (KeeperException.NoNodeException e) {
                 // OK, expected that
                 // OK, expected that
             }
             }
-            zk.create("/frog", "hi".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create("/frog", "hi".getBytes(), Ids.OPEN_ACL_UNSAFE,
+                    CreateMode.PERSISTENT);
             // the first poll is just a session delivery
             // the first poll is just a session delivery
             LOG.info("Comment: checking for events length "
             LOG.info("Comment: checking for events length "
                      + watcher.events.size());
                      + watcher.events.size());
@@ -346,7 +347,7 @@ public class ClientTest extends ClientBase {
             zk.getChildren("/ben", true);
             zk.getChildren("/ben", true);
             for (int i = 0; i < 10; i++) {
             for (int i = 0; i < 10; i++) {
                 zk.create("/ben/" + i + "-", Integer.toString(i).getBytes(),
                 zk.create("/ben/" + i + "-", Integer.toString(i).getBytes(),
-                        Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE);
+                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             }
             }
             children = zk.getChildren("/ben", false);
             children = zk.getChildren("/ben", false);
             Collections.sort(children);
             Collections.sort(children);
@@ -384,17 +385,17 @@ public class ClientTest extends ClientBase {
                 assertEquals(Event.EventNodeDeleted, event.getType());
                 assertEquals(Event.EventNodeDeleted, event.getType());
                 assertEquals(Event.KeeperStateSyncConnected, event.getState());
                 assertEquals(Event.KeeperStateSyncConnected, event.getState());
             }
             }
-            zk.create("/good\u0001path", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create("/good\u0001path", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             //try {
             //try {
-            //    zk.create("/bad\u0000path", "".getBytes(), null, 0);
+            //    zk.create("/bad\u0000path", "".getBytes(), null, CreateMode.PERSISTENT);
             //    fail("created an invalid path");
             //    fail("created an invalid path");
             //} catch(KeeperException e) {
             //} catch(KeeperException e) {
             //    assertEquals(KeeperException.Code.BadArguments, e.getCode());
             //    assertEquals(KeeperException.Code.BadArguments, e.getCode());
             //}
             //}
 
 
-            zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             try {
             try {
-                zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+                zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 fail("duplicate create allowed");
                 fail("duplicate create allowed");
             } catch(KeeperException.NodeExistsException e) {
             } catch(KeeperException.NodeExistsException e) {
                 // OK, expected that
                 // OK, expected that
@@ -419,19 +420,18 @@ public class ClientTest extends ClientBase {
         ZooKeeper zk = null;
         ZooKeeper zk = null;
         try {
         try {
             zk = createClient();
             zk = createClient();
-            zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
-            zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE);
+            zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+            zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             List<String> children = zk.getChildren(path, false);
             List<String> children = zk.getChildren(path, false);
             assertEquals(1, children.size());
             assertEquals(1, children.size());
             assertEquals(file + "0000000000", children.get(0));
             assertEquals(file + "0000000000", children.get(0));
 
 
-            zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE);
+            zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             children = zk.getChildren(path, false);
             children = zk.getChildren(path, false);
             assertEquals(2, children.size());
             assertEquals(2, children.size());
-            assertTrue("contains child 1",
-                       children.contains(file + "0000000001"));
+            assertTrue("contains child 1",  children.contains(file + "0000000001"));
 
 
-            zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE);
+            zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             children = zk.getChildren(path, false);
             children = zk.getChildren(path, false);
             assertEquals(3, children.size());
             assertEquals(3, children.size());
             assertTrue("contains child 2",
             assertTrue("contains child 2",
@@ -440,7 +440,7 @@ public class ClientTest extends ClientBase {
             // The pattern is holding so far.  Let's run the counter a bit
             // The pattern is holding so far.  Let's run the counter a bit
             // to be sure it continues to spit out the correct answer
             // to be sure it continues to spit out the correct answer
             for(int i = children.size(); i < 105; i++)
             for(int i = children.size(); i < 105; i++)
-               zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE);
+               zk.create(filepath, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
 
 
             children = zk.getChildren(path, false);
             children = zk.getChildren(path, false);
             assertTrue("contains child 104",
             assertTrue("contains child 104",
@@ -471,8 +471,8 @@ public class ClientTest extends ClientBase {
     @Test
     @Test
     public void testDeleteWithChildren() throws Exception {
     public void testDeleteWithChildren() throws Exception {
         ZooKeeper zk = createClient();
         ZooKeeper zk = createClient();
-        zk.create("/parent", new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
-        zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
+        zk.create("/parent", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+        zk.create("/parent/child", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         try {
         try {
             zk.delete("/parent", -1);
             zk.delete("/parent", -1);
             fail("Should have received a not equals message");
             fail("Should have received a not equals message");
@@ -512,7 +512,7 @@ public class ClientTest extends ClientBase {
                 for (; current < count; current++) {
                 for (; current < count; current++) {
                     // Simulate a bit of network latency...
                     // Simulate a bit of network latency...
                     Thread.sleep(HAMMERTHREAD_LATENCY);
                     Thread.sleep(HAMMERTHREAD_LATENCY);
-                    zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, 0);
+                    zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 }
                 }
             } catch (Throwable t) {
             } catch (Throwable t) {
                 LOG.error("Client create operation failed", t);
                 LOG.error("Client create operation failed", t);
@@ -544,7 +544,7 @@ public class ClientTest extends ClientBase {
                 for (; current < count; current++) {
                 for (; current < count; current++) {
                     ZooKeeper zk = parent.createClient();
                     ZooKeeper zk = parent.createClient();
                     try {
                     try {
-                        zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, 0);
+                        zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     } finally {
                     } finally {
                         try {
                         try {
                             zk.close();
                             zk.close();
@@ -575,7 +575,7 @@ public class ClientTest extends ClientBase {
             for (int i = 0; i < threads.length; i++) {
             for (int i = 0; i < threads.length; i++) {
                 ZooKeeper zk = createClient();
                 ZooKeeper zk = createClient();
                 String prefix = "/test-" + i;
                 String prefix = "/test-" + i;
-                zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
+                zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 prefix += "/";
                 prefix += "/";
                 HammerThread thread = 
                 HammerThread thread = 
                     new BasicHammerThread("BasicHammerThread-" + i, zk, prefix,
                     new BasicHammerThread("BasicHammerThread-" + i, zk, prefix,
@@ -610,7 +610,7 @@ public class ClientTest extends ClientBase {
                 {
                 {
                     ZooKeeper zk = createClient();
                     ZooKeeper zk = createClient();
                     try {
                     try {
-                        zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, 0);
+                        zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     } finally {
                     } finally {
                         zk.close();
                         zk.close();
                     }
                     }

+ 81 - 0
src/java/test/org/apache/zookeeper/test/CreateModeTest.java

@@ -0,0 +1,81 @@
+/**
+ * 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.zookeeper.test;
+
+import java.util.EnumSet;
+
+import junit.framework.TestCase;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.Code;
+import org.junit.Test;
+
+public class CreateModeTest extends TestCase {
+    
+    @Test
+    public void testBasicCreateMode() {
+        CreateMode cm = CreateMode.PERSISTENT;
+        assertEquals(cm.toFlag(), 0);
+        assertFalse(cm.isEphemeral());
+        assertFalse(cm.isSequential());
+        
+        cm = CreateMode.EPHEMERAL;
+        assertEquals(cm.toFlag(), 1);
+        assertTrue(cm.isEphemeral());
+        assertFalse(cm.isSequential());
+        
+        cm = CreateMode.PERSISTENT_SEQUENTIAL;
+        assertEquals(cm.toFlag(), 2);
+        assertFalse(cm.isEphemeral());
+        assertTrue(cm.isSequential());
+        
+        cm = CreateMode.EPHEMERAL_SEQUENTIAL;
+        assertEquals(cm.toFlag(), 3);
+        assertTrue(cm.isEphemeral());
+        assertTrue(cm.isSequential());
+    }
+    
+    @Test
+    public void testFlagConversion() throws KeeperException {
+        // Ensure we get the same value back after round trip conversion
+        EnumSet<CreateMode> allModes = EnumSet.allOf(CreateMode.class);
+
+        for(CreateMode cm : allModes) {
+            assertEquals(cm, CreateMode.fromFlag( cm.toFlag() ) );
+        }
+    }
+
+    @Test
+    public void testInvalidFlagConversion() throws KeeperException {
+        try {
+            CreateMode cm = CreateMode.fromFlag(99);
+            fail("Shouldn't be able to convert 99 to a CreateMode.");
+        } catch(KeeperException ke) {
+            assertEquals(Code.BadArguments, ke.getCode());
+        }
+
+        try {
+            CreateMode cm = CreateMode.fromFlag(-1);
+            fail("Shouldn't be able to convert -1 to a CreateMode.");
+        } catch(KeeperException ke) {
+            assertEquals(Code.BadArguments, ke.getCode());
+        }
+    }
+}

+ 2 - 2
src/java/test/org/apache/zookeeper/test/GenerateLoad.java

@@ -42,7 +42,7 @@ import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
@@ -313,7 +313,7 @@ public class GenerateLoad {
                     try {
                     try {
                         Thread.sleep(100);
                         Thread.sleep(100);
                         path = zk.create("/client", new byte[16], Ids.OPEN_ACL_UNSAFE,
                         path = zk.create("/client", new byte[16], Ids.OPEN_ACL_UNSAFE,
-                                CreateFlags.EPHEMERAL|CreateFlags.SEQUENCE);
+                                CreateMode.EPHEMERAL_SEQUENTIAL);
                         break;
                         break;
                     } catch(KeeperException e) {
                     } catch(KeeperException e) {
                         LOG.error("keeper exception thrown", e);
                         LOG.error("keeper exception thrown", e);

+ 3 - 2
src/java/test/org/apache/zookeeper/test/IntegrityCheck.java

@@ -40,6 +40,7 @@ import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
@@ -115,7 +116,7 @@ public class IntegrityCheck implements Watcher, StatCallback, DataCallback {
     void doCreate() throws InterruptedException, KeeperException {
     void doCreate() throws InterruptedException, KeeperException {
         // create top level znode
         // create top level znode
         try{
         try{
-            zk.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         }catch(KeeperException.NodeExistsException e){
         }catch(KeeperException.NodeExistsException e){
             // ignore duplicate create
             // ignore duplicate create
         }
         }
@@ -127,7 +128,7 @@ public class IntegrityCheck implements Watcher, StatCallback, DataCallback {
             try{
             try{
                 if(i%10==0)
                 if(i%10==0)
                     LOG.warn("Creating znode "+cpath);
                     LOG.warn("Creating znode "+cpath);
-                zk.create(cpath, v, ZooDefs.Ids.OPEN_ACL_UNSAFE, 0);
+                zk.create(cpath, v, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             }catch(KeeperException.NodeExistsException e){
             }catch(KeeperException.NodeExistsException e){
                 // ignore duplicate create
                 // ignore duplicate create
             }
             }

+ 2 - 1
src/java/test/org/apache/zookeeper/test/OOMTest.java

@@ -29,6 +29,7 @@ import junit.framework.TestCase;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -115,7 +116,7 @@ public class OOMTest extends TestCase implements Watcher {
             InterruptedException, KeeperException {
             InterruptedException, KeeperException {
         ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this);
         ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this);
         for (int i = 0; i < 10000; i++) {
         for (int i = 0; i < 10000; i++) {
-            zk.create("/" + i, null, Ids.OPEN_ACL_UNSAFE, 0);
+            zk.create("/" + i, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         }
         }
         zk.close();
         zk.close();
     }
     }

+ 4 - 3
src/java/test/org/apache/zookeeper/test/RecoveryTest.java

@@ -29,6 +29,7 @@ import junit.framework.TestCase;
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -98,15 +99,15 @@ public class RecoveryTest extends TestCase implements Watcher {
                 path = "/" + i;
                 path = "/" + i;
                 zk.create(path,
                 zk.create(path,
                           (path + "!").getBytes(),
                           (path + "!").getBytes(),
-                          Ids.OPEN_ACL_UNSAFE, 0);
+                          Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 for (int j = 0; j < 10; j++) {
                 for (int j = 0; j < 10; j++) {
                     String subpath = path + "/" + j;
                     String subpath = path + "/" + j;
                     zk.create(subpath, (subpath + "!").getBytes(),
                     zk.create(subpath, (subpath + "!").getBytes(),
-                            Ids.OPEN_ACL_UNSAFE, 0);
+                            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     for (int k = 0; k < 20; k++) {
                     for (int k = 0; k < 20; k++) {
                         String subsubpath = subpath + "/" + k;
                         String subsubpath = subpath + "/" + k;
                         zk.create(subsubpath, (subsubpath + "!").getBytes(),
                         zk.create(subsubpath, (subsubpath + "!").getBytes(),
-                                Ids.OPEN_ACL_UNSAFE, 0);
+                                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     }
                     }
                 }
                 }
             }
             }

+ 2 - 2
src/java/test/org/apache/zookeeper/test/SessionTest.java

@@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit;
 import junit.framework.TestCase;
 import junit.framework.TestCase;
 
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -145,7 +145,7 @@ public class SessionTest extends TestCase implements Watcher {
     {
     {
         DisconnectableZooKeeper zk = createClient();
         DisconnectableZooKeeper zk = createClient();
         zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
         zk.create("/e", new byte[0], Ids.OPEN_ACL_UNSAFE,
-                        CreateFlags.EPHEMERAL);
+                        CreateMode.EPHEMERAL);
         LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
         LOG.info("zk with session id 0x" + Long.toHexString(zk.getSessionId())
                 + " was destroyed!");
                 + " was destroyed!");
 
 

+ 2 - 2
src/java/test/org/apache/zookeeper/test/SledgeHammer.java

@@ -25,7 +25,7 @@ import java.util.List;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -48,7 +48,7 @@ public class SledgeHammer extends Thread implements Watcher {
         try {
         try {
             Stat stat = new Stat();
             Stat stat = new Stat();
             String path = zk.create("/hammers/hammer-", new byte[0],
             String path = zk.create("/hammers/hammer-", new byte[0],
-                    Ids.OPEN_ACL_UNSAFE, CreateFlags.SEQUENCE);
+                    Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
             byte tag[] = (path + " was here!").getBytes();
             byte tag[] = (path + " was here!").getBytes();
             synchronized (this) {
             synchronized (this) {
                 String startPath = "/hammers/start";
                 String startPath = "/hammers/start";

+ 2 - 1
src/java/test/org/apache/zookeeper/test/SyncCallTest.java

@@ -26,6 +26,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeUnit;
 
 
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
@@ -51,7 +52,7 @@ public class SyncCallTest extends ClientBase
             LOG.info("Beginning test:" + (new Date()).toString());
             LOG.info("Beginning test:" + (new Date()).toString());
             for(int i = 0; i < 100; i++)
             for(int i = 0; i < 100; i++)
                 zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                 zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
-                        0, this, results);
+                        CreateMode.PERSISTENT, this, results);
             zk.sync("/test", this, results);
             zk.sync("/test", this, results);
             for(int i = 0; i < 100; i++)
             for(int i = 0; i < 100; i++)
                 zk.delete("/test" + i, 0, this, results);
                 zk.delete("/test" + i, 0, this, results);

+ 2 - 2
src/java/test/org/apache/zookeeper/test/TestHammer.java

@@ -22,7 +22,7 @@ import java.io.IOException;
 
 
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 
 
 public class TestHammer implements VoidCallback {
 public class TestHammer implements VoidCallback {
@@ -44,7 +44,7 @@ public class TestHammer implements VoidCallback {
             for(int i = 0; i < REPS; i++) {
             for(int i = 0; i < REPS; i++) {
                 try {
                 try {
                     String name = zk.create("/testFile-", new byte[16], Ids.OPEN_ACL_UNSAFE,
                     String name = zk.create("/testFile-", new byte[16], Ids.OPEN_ACL_UNSAFE,
-                        CreateFlags.EPHEMERAL|CreateFlags.SEQUENCE);
+                        CreateMode.EPHEMERAL_SEQUENTIAL);
                     zk.delete(name, -1, new TestHammer(), null);
                     zk.delete(name, -1, new TestHammer(), null);
                 } catch(Exception e) {
                 } catch(Exception e) {
                     i--;
                     i--;

+ 13 - 12
src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java

@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
 
 
@@ -122,9 +123,9 @@ public class WatcherFuncTest extends ClientBase {
         assertNull(lsnr.exists("/foo", true));
         assertNull(lsnr.exists("/foo", true));
         assertNull(lsnr.exists("/foo/bar", true));
         assertNull(lsnr.exists("/foo/bar", true));
 
 
-        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(Watcher.Event.EventNodeCreated);
         expected.add(Watcher.Event.EventNodeCreated);
-        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(Watcher.Event.EventNodeCreated);
         expected.add(Watcher.Event.EventNodeCreated);
 
 
         verify();
         verify();
@@ -182,9 +183,9 @@ public class WatcherFuncTest extends ClientBase {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         }
 
 
-        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         assertNotNull(lsnr.getData("/foo", true, null));
         assertNotNull(lsnr.getData("/foo", true, null));
-        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         assertNotNull(lsnr.getData("/foo/bar", true, null));
         assertNotNull(lsnr.getData("/foo/bar", true, null));
 
 
         client.setData("/foo", "parent".getBytes(), -1);
         client.setData("/foo", "parent".getBytes(), -1);
@@ -221,10 +222,10 @@ public class WatcherFuncTest extends ClientBase {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         }
 
 
-        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         assertNotNull(lsnr.getChildren("/foo", true));
         assertNotNull(lsnr.getChildren("/foo", true));
 
 
-        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(Watcher.Event.EventNodeChildrenChanged); // /foo
         expected.add(Watcher.Event.EventNodeChildrenChanged); // /foo
         assertNotNull(lsnr.getChildren("/foo/bar", true));
         assertNotNull(lsnr.getChildren("/foo/bar", true));
 
 
@@ -265,9 +266,9 @@ public class WatcherFuncTest extends ClientBase {
         assertNull(lsnr.exists("/foo/bar", w3));
         assertNull(lsnr.exists("/foo/bar", w3));
         assertNull(lsnr.exists("/foo/bar", w4));
         assertNull(lsnr.exists("/foo/bar", w4));
 
 
-        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(Watcher.Event.EventNodeCreated);
         expected.add(Watcher.Event.EventNodeCreated);
-        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         e2.add(Watcher.Event.EventNodeCreated);
         e2.add(Watcher.Event.EventNodeCreated);
 
 
         lsnr_dwatch.verify(expected);
         lsnr_dwatch.verify(expected);
@@ -346,10 +347,10 @@ public class WatcherFuncTest extends ClientBase {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         }
 
 
-        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         assertNotNull(lsnr.getData("/foo", true, null));
         assertNotNull(lsnr.getData("/foo", true, null));
         assertNotNull(lsnr.getData("/foo", w1, null));
         assertNotNull(lsnr.getData("/foo", w1, null));
-        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         assertNotNull(lsnr.getData("/foo/bar", w2, null));
         assertNotNull(lsnr.getData("/foo/bar", w2, null));
         assertNotNull(lsnr.getData("/foo/bar", w3, null));
         assertNotNull(lsnr.getData("/foo/bar", w3, null));
         assertNotNull(lsnr.getData("/foo/bar", w4, null));
         assertNotNull(lsnr.getData("/foo/bar", w4, null));
@@ -412,11 +413,11 @@ public class WatcherFuncTest extends ClientBase {
             assertEquals(KeeperException.Code.NoNode, e.getCode());
             assertEquals(KeeperException.Code.NoNode, e.getCode());
         }
         }
 
 
-        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo", "parent".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         assertNotNull(lsnr.getChildren("/foo", true));
         assertNotNull(lsnr.getChildren("/foo", true));
         assertNotNull(lsnr.getChildren("/foo", w1));
         assertNotNull(lsnr.getChildren("/foo", w1));
 
 
-        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+        client.create("/foo/bar", "child".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
         expected.add(Watcher.Event.EventNodeChildrenChanged); // /foo
         expected.add(Watcher.Event.EventNodeChildrenChanged); // /foo
         assertNotNull(lsnr.getChildren("/foo/bar", w2));
         assertNotNull(lsnr.getChildren("/foo/bar", w2));
         assertNotNull(lsnr.getChildren("/foo/bar", w2));
         assertNotNull(lsnr.getChildren("/foo/bar", w2));

+ 11 - 13
src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java

@@ -26,16 +26,15 @@ import java.util.concurrent.TimeUnit;
 import junit.framework.AssertionFailedError;
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 import junit.framework.TestCase;
 
 
-import org.junit.Test;
-
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.apache.zookeeper.proto.WatcherEvent;
+import org.junit.Test;
 
 
 public class ZooKeeperTestClient extends TestCase implements Watcher {
 public class ZooKeeperTestClient extends TestCase implements Watcher {
   protected String hostPort = "127.0.0.1:22801";
   protected String hostPort = "127.0.0.1:22801";
@@ -83,7 +82,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
     ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
 
 
     try {
     try {
-      zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, 0);
+      zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException.NodeExistsException ke) {
     } catch (KeeperException.NodeExistsException ke) {
         // expected, sort of
         // expected, sort of
     } catch (KeeperException ke) {
     } catch (KeeperException ke) {
@@ -92,7 +91,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     }
     }
 
 
     try {
     try {
-      zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, 0);
+      zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException.NodeExistsException ke) {
     } catch (KeeperException.NodeExistsException ke) {
         // expected, sort of
         // expected, sort of
     } catch (KeeperException ke) {
     } catch (KeeperException ke) {
@@ -113,14 +112,14 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     Stat stat = zk.exists(parentName, false);
     Stat stat = zk.exists(parentName, false);
     if (stat == null) {
     if (stat == null) {
       try {
       try {
-        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, 0);
+        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       } catch (KeeperException ke) {
       } catch (KeeperException ke) {
         fail("Creating node " + parentName + ke.getMessage());
         fail("Creating node " + parentName + ke.getMessage());
       }
       }
     }
     }
 
 
     try {
     try {
-      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL);
+      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
     } catch (KeeperException ke) {
     } catch (KeeperException ke) {
       int code = ke.getCode();
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NodeExists;
       boolean valid = code == KeeperException.Code.NodeExists;
@@ -167,7 +166,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     Stat stat = zk_1.exists(parentName, false);
     Stat stat = zk_1.exists(parentName, false);
     if (stat == null) {
     if (stat == null) {
       try {
       try {
-        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, 0);
+        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       } catch (KeeperException ke) {
       } catch (KeeperException ke) {
         fail("Creating node " + parentName + ke.getMessage());
         fail("Creating node " + parentName + ke.getMessage());
       }
       }
@@ -191,7 +190,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     List<String> firstGen = zk_1.getChildren(parentName, true);
     List<String> firstGen = zk_1.getChildren(parentName, true);
 
 
     try {
     try {
-      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL);
+      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
     } catch (KeeperException ke) {
     } catch (KeeperException ke) {
       int code = ke.getCode();
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NodeExists;
       boolean valid = code == KeeperException.Code.NodeExists;
@@ -227,9 +226,8 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
     }
     }
 
 
     try {
     try {
-      zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, ZooDefs.CreateFlags.EPHEMERAL);
-      fail("Should be impossible to create child off Ephemeral node "
-          + nodeName);
+      zk.create(nodeName + "/def", null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
+      fail("Should be impossible to create child off Ephemeral node " + nodeName);
     } catch (KeeperException ke) {
     } catch (KeeperException ke) {
       int code = ke.getCode();
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NoChildrenForEphemerals;
       boolean valid = code == KeeperException.Code.NoChildrenForEphemerals;
@@ -317,7 +315,7 @@ public class ZooKeeperTestClient extends TestCase implements Watcher {
       }
       }
     }
     }
     try {
     try {
-      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, 0);
+      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException ke) {
     } catch (KeeperException ke) {
       int code = ke.getCode();
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NodeExists;
       boolean valid = code == KeeperException.Code.NodeExists;