hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r693164 - in /hadoop/zookeeper/trunk/src/java: main/org/apache/zookeeper/ main/org/apache/zookeeper/server/ test/org/apache/zookeeper/test/
Date Mon, 08 Sep 2008 16:55:58 GMT
Author: phunt
Date: Mon Sep  8 09:55:56 2008
New Revision: 693164

URL: http://svn.apache.org/viewvc?rev=693164&view=rev
Log:
fix for ZOOKEEPER-132, creation enum to replace createflag

Added:
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/CreateMode.java   (with props)
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java   (with props)
Modified:
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooDefs.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncOps.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GenerateLoad.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SyncCallTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java

Added: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/CreateMode.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/CreateMode.java?rev=693164&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/CreateMode.java (added)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/CreateMode.java Mon Sep  8 09:55:56 2008
@@ -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(); 
+        }
+    }
+}

Propchange: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/CreateMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooDefs.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooDefs.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooDefs.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooDefs.java Mon Sep  8 09:55:56 2008
@@ -57,12 +57,6 @@
         public final int error = -1;
     }
 
-    public interface CreateFlags {
-        int EPHEMERAL = 1 << 0;
-
-        int SEQUENCE = 1 << 1;
-    }
-
     public interface Perms {
         int READ = 1 << 0;
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java Mon Sep  8 09:55:56 2008
@@ -377,14 +377,16 @@
      * @throws org.apache.zookeeper.KeeperException.InvalidACLException if the ACL is invalid
      * @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();
         h.setType(ZooDefs.OpCode.create);
         CreateRequest request = new CreateRequest();
         CreateResponse response = new CreateResponse();
         request.setData(data);
-        request.setFlags(flags);
+        request.setFlags(createMode.toFlag());
         request.setPath(path);
         if (acl != null && acl.size() == 0) {
             throw new KeeperException.InvalidACLException();
@@ -397,22 +399,25 @@
         return response.getPath();
     }
 
-    /**
+
+
+	/**
      * The Asynchronous version of create. The request doesn't actually until
      * 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();
         h.setType(ZooDefs.OpCode.create);
         CreateRequest request = new CreateRequest();
         CreateResponse response = new CreateResponse();
         ReplyHeader r = new ReplyHeader();
         request.setData(data);
-        request.setFlags(flags);
+        request.setFlags(createMode.toFlag());
         request.setPath(path);
         request.setAcl(acl);
         cnxn.queuePacket(h, r, request, response, cb, path, ctx, null);

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java Mon Sep  8 09:55:56 2008
@@ -23,13 +23,13 @@
 import java.util.ArrayList;
 import java.util.Date;
 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.Id;
 import org.apache.zookeeper.data.Stat;
 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.
@@ -147,7 +147,7 @@
             if (args.length == 5) {
                 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);
         } else if (cmd.equals("delete") && args.length >= 3) {
             zooKeeper.delete(path, watch ? Integer.parseInt(args[3]) : -1);

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java Mon Sep  8 09:55:56 2008
@@ -29,8 +29,8 @@
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
@@ -202,7 +202,8 @@
                 checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE,
                         request.authInfo);
                 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);
                 }
                 try {
@@ -218,9 +219,9 @@
                 }
                 txn = new CreateTxn(path, createRequest.getData(),
                         createRequest.getAcl(),
-                        (createRequest.getFlags() & CreateFlags.EPHEMERAL) != 0);
+                        createMode.isEphemeral());
                 Stat s = new Stat();
-                if ((createRequest.getFlags() & CreateFlags.EPHEMERAL) != 0) {
+                if (createMode.isEphemeral()) {
                     s.setEphemeralOwner(request.sessionId);
                 }
                 parentRecord = parentRecord.duplicate(txnHeader.getZxid());

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncOps.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncOps.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncOps.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncOps.java Mon Sep  8 09:55:56 2008
@@ -27,6 +27,7 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.ACLCallback;
@@ -133,7 +134,7 @@
     public static class StringCB extends AsyncCB implements StringCallback {
         byte[] data = new byte[10];
         List<ACL> acl = Ids.CREATOR_ALL_ACL;
-        int flags = 0;
+        CreateMode flags = CreateMode.PERSISTENT;
         String name = path;
         
         StringCB(ZooKeeper zk) {

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncTest.java Mon Sep  8 09:55:56 2008
@@ -36,8 +36,8 @@
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
 import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
 import org.junit.After;
@@ -123,7 +123,7 @@
                 while(bang) {
                     incOutstanding(); // before create otw race
                     zk.create("/test-", new byte[0], Ids.OPEN_ACL_UNSAFE,
-                            CreateFlags.SEQUENCE, this, null);
+                            CreateMode.PERSISTENT_SEQUENTIAL, this, null);
                 }
             } catch (InterruptedException e) {
                 if (bang) {
@@ -208,10 +208,10 @@
         zk = createClient();
         try {
             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.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);
             synchronized (results) {
                 while (results.size() < 5) {

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientTest.java Mon Sep  8 09:55:56 2008
@@ -27,12 +27,12 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.KeeperException.InvalidACLException;
 import org.apache.zookeeper.Watcher.Event;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooDefs.Perms;
 import org.apache.zookeeper.data.ACL;
@@ -57,7 +57,7 @@
             zkIdle = createClient();
             zkWatchCreator = createClient();
             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++) {
                 zkIdle.exists("/" + i, true);
@@ -98,7 +98,7 @@
         try {
             zk = createClient();
             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");
             } catch(InvalidACLException e) {
                 LOG.info("Test successful, invalid acl received : "
@@ -108,14 +108,14 @@
                 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, 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");
             } catch(InvalidACLException e) {
                 LOG.info("Test successful, invalid acl received : "
                         + e.getMessage());
             }
             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 = createClient();
             zk.addAuthInfo("digest", "ben:passwd2".getBytes());
@@ -174,7 +174,7 @@
                 watchers[i] = new MyWatcher();
                 watchers2[i] = new MyWatcher();
                 zk.create("/foo-" + i, ("foodata" + i).getBytes(),
-                        Ids.OPEN_ACL_UNSAFE, 0);
+                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
             }
             Stat stat = new Stat();
 
@@ -285,7 +285,7 @@
             zk = createClient(watcher, hostPort);
             //LOG.info("Created client: " + zk.describeCNXN());
             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");
             try {
                 zk.setData("/benwashere", "hi".getBytes(), 57);
@@ -315,7 +315,7 @@
             Stat stat = new Stat();
             // Test basic create, ls, and getData
             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 /");
             List<String> children = zk.getChildren("/", false);
             assertEquals(1, children.size());
@@ -334,7 +334,8 @@
             } catch (KeeperException.NoNodeException e) {
                 // 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
             LOG.info("Comment: checking for events length "
                      + watcher.events.size());
@@ -346,7 +347,7 @@
             zk.getChildren("/ben", true);
             for (int i = 0; i < 10; i++) {
                 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);
             Collections.sort(children);
@@ -384,17 +385,17 @@
                 assertEquals(Event.EventNodeDeleted, event.getType());
                 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 {
-            //    zk.create("/bad\u0000path", "".getBytes(), null, 0);
+            //    zk.create("/bad\u0000path", "".getBytes(), null, CreateMode.PERSISTENT);
             //    fail("created an invalid path");
             //} catch(KeeperException e) {
             //    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 {
-                zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, 0);
+                zk.create("/duplicate", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 fail("duplicate create allowed");
             } catch(KeeperException.NodeExistsException e) {
                 // OK, expected that
@@ -419,19 +420,18 @@
         ZooKeeper zk = null;
         try {
             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);
             assertEquals(1, children.size());
             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);
             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);
             assertEquals(3, children.size());
             assertTrue("contains child 2",
@@ -440,7 +440,7 @@
             // The pattern is holding so far.  Let's run the counter a bit
             // to be sure it continues to spit out the correct answer
             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);
             assertTrue("contains child 104",
@@ -471,8 +471,8 @@
     @Test
     public void testDeleteWithChildren() throws Exception {
         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 {
             zk.delete("/parent", -1);
             fail("Should have received a not equals message");
@@ -512,7 +512,7 @@
                 for (; current < count; current++) {
                     // Simulate a bit of network 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) {
                 LOG.error("Client create operation failed", t);
@@ -544,7 +544,7 @@
                 for (; current < count; current++) {
                     ZooKeeper zk = parent.createClient();
                     try {
-                        zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, 0);
+                        zk.create(prefix + current, b, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     } finally {
                         try {
                             zk.close();
@@ -575,7 +575,7 @@
             for (int i = 0; i < threads.length; i++) {
                 ZooKeeper zk = createClient();
                 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 += "/";
                 HammerThread thread = 
                     new BasicHammerThread("BasicHammerThread-" + i, zk, prefix,
@@ -610,7 +610,7 @@
                 {
                     ZooKeeper zk = createClient();
                     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 {
                         zk.close();
                     }

Added: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java?rev=693164&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java (added)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java Mon Sep  8 09:55:56 2008
@@ -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());
+        }
+    }
+}

Propchange: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/CreateModeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GenerateLoad.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GenerateLoad.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GenerateLoad.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/GenerateLoad.java Mon Sep  8 09:55:56 2008
@@ -42,7 +42,7 @@
 import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.KeeperException;
 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.ZooKeeper;
 import org.apache.zookeeper.data.Stat;
@@ -313,7 +313,7 @@
                     try {
                         Thread.sleep(100);
                         path = zk.create("/client", new byte[16], Ids.OPEN_ACL_UNSAFE,
-                                CreateFlags.EPHEMERAL|CreateFlags.SEQUENCE);
+                                CreateMode.EPHEMERAL_SEQUENTIAL);
                         break;
                     } catch(KeeperException e) {
                         LOG.error("keeper exception thrown", e);

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/IntegrityCheck.java Mon Sep  8 09:55:56 2008
@@ -40,6 +40,7 @@
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.AsyncCallback.DataCallback;
 import org.apache.zookeeper.AsyncCallback.StatCallback;
@@ -115,7 +116,7 @@
     void doCreate() throws InterruptedException, KeeperException {
         // create top level znode
         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){
             // ignore duplicate create
         }
@@ -127,7 +128,7 @@
             try{
                 if(i%10==0)
                     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){
                 // ignore duplicate create
             }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/OOMTest.java Mon Sep  8 09:55:56 2008
@@ -29,6 +29,7 @@
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -115,7 +116,7 @@
             InterruptedException, KeeperException {
         ZooKeeper zk = new ZooKeeper("127.0.0.1:33221", 30000, this);
         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();
     }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/RecoveryTest.java Mon Sep  8 09:55:56 2008
@@ -29,6 +29,7 @@
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -98,15 +99,15 @@
                 path = "/" + i;
                 zk.create(path,
                           (path + "!").getBytes(),
-                          Ids.OPEN_ACL_UNSAFE, 0);
+                          Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                 for (int j = 0; j < 10; j++) {
                     String subpath = path + "/" + j;
                     zk.create(subpath, (subpath + "!").getBytes(),
-                            Ids.OPEN_ACL_UNSAFE, 0);
+                            Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     for (int k = 0; k < 20; k++) {
                         String subsubpath = subpath + "/" + k;
                         zk.create(subsubpath, (subsubpath + "!").getBytes(),
-                                Ids.OPEN_ACL_UNSAFE, 0);
+                                Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                     }
                 }
             }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SessionTest.java Mon Sep  8 09:55:56 2008
@@ -28,9 +28,9 @@
 import junit.framework.TestCase;
 
 import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -145,7 +145,7 @@
     {
         DisconnectableZooKeeper zk = createClient();
         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())
                 + " was destroyed!");
 

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SledgeHammer.java Mon Sep  8 09:55:56 2008
@@ -25,7 +25,7 @@
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 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.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
@@ -48,7 +48,7 @@
         try {
             Stat stat = new Stat();
             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();
             synchronized (this) {
                 String startPath = "/hammers/start";

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SyncCallTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SyncCallTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SyncCallTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/SyncCallTest.java Mon Sep  8 09:55:56 2008
@@ -26,6 +26,7 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.AsyncCallback.ChildrenCallback;
 import org.apache.zookeeper.AsyncCallback.StringCallback;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
@@ -51,7 +52,7 @@
             LOG.info("Beginning test:" + (new Date()).toString());
             for(int i = 0; i < 100; i++)
                 zk.create("/test" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
-                        0, this, results);
+                        CreateMode.PERSISTENT, this, results);
             zk.sync("/test", this, results);
             for(int i = 0; i < 100; i++)
                 zk.delete("/test" + i, 0, this, results);

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/TestHammer.java Mon Sep  8 09:55:56 2008
@@ -22,7 +22,7 @@
 
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.AsyncCallback.VoidCallback;
-import org.apache.zookeeper.ZooDefs.CreateFlags;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 
 public class TestHammer implements VoidCallback {
@@ -44,7 +44,7 @@
             for(int i = 0; i < REPS; i++) {
                 try {
                     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);
                 } catch(Exception e) {
                     i--;

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/WatcherFuncTest.java Mon Sep  8 09:55:56 2008
@@ -28,6 +28,7 @@
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.proto.WatcherEvent;
 
@@ -122,9 +123,9 @@
         assertNull(lsnr.exists("/foo", 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);
-        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);
 
         verify();
@@ -182,9 +183,9 @@
             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));
-        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));
 
         client.setData("/foo", "parent".getBytes(), -1);
@@ -221,10 +222,10 @@
             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));
 
-        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
         assertNotNull(lsnr.getChildren("/foo/bar", true));
 
@@ -265,9 +266,9 @@
         assertNull(lsnr.exists("/foo/bar", w3));
         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);
-        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);
 
         lsnr_dwatch.verify(expected);
@@ -346,10 +347,10 @@
             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", 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", w3, null));
         assertNotNull(lsnr.getData("/foo/bar", w4, null));
@@ -412,11 +413,11 @@
             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", 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
         assertNotNull(lsnr.getChildren("/foo/bar", w2));
         assertNotNull(lsnr.getChildren("/foo/bar", w2));

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java?rev=693164&r1=693163&r2=693164&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ZooKeeperTestClient.java Mon Sep  8 09:55:56 2008
@@ -26,16 +26,15 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
-import org.junit.Test;
-
+import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.WatcherEvent;
+import org.junit.Test;
 
 public class ZooKeeperTestClient extends TestCase implements Watcher {
   protected String hostPort = "127.0.0.1:22801";
@@ -83,7 +82,7 @@
     ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
 
     try {
-      zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, 0);
+      zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException.NodeExistsException ke) {
         // expected, sort of
     } catch (KeeperException ke) {
@@ -92,7 +91,7 @@
     }
 
     try {
-      zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, 0);
+      zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException.NodeExistsException ke) {
         // expected, sort of
     } catch (KeeperException ke) {
@@ -113,14 +112,14 @@
     Stat stat = zk.exists(parentName, false);
     if (stat == null) {
       try {
-        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, 0);
+        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       } catch (KeeperException ke) {
         fail("Creating node " + parentName + ke.getMessage());
       }
     }
 
     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) {
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NodeExists;
@@ -167,7 +166,7 @@
     Stat stat = zk_1.exists(parentName, false);
     if (stat == null) {
       try {
-        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, 0);
+        zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
       } catch (KeeperException ke) {
         fail("Creating node " + parentName + ke.getMessage());
       }
@@ -191,7 +190,7 @@
     List<String> firstGen = zk_1.getChildren(parentName, true);
 
     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) {
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NodeExists;
@@ -227,9 +226,8 @@
     }
 
     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) {
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NoChildrenForEphemerals;
@@ -317,7 +315,7 @@
       }
     }
     try {
-      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, 0);
+      zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
     } catch (KeeperException ke) {
       int code = ke.getCode();
       boolean valid = code == KeeperException.Code.NodeExists;



Mime
View raw message