zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mic...@apache.org
Subject svn commit: r1584500 [9/9] - in /zookeeper/branches/branch-3.4: bin/ src/c/ src/contrib/loggraph/web/org/apache/zookeeper/graph/resources/ src/contrib/zooinspector/ src/contrib/zooinspector/lib/ src/contrib/zooinspector/src/java/org/apache/zookeeper/in...
Date Fri, 04 Apr 2014 01:30:25 GMT
Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java Fri Apr  4 01:30:24 2014
@@ -1,288 +1,288 @@
-/**
- * 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.retry;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Stat;
-import org.apache.zookeeper.inspector.logger.LoggerFactory;
-
-/**
- * A Class which extends {@link ZooKeeper} and will automatically retry calls to
- * zookeeper if a {@link KeeperException.ConnectionLossException} occurs
- */
-public class ZooKeeperRetry extends ZooKeeper {
-
-    private boolean closed = false;
-    private final Watcher watcher;
-    private int limit = -1;
-
-    /**
-     * @param connectString
-     * @param sessionTimeout
-     * @param watcher
-     * @throws IOException
-     */
-    public ZooKeeperRetry(String connectString, int sessionTimeout,
-            Watcher watcher) throws IOException {
-        super(connectString, sessionTimeout, watcher);
-        this.watcher = watcher;
-    }
-
-    /**
-     * @param connectString
-     * @param sessionTimeout
-     * @param watcher
-     * @param sessionId
-     * @param sessionPasswd
-     * @throws IOException
-     */
-    public ZooKeeperRetry(String connectString, int sessionTimeout,
-            Watcher watcher, long sessionId, byte[] sessionPasswd)
-            throws IOException {
-        super(connectString, sessionTimeout, watcher, sessionId, sessionPasswd);
-        this.watcher = watcher;
-    }
-
-    @Override
-    public synchronized void close() throws InterruptedException {
-        this.closed = true;
-        super.close();
-    }
-
-    @Override
-    public String create(String path, byte[] data, List<ACL> acl,
-            CreateMode createMode) throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.create(path, data, acl, createMode);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-                if (exists(path, false) != null) {
-                    return path;
-                }
-            } catch (KeeperException.NodeExistsException e) {
-                return path;
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public void delete(String path, int version) throws InterruptedException,
-            KeeperException {
-        int count = 0;
-        do {
-            try {
-                super.delete(path, version);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-                if (exists(path, false) == null) {
-                    return;
-                }
-            } catch (KeeperException.NoNodeException e) {
-                break;
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-    }
-
-    @Override
-    public Stat exists(String path, boolean watch) throws KeeperException,
-            InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.exists(path, watch ? watcher : null);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public Stat exists(String path, Watcher watcher) throws KeeperException,
-            InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.exists(path, watcher);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public List<ACL> getACL(String path, Stat stat) throws KeeperException,
-            InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.getACL(path, stat);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public List<String> getChildren(String path, boolean watch)
-            throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.getChildren(path, watch ? watcher : null);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return new ArrayList<String>();
-    }
-
-    @Override
-    public List<String> getChildren(String path, Watcher watcher)
-            throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.getChildren(path, watcher);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return new ArrayList<String>();
-    }
-
-    @Override
-    public byte[] getData(String path, boolean watch, Stat stat)
-            throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.getData(path, watch ? watcher : null, stat);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public byte[] getData(String path, Watcher watcher, Stat stat)
-            throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.getData(path, watcher, stat);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public Stat setACL(String path, List<ACL> acl, int version)
-            throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.setACL(path, acl, version);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-                Stat s = exists(path, false);
-                if (s != null) {
-                    if (getACL(path, s).equals(acl)) {
-                        return s;
-                    }
-                } else {
-                    return null;
-                }
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    @Override
-    public Stat setData(String path, byte[] data, int version)
-            throws KeeperException, InterruptedException {
-        int count = 0;
-        do {
-            try {
-                return super.setData(path, data, version);
-            } catch (KeeperException.ConnectionLossException e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-                Stat s = exists(path, false);
-                if (s != null) {
-                    if (getData(path, false, s) == data) {
-                        return s;
-                    }
-                } else {
-                    return null;
-                }
-            }
-        } while (!closed && (limit == -1 || count++ < limit));
-        return null;
-    }
-
-    /**
-     * @param limit
-     */
-    public void setRetryLimit(int limit) {
-        this.limit = limit;
-    }
-
-    /**
-     * @return true if successfully connected to zookeeper
-     */
-    public boolean testConnection() {
-        int count = 0;
-        do {
-            try {
-                return super.exists("/", null) != null;
-            } catch (Exception e) {
-                LoggerFactory.getLogger().warn(
-                        "ZooKeeper connection lost.  Trying to reconnect.");
-            }
-        } while (count++ < 5);
-        return false;
-    }
-
-}
+/**
+ * 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.retry;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.inspector.logger.LoggerFactory;
+
+/**
+ * A Class which extends {@link ZooKeeper} and will automatically retry calls to
+ * zookeeper if a {@link KeeperException.ConnectionLossException} occurs
+ */
+public class ZooKeeperRetry extends ZooKeeper {
+
+    private boolean closed = false;
+    private final Watcher watcher;
+    private int limit = -1;
+
+    /**
+     * @param connectString
+     * @param sessionTimeout
+     * @param watcher
+     * @throws IOException
+     */
+    public ZooKeeperRetry(String connectString, int sessionTimeout,
+            Watcher watcher) throws IOException {
+        super(connectString, sessionTimeout, watcher);
+        this.watcher = watcher;
+    }
+
+    /**
+     * @param connectString
+     * @param sessionTimeout
+     * @param watcher
+     * @param sessionId
+     * @param sessionPasswd
+     * @throws IOException
+     */
+    public ZooKeeperRetry(String connectString, int sessionTimeout,
+            Watcher watcher, long sessionId, byte[] sessionPasswd)
+            throws IOException {
+        super(connectString, sessionTimeout, watcher, sessionId, sessionPasswd);
+        this.watcher = watcher;
+    }
+
+    @Override
+    public synchronized void close() throws InterruptedException {
+        this.closed = true;
+        super.close();
+    }
+
+    @Override
+    public String create(String path, byte[] data, List<ACL> acl,
+            CreateMode createMode) throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.create(path, data, acl, createMode);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+                if (exists(path, false) != null) {
+                    return path;
+                }
+            } catch (KeeperException.NodeExistsException e) {
+                return path;
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public void delete(String path, int version) throws InterruptedException,
+            KeeperException {
+        int count = 0;
+        do {
+            try {
+                super.delete(path, version);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+                if (exists(path, false) == null) {
+                    return;
+                }
+            } catch (KeeperException.NoNodeException e) {
+                break;
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+    }
+
+    @Override
+    public Stat exists(String path, boolean watch) throws KeeperException,
+            InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.exists(path, watch ? watcher : null);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public Stat exists(String path, Watcher watcher) throws KeeperException,
+            InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.exists(path, watcher);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public List<ACL> getACL(String path, Stat stat) throws KeeperException,
+            InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.getACL(path, stat);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public List<String> getChildren(String path, boolean watch)
+            throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.getChildren(path, watch ? watcher : null);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return new ArrayList<String>();
+    }
+
+    @Override
+    public List<String> getChildren(String path, Watcher watcher)
+            throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.getChildren(path, watcher);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return new ArrayList<String>();
+    }
+
+    @Override
+    public byte[] getData(String path, boolean watch, Stat stat)
+            throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.getData(path, watch ? watcher : null, stat);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public byte[] getData(String path, Watcher watcher, Stat stat)
+            throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.getData(path, watcher, stat);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public Stat setACL(String path, List<ACL> acl, int version)
+            throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.setACL(path, acl, version);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+                Stat s = exists(path, false);
+                if (s != null) {
+                    if (getACL(path, s).equals(acl)) {
+                        return s;
+                    }
+                } else {
+                    return null;
+                }
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    @Override
+    public Stat setData(String path, byte[] data, int version)
+            throws KeeperException, InterruptedException {
+        int count = 0;
+        do {
+            try {
+                return super.setData(path, data, version);
+            } catch (KeeperException.ConnectionLossException e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+                Stat s = exists(path, false);
+                if (s != null) {
+                    if (getData(path, false, s) == data) {
+                        return s;
+                    }
+                } else {
+                    return null;
+                }
+            }
+        } while (!closed && (limit == -1 || count++ < limit));
+        return null;
+    }
+
+    /**
+     * @param limit
+     */
+    public void setRetryLimit(int limit) {
+        this.limit = limit;
+    }
+
+    /**
+     * @return true if successfully connected to zookeeper
+     */
+    public boolean testConnection() {
+        int count = 0;
+        do {
+            try {
+                return super.exists("/", null) != null;
+            } catch (Exception e) {
+                LoggerFactory.getLogger().warn(
+                        "ZooKeeper connection lost.  Trying to reconnect.");
+            }
+        } while (count++ < 5);
+        return false;
+    }
+
+}

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/src/java/org/apache/zookeeper/retry/ZooKeeperRetry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector-dev.sh
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector-dev.sh?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector-dev.sh (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector-dev.sh Fri Apr  4 01:30:24 2014
@@ -1,18 +1,18 @@
-#!/bin/sh
-
-# 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.
-         
+#!/bin/sh
+
+# 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.
+         
 java -cp ../../../build/contrib/ZooInspector/zookeeper-dev-ZooInspector.jar:../../../build/lib/log4j-1.2.15.jar:lib/zookeeper-3.3.0.jar:lib/jtoaster-1.0.4.jar:lib org.apache.zookeeper.inspector.ZooInspector
\ No newline at end of file

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector-dev.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector.cmd
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector.cmd?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector.cmd (original)
+++ zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector.cmd Fri Apr  4 01:30:24 2014
@@ -1,18 +1,18 @@
-#!/bin/sh
-
-# 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.
-
+#!/bin/sh
+
+# 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.
+
 java -cp zookeeper-dev-ZooInspector.jar;lib/log4j-1.2.15.jar;lib/zookeeper-3.3.0.jar;lib/jToaster-1.0.4.jar;lib org.apache.zookeeper.inspector.ZooInspector
\ No newline at end of file

Propchange: zookeeper/branches/branch-3.4/src/contrib/zooinspector/zooInspector.cmd
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java (original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java Fri Apr  4 01:30:24 2014
@@ -1,128 +1,128 @@
-/**
- * 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.server;
-
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.zip.Adler32;
-import java.util.zip.CheckedInputStream;
-
-import org.apache.jute.BinaryInputArchive;
-import org.apache.jute.InputArchive;
-import org.apache.zookeeper.data.StatPersisted;
-import org.apache.zookeeper.server.persistence.FileSnap;
-
-/**
- * Dump a snapshot file to stdout.
- */
-public class SnapshotFormatter {
-
-    /**
-     * USAGE: SnapshotFormatter snapshot_file
-     */
-    public static void main(String[] args) throws Exception {
-        if (args.length != 1) {
-            System.err.println("USAGE: SnapshotFormatter snapshot_file");
-            System.exit(2);
-        }
-
-        new SnapshotFormatter().run(args[0]);
-    }
-    
-    public void run(String snapshotFileName) throws IOException {
-        InputStream is = new CheckedInputStream(
-                new BufferedInputStream(new FileInputStream(snapshotFileName)),
-                new Adler32());
-        InputArchive ia = BinaryInputArchive.getArchive(is);
-        
-        FileSnap fileSnap = new FileSnap(null);
-
-        DataTree dataTree = new DataTree();
-        Map<Long, Integer> sessions = new HashMap<Long, Integer>();
-        
-        fileSnap.deserialize(dataTree, sessions, ia);
-
-        printDetails(dataTree, sessions);
-    }
-
-    private void printDetails(DataTree dataTree, Map<Long, Integer> sessions) {
-        printZnodeDetails(dataTree);
-        printSessionDetails(dataTree, sessions);
-    }
-
-    private void printZnodeDetails(DataTree dataTree) {
-        System.out.println(String.format("ZNode Details (count=%d):",
-                dataTree.getNodeCount()));
-        
-        printZnode(dataTree, "/");
-        System.out.println("----");
-    }
-
-    private void printZnode(DataTree dataTree, String name) {
-        System.out.println("----");
-        DataNode n = dataTree.getNode(name);
-        Set<String> children;
-        synchronized(n) { // keep findbugs happy
-            System.out.println(name);
-            printStat(n.stat);
-            if (n.data != null) {
-                System.out.println("  dataLength = " + n.data.length);
-            } else {
-                System.out.println("  no data");
-            }
-            children = n.getChildren();
-        }
-        if (children != null) {
-            for (String child : children) {
-                printZnode(dataTree, name + (name.equals("/") ? "" : "/") + child);
-            }
-        }
-    }
-
-    private void printSessionDetails(DataTree dataTree, Map<Long, Integer> sessions) {
-        System.out.println("Session Details (sid, timeout, ephemeralCount):");
-        for (Map.Entry<Long, Integer> e : sessions.entrySet()) {
-            long sid = e.getKey();
-            System.out.println(String.format("%#016x, %d, %d",
-                    sid, e.getValue(), dataTree.getEphemerals(sid).size()));
-        }
-    }
-
-    private void printStat(StatPersisted stat) {
-        printHex("cZxid", stat.getCzxid());
-        System.out.println("  ctime = " + new Date(stat.getCtime()).toString());
-        printHex("mZxid", stat.getMzxid());
-        System.out.println("  mtime = " + new Date(stat.getMtime()).toString());
-        printHex("pZxid", stat.getPzxid());
-        System.out.println("  cversion = " + stat.getCversion());
-        System.out.println("  dataVersion = " + stat.getVersion());
-        System.out.println("  aclVersion = " + stat.getAversion());
-        printHex("ephemeralOwner", stat.getEphemeralOwner());
-    }
-
-    private void printHex(String prefix, long value) {
-        System.out.println(String.format("  %s = %#016x", prefix, value));
-    }
-}
+/**
+ * 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.server;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.zip.Adler32;
+import java.util.zip.CheckedInputStream;
+
+import org.apache.jute.BinaryInputArchive;
+import org.apache.jute.InputArchive;
+import org.apache.zookeeper.data.StatPersisted;
+import org.apache.zookeeper.server.persistence.FileSnap;
+
+/**
+ * Dump a snapshot file to stdout.
+ */
+public class SnapshotFormatter {
+
+    /**
+     * USAGE: SnapshotFormatter snapshot_file
+     */
+    public static void main(String[] args) throws Exception {
+        if (args.length != 1) {
+            System.err.println("USAGE: SnapshotFormatter snapshot_file");
+            System.exit(2);
+        }
+
+        new SnapshotFormatter().run(args[0]);
+    }
+    
+    public void run(String snapshotFileName) throws IOException {
+        InputStream is = new CheckedInputStream(
+                new BufferedInputStream(new FileInputStream(snapshotFileName)),
+                new Adler32());
+        InputArchive ia = BinaryInputArchive.getArchive(is);
+        
+        FileSnap fileSnap = new FileSnap(null);
+
+        DataTree dataTree = new DataTree();
+        Map<Long, Integer> sessions = new HashMap<Long, Integer>();
+        
+        fileSnap.deserialize(dataTree, sessions, ia);
+
+        printDetails(dataTree, sessions);
+    }
+
+    private void printDetails(DataTree dataTree, Map<Long, Integer> sessions) {
+        printZnodeDetails(dataTree);
+        printSessionDetails(dataTree, sessions);
+    }
+
+    private void printZnodeDetails(DataTree dataTree) {
+        System.out.println(String.format("ZNode Details (count=%d):",
+                dataTree.getNodeCount()));
+        
+        printZnode(dataTree, "/");
+        System.out.println("----");
+    }
+
+    private void printZnode(DataTree dataTree, String name) {
+        System.out.println("----");
+        DataNode n = dataTree.getNode(name);
+        Set<String> children;
+        synchronized(n) { // keep findbugs happy
+            System.out.println(name);
+            printStat(n.stat);
+            if (n.data != null) {
+                System.out.println("  dataLength = " + n.data.length);
+            } else {
+                System.out.println("  no data");
+            }
+            children = n.getChildren();
+        }
+        if (children != null) {
+            for (String child : children) {
+                printZnode(dataTree, name + (name.equals("/") ? "" : "/") + child);
+            }
+        }
+    }
+
+    private void printSessionDetails(DataTree dataTree, Map<Long, Integer> sessions) {
+        System.out.println("Session Details (sid, timeout, ephemeralCount):");
+        for (Map.Entry<Long, Integer> e : sessions.entrySet()) {
+            long sid = e.getKey();
+            System.out.println(String.format("%#016x, %d, %d",
+                    sid, e.getValue(), dataTree.getEphemerals(sid).size()));
+        }
+    }
+
+    private void printStat(StatPersisted stat) {
+        printHex("cZxid", stat.getCzxid());
+        System.out.println("  ctime = " + new Date(stat.getCtime()).toString());
+        printHex("mZxid", stat.getMzxid());
+        System.out.println("  mtime = " + new Date(stat.getMtime()).toString());
+        printHex("pZxid", stat.getPzxid());
+        System.out.println("  cversion = " + stat.getCversion());
+        System.out.println("  dataVersion = " + stat.getVersion());
+        System.out.println("  aclVersion = " + stat.getAversion());
+        printHex("ephemeralOwner", stat.getEphemeralOwner());
+    }
+
+    private void printHex(String prefix, long value) {
+        System.out.println(String.format("  %s = %#016x", prefix, value));
+    }
+}

Propchange: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/SnapshotFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java Fri Apr  4 01:30:24 2014
@@ -1,131 +1,131 @@
-/**
- * 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.server;
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.nio.ByteBuffer;
-import java.util.concurrent.CountDownLatch;
-
-import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.KeeperException.Code;
-import org.apache.zookeeper.KeeperException.SessionExpiredException;
-import org.apache.zookeeper.KeeperException.SessionMovedException;
-import org.apache.zookeeper.ZooDefs.OpCode;
-import org.apache.zookeeper.server.PrepRequestProcessor;
-import org.apache.zookeeper.server.Request;
-import org.apache.zookeeper.server.RequestProcessor;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.SyncRequestProcessor;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.test.ClientBase;
-import org.apache.zookeeper.txn.ErrorTxn;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class PrepRequestProcessorTest extends ClientBase {
-    private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
-    private static final int CONNECTION_TIMEOUT = 3000;
-    private final CountDownLatch testEnd = new CountDownLatch(1);
-
-    @Test
-    public void testPRequest() throws Exception {
-        File tmpDir = ClientBase.createTmpDir();
-        ClientBase.setupTestEnv();
-        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
-        SyncRequestProcessor.setSnapCount(100);
-        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
-        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
-        f.startup(zks);
-        Assert.assertTrue("waiting for server being up ",
-                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
-        zks.sessionTracker = new MySessionTracker(); 
-        PrepRequestProcessor processor = new PrepRequestProcessor(zks, new MyRequestProcessor());
-        Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null);
-        processor.pRequest(foo);
-        testEnd.await(5, java.util.concurrent.TimeUnit.SECONDS);
-        f.shutdown();
-        zks.shutdown();
-    }
- 
-
-    private class MyRequestProcessor implements RequestProcessor {
-        @Override
-        public void processRequest(Request request) {
-            Assert.assertEquals("Request should have marshalling error", new ErrorTxn(Code.MARSHALLINGERROR.intValue()),  request.txn);
-            testEnd.countDown();            
-        }
-        @Override
-        public void shutdown() {
-            // TODO Auto-generated method stub
-            
-        }
-    }
-    
-    private class MySessionTracker implements SessionTracker {
-        @Override
-        public void addSession(long id, int to) {
-            // TODO Auto-generated method stub
-            
-        }
-        @Override
-        public void checkSession(long sessionId, Object owner)
-                throws SessionExpiredException, SessionMovedException {
-            // TODO Auto-generated method stub
-            
-        }
-        @Override
-        public long createSession(int sessionTimeout) {
-            // TODO Auto-generated method stub
-            return 0;
-        }
-        @Override
-        public void dumpSessions(PrintWriter pwriter) {
-            // TODO Auto-generated method stub
-            
-        }
-         @Override
-        public void removeSession(long sessionId) {
-            // TODO Auto-generated method stub
-            
-        }
-        @Override
-        public void setOwner(long id, Object owner)
-                throws SessionExpiredException {
-            // TODO Auto-generated method stub
-            
-        }
-        @Override
-        public void shutdown() {
-            // TODO Auto-generated method stub
-            
-        }
-        @Override
-        public boolean touchSession(long sessionId, int sessionTimeout) {
-            // TODO Auto-generated method stub
-            return false;
-        }
-        @Override
-        public void setSessionClosing(long sessionId) {
-          // TODO Auto-generated method stub
-        }
-    }
-}
+/**
+ * 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.server;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.KeeperException.Code;
+import org.apache.zookeeper.KeeperException.SessionExpiredException;
+import org.apache.zookeeper.KeeperException.SessionMovedException;
+import org.apache.zookeeper.ZooDefs.OpCode;
+import org.apache.zookeeper.server.PrepRequestProcessor;
+import org.apache.zookeeper.server.Request;
+import org.apache.zookeeper.server.RequestProcessor;
+import org.apache.zookeeper.server.ServerCnxnFactory;
+import org.apache.zookeeper.server.SyncRequestProcessor;
+import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.test.ClientBase;
+import org.apache.zookeeper.txn.ErrorTxn;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PrepRequestProcessorTest extends ClientBase {
+    private static String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
+    private static final int CONNECTION_TIMEOUT = 3000;
+    private final CountDownLatch testEnd = new CountDownLatch(1);
+
+    @Test
+    public void testPRequest() throws Exception {
+        File tmpDir = ClientBase.createTmpDir();
+        ClientBase.setupTestEnv();
+        ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
+        SyncRequestProcessor.setSnapCount(100);
+        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
+        ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
+        f.startup(zks);
+        Assert.assertTrue("waiting for server being up ",
+                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
+        zks.sessionTracker = new MySessionTracker(); 
+        PrepRequestProcessor processor = new PrepRequestProcessor(zks, new MyRequestProcessor());
+        Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null);
+        processor.pRequest(foo);
+        testEnd.await(5, java.util.concurrent.TimeUnit.SECONDS);
+        f.shutdown();
+        zks.shutdown();
+    }
+ 
+
+    private class MyRequestProcessor implements RequestProcessor {
+        @Override
+        public void processRequest(Request request) {
+            Assert.assertEquals("Request should have marshalling error", new ErrorTxn(Code.MARSHALLINGERROR.intValue()),  request.txn);
+            testEnd.countDown();            
+        }
+        @Override
+        public void shutdown() {
+            // TODO Auto-generated method stub
+            
+        }
+    }
+    
+    private class MySessionTracker implements SessionTracker {
+        @Override
+        public void addSession(long id, int to) {
+            // TODO Auto-generated method stub
+            
+        }
+        @Override
+        public void checkSession(long sessionId, Object owner)
+                throws SessionExpiredException, SessionMovedException {
+            // TODO Auto-generated method stub
+            
+        }
+        @Override
+        public long createSession(int sessionTimeout) {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+        @Override
+        public void dumpSessions(PrintWriter pwriter) {
+            // TODO Auto-generated method stub
+            
+        }
+         @Override
+        public void removeSession(long sessionId) {
+            // TODO Auto-generated method stub
+            
+        }
+        @Override
+        public void setOwner(long id, Object owner)
+                throws SessionExpiredException {
+            // TODO Auto-generated method stub
+            
+        }
+        @Override
+        public void shutdown() {
+            // TODO Auto-generated method stub
+            
+        }
+        @Override
+        public boolean touchSession(long sessionId, int sessionTimeout) {
+            // TODO Auto-generated method stub
+            return false;
+        }
+        @Override
+        public void setSessionClosing(long sessionId) {
+          // TODO Auto-generated method stub
+        }
+    }
+}

Propchange: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/PrepRequestProcessorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java Fri Apr  4 01:30:24 2014
@@ -1,105 +1,105 @@
-/**
- * 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.io.File;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.HashMap;
-
-import org.apache.zookeeper.server.quorum.FastLeaderElection;
-import org.apache.zookeeper.server.quorum.QuorumCnxManager;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
-import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
-import org.apache.zookeeper.PortAssignment;
-import org.apache.zookeeper.ZKTestCase;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class FLEPredicateTest extends ZKTestCase {
-    
-    protected static final Logger LOG = LoggerFactory.getLogger(FLEPredicateTest.class);
-    
-    class MockFLE extends FastLeaderElection {
-        MockFLE(QuorumPeer peer){
-            super(peer, new QuorumCnxManager(peer));
-        }
-        
-        boolean predicate(long newId, long newZxid, long newEpoch, long curId, long curZxid, long curEpoch){
-            return this.totalOrderPredicate(newId, newZxid, newEpoch, curId, curZxid, curEpoch);
-        }
-    }
-    
-    
-    HashMap<Long,QuorumServer> peers;
-    
-    @Test
-    public void testPredicate() throws IOException {
-        
-        peers = new HashMap<Long,QuorumServer>(3);
-        
-        /*
-         * Creates list of peers.
-         */
-        for(int i = 0; i < 3; i++) {
-            peers.put(Long.valueOf(i),
-                    new QuorumServer(i,
-                            new InetSocketAddress(PortAssignment.unique()),
-                    new InetSocketAddress(PortAssignment.unique())));
-        }
-
-        /*
-         * Creating peer.
-         */
-        try{
-            File tmpDir = ClientBase.createTmpDir();
-            QuorumPeer peer = new QuorumPeer(peers, tmpDir, tmpDir,
-                                        PortAssignment.unique(), 3, 0, 1000, 2, 2);
-        
-            MockFLE mock = new MockFLE(peer);
-            
-            /*
-             * Lower epoch must return false
-             */
-            
-            Assert.assertFalse (mock.predicate(4L, 0L, 0L, 3L, 0L, 2L));
-            
-            /*
-             * Later epoch
-             */
-            Assert.assertTrue (mock.predicate(0L, 0L, 1L, 1L, 0L, 0L));
-        
-            /*
-             * Higher zxid
-             */
-            Assert.assertTrue(mock.predicate(0L, 1L, 0L, 1L, 0L, 0L));
-        
-            /*
-             * Higher id
-             */
-            Assert.assertTrue(mock.predicate(1L, 1L, 0L, 0L, 1L, 0L));
-        } catch (IOException e) {
-            LOG.error("Exception while creating quorum peer", e);
-            Assert.fail("Exception while creating quorum peer");
-        }
-    }
-}
+/**
+ * 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.io.File;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+
+import org.apache.zookeeper.server.quorum.FastLeaderElection;
+import org.apache.zookeeper.server.quorum.QuorumCnxManager;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.apache.zookeeper.PortAssignment;
+import org.apache.zookeeper.ZKTestCase;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class FLEPredicateTest extends ZKTestCase {
+    
+    protected static final Logger LOG = LoggerFactory.getLogger(FLEPredicateTest.class);
+    
+    class MockFLE extends FastLeaderElection {
+        MockFLE(QuorumPeer peer){
+            super(peer, new QuorumCnxManager(peer));
+        }
+        
+        boolean predicate(long newId, long newZxid, long newEpoch, long curId, long curZxid, long curEpoch){
+            return this.totalOrderPredicate(newId, newZxid, newEpoch, curId, curZxid, curEpoch);
+        }
+    }
+    
+    
+    HashMap<Long,QuorumServer> peers;
+    
+    @Test
+    public void testPredicate() throws IOException {
+        
+        peers = new HashMap<Long,QuorumServer>(3);
+        
+        /*
+         * Creates list of peers.
+         */
+        for(int i = 0; i < 3; i++) {
+            peers.put(Long.valueOf(i),
+                    new QuorumServer(i,
+                            new InetSocketAddress(PortAssignment.unique()),
+                    new InetSocketAddress(PortAssignment.unique())));
+        }
+
+        /*
+         * Creating peer.
+         */
+        try{
+            File tmpDir = ClientBase.createTmpDir();
+            QuorumPeer peer = new QuorumPeer(peers, tmpDir, tmpDir,
+                                        PortAssignment.unique(), 3, 0, 1000, 2, 2);
+        
+            MockFLE mock = new MockFLE(peer);
+            
+            /*
+             * Lower epoch must return false
+             */
+            
+            Assert.assertFalse (mock.predicate(4L, 0L, 0L, 3L, 0L, 2L));
+            
+            /*
+             * Later epoch
+             */
+            Assert.assertTrue (mock.predicate(0L, 0L, 1L, 1L, 0L, 0L));
+        
+            /*
+             * Higher zxid
+             */
+            Assert.assertTrue(mock.predicate(0L, 1L, 0L, 1L, 0L, 0L));
+        
+            /*
+             * Higher id
+             */
+            Assert.assertTrue(mock.predicate(1L, 1L, 0L, 0L, 1L, 0L));
+        } catch (IOException e) {
+            LOG.error("Exception while creating quorum peer", e);
+            Assert.fail("Exception while creating quorum peer");
+        }
+    }
+}

Propchange: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/FLEPredicateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ObserverLETest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ObserverLETest.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ObserverLETest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ObserverLETest.java Fri Apr  4 01:30:24 2014
@@ -1,76 +1,76 @@
-/**
- * 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 static org.junit.Assert.*;
-
-import java.util.Arrays;
-
-import org.apache.zookeeper.ZKTestCase;
-import org.apache.zookeeper.server.quorum.QuorumPeer;
-import org.apache.zookeeper.server.quorum.QuorumStats;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ObserverLETest extends ZKTestCase {
-    final QuorumBase qb = new QuorumBase();
-    final ClientTest ct = new ClientTest();
-
-    @Before
-    public void establishThreeParticipantOneObserverEnsemble() throws Exception {
-        qb.setUp(true);
-        ct.hostPort = qb.hostPort;
-        ct.setUpAll();
-        qb.s5.shutdown();
-    }
-
-    @After
-    public void shutdownQuorum() throws Exception {
-        ct.tearDownAll();
-        qb.tearDown();
-    }
-
-    /**
-     * See ZOOKEEPER-1294. Confirms that an observer will not support the quorum
-     * of a leader by forming a 5-node, 2-observer ensemble (so quorum size is 2).
-     * When all but the leader and one observer are shut down, the leader should
-     * enter the 'looking' state, not stay in the 'leading' state.
-     */
-    @Test
-    public void testLEWithObserver() throws Exception {
-        QuorumPeer leader = null;
-        for (QuorumPeer server : Arrays.asList(qb.s1, qb.s2, qb.s3)) {
-            if (server.getServerState().equals(
-                    QuorumStats.Provider.FOLLOWING_STATE)) {
-                server.shutdown();
-                assertTrue("Waiting for server down", ClientBase
-                        .waitForServerDown("127.0.0.1:"
-                                + server.getClientPort(),
-                                ClientBase.CONNECTION_TIMEOUT));
-            } else {
-                assertNull("More than one leader found", leader);
-                leader = server;
-            }
-        }
-        assertTrue("Leader is not in Looking state", ClientBase
-                .waitForServerState(leader, ClientBase.CONNECTION_TIMEOUT,
-                        QuorumStats.Provider.LOOKING_STATE));
-    }
-
-}
+/**
+ * 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 static org.junit.Assert.*;
+
+import java.util.Arrays;
+
+import org.apache.zookeeper.ZKTestCase;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.QuorumStats;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ObserverLETest extends ZKTestCase {
+    final QuorumBase qb = new QuorumBase();
+    final ClientTest ct = new ClientTest();
+
+    @Before
+    public void establishThreeParticipantOneObserverEnsemble() throws Exception {
+        qb.setUp(true);
+        ct.hostPort = qb.hostPort;
+        ct.setUpAll();
+        qb.s5.shutdown();
+    }
+
+    @After
+    public void shutdownQuorum() throws Exception {
+        ct.tearDownAll();
+        qb.tearDown();
+    }
+
+    /**
+     * See ZOOKEEPER-1294. Confirms that an observer will not support the quorum
+     * of a leader by forming a 5-node, 2-observer ensemble (so quorum size is 2).
+     * When all but the leader and one observer are shut down, the leader should
+     * enter the 'looking' state, not stay in the 'leading' state.
+     */
+    @Test
+    public void testLEWithObserver() throws Exception {
+        QuorumPeer leader = null;
+        for (QuorumPeer server : Arrays.asList(qb.s1, qb.s2, qb.s3)) {
+            if (server.getServerState().equals(
+                    QuorumStats.Provider.FOLLOWING_STATE)) {
+                server.shutdown();
+                assertTrue("Waiting for server down", ClientBase
+                        .waitForServerDown("127.0.0.1:"
+                                + server.getClientPort(),
+                                ClientBase.CONNECTION_TIMEOUT));
+            } else {
+                assertNull("More than one leader found", leader);
+                leader = server;
+            }
+        }
+        assertTrue("Leader is not in Looking state", ClientBase
+                .waitForServerState(leader, ClientBase.CONNECTION_TIMEOUT,
+                        QuorumStats.Provider.LOOKING_STATE));
+    }
+
+}

Propchange: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/ObserverLETest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java?rev=1584500&r1=1584499&r2=1584500&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java (original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java Fri Apr  4 01:30:24 2014
@@ -1,105 +1,105 @@
-/**
- * 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.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-
-import junit.framework.Assert;
-
-import org.apache.jute.BinaryOutputArchive;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooDefs.Ids;
-import org.apache.zookeeper.ZooDefs.OpCode;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.proto.ConnectRequest;
-import org.apache.zookeeper.proto.CreateRequest;
-import org.apache.zookeeper.proto.RequestHeader;
-import org.junit.Test;
-
-public class SessionInvalidationTest extends ClientBase {
-    /**
-     * Test solution for ZOOKEEPER-1208. Verify that operations are not
-     * accepted after a close session.
-     * 
-     * We're using our own marshalling here in order to force an operation
-     * after the session is closed (ZooKeeper.class will not allow this). Also
-     * by filling the pipe with operations it increases the likelyhood that
-     * the server will process the create before FinalRequestProcessor
-     * removes the session from the tracker.
-     */
-    @Test
-    public void testCreateAfterCloseShouldFail() throws Exception {
-        for (int i = 0; i < 10; i++) {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
-
-            // open a connection
-            boa.writeInt(44, "len");
-            ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]);
-            conReq.serialize(boa, "connect");
-
-            // close connection
-            boa.writeInt(8, "len");
-            RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.closeSession);
-            h.serialize(boa, "header");
-
-            // create ephemeral znode
-            boa.writeInt(52, "len"); // We'll fill this in later
-            RequestHeader header = new RequestHeader(2, OpCode.create);
-            header.serialize(boa, "header");
-            CreateRequest createReq = new CreateRequest("/foo" + i, new byte[0],
-                    Ids.OPEN_ACL_UNSAFE, 1);
-            createReq.serialize(boa, "request");
-            baos.close();
-            
-            System.out.println("Length:" + baos.toByteArray().length);
-            
-            String hp[] = hostPort.split(":");
-            Socket sock = new Socket(hp[0], Integer.parseInt(hp[1]));
-            InputStream resultStream = null;
-            try {
-                OutputStream outstream = sock.getOutputStream();
-                byte[] data = baos.toByteArray();
-                outstream.write(data);
-                outstream.flush();
-                
-                resultStream = sock.getInputStream();
-                byte[] b = new byte[10000];
-                int len;
-                while ((len = resultStream.read(b)) >= 0) {
-                    // got results
-                    System.out.println("gotlen:" + len);
-                }
-            } finally {
-                if (resultStream != null) {
-                    resultStream.close();
-                }
-                sock.close();
-            }
-        }
-        
-        ZooKeeper zk = createClient();
-        Assert.assertEquals(1, zk.getChildren("/", false).size());
-
-        zk.close();
-    }
-}
+/**
+ * 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.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+import junit.framework.Assert;
+
+import org.apache.jute.BinaryOutputArchive;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooDefs.OpCode;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.proto.ConnectRequest;
+import org.apache.zookeeper.proto.CreateRequest;
+import org.apache.zookeeper.proto.RequestHeader;
+import org.junit.Test;
+
+public class SessionInvalidationTest extends ClientBase {
+    /**
+     * Test solution for ZOOKEEPER-1208. Verify that operations are not
+     * accepted after a close session.
+     * 
+     * We're using our own marshalling here in order to force an operation
+     * after the session is closed (ZooKeeper.class will not allow this). Also
+     * by filling the pipe with operations it increases the likelyhood that
+     * the server will process the create before FinalRequestProcessor
+     * removes the session from the tracker.
+     */
+    @Test
+    public void testCreateAfterCloseShouldFail() throws Exception {
+        for (int i = 0; i < 10; i++) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
+
+            // open a connection
+            boa.writeInt(44, "len");
+            ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]);
+            conReq.serialize(boa, "connect");
+
+            // close connection
+            boa.writeInt(8, "len");
+            RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.closeSession);
+            h.serialize(boa, "header");
+
+            // create ephemeral znode
+            boa.writeInt(52, "len"); // We'll fill this in later
+            RequestHeader header = new RequestHeader(2, OpCode.create);
+            header.serialize(boa, "header");
+            CreateRequest createReq = new CreateRequest("/foo" + i, new byte[0],
+                    Ids.OPEN_ACL_UNSAFE, 1);
+            createReq.serialize(boa, "request");
+            baos.close();
+            
+            System.out.println("Length:" + baos.toByteArray().length);
+            
+            String hp[] = hostPort.split(":");
+            Socket sock = new Socket(hp[0], Integer.parseInt(hp[1]));
+            InputStream resultStream = null;
+            try {
+                OutputStream outstream = sock.getOutputStream();
+                byte[] data = baos.toByteArray();
+                outstream.write(data);
+                outstream.flush();
+                
+                resultStream = sock.getInputStream();
+                byte[] b = new byte[10000];
+                int len;
+                while ((len = resultStream.read(b)) >= 0) {
+                    // got results
+                    System.out.println("gotlen:" + len);
+                }
+            } finally {
+                if (resultStream != null) {
+                    resultStream.close();
+                }
+                sock.close();
+            }
+        }
+        
+        ZooKeeper zk = createClient();
+        Assert.assertEquals(1, zk.getChildren("/", false).size());
+
+        zk.close();
+    }
+}

Propchange: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/SessionInvalidationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message