You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/10/21 00:03:29 UTC
[4/7] git commit: ACCUMULO-3242 Spelling error,
missing hashCode/toString/equals on ZKConnectionInfo, and some extra braces.
ACCUMULO-3242 Spelling error, missing hashCode/toString/equals on ZKConnectionInfo, and some extra braces.
Recommendations from Eric about ZK changes on reviewboard
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/15e83709
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/15e83709
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/15e83709
Branch: refs/heads/1.6
Commit: 15e83709a4338da619392c99ee83bb016ff1c9c4
Parents: 2e6be53
Author: Josh Elser <el...@apache.org>
Authored: Mon Oct 20 17:10:22 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Mon Oct 20 17:10:22 2014 -0400
----------------------------------------------------------------------
.../accumulo/fate/zookeeper/ZooCache.java | 2 +-
.../apache/accumulo/fate/zookeeper/ZooUtil.java | 70 ++++++++++++++++++--
.../zookeeper/ZooKeeperConnectionInfoTest.java | 31 +++++++++
3 files changed, 97 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/15e83709/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
index b3dd19a..d72ac08 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java
@@ -162,7 +162,7 @@ public class ZooCache {
if (code == Code.NONODE) {
log.error("Looked up non-existent node in cache " + e.getPath(), e);
} else if (code == Code.CONNECTIONLOSS || code == Code.OPERATIONTIMEOUT || code == Code.SESSIONEXPIRED) {
- log.warn("Saw (possibly) transient exception communicating with ZooKeeper, wil retry", e);
+ log.warn("Saw (possibly) transient exception communicating with ZooKeeper, will retry", e);
continue;
}
log.warn("Zookeeper error, will retry", e);
http://git-wip-us.apache.org/repos/asf/accumulo/blob/15e83709/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
index 674c1d8..1a3af6b 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java
@@ -18,9 +18,11 @@ package org.apache.accumulo.fate.zookeeper;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.log4j.Logger;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
@@ -32,6 +34,8 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
+import com.google.common.base.Preconditions;
+
public class ZooUtil {
private static final Logger log = Logger.getLogger(ZooUtil.class);
@@ -87,11 +91,68 @@ public class ZooUtil {
byte[] auth;
public ZooKeeperConnectionInfo(String keepers, int timeout, String scheme, byte[] auth) {
+ Preconditions.checkNotNull(keepers);
this.keepers = keepers;
this.timeout = timeout;
this.scheme = scheme;
this.auth = auth;
}
+
+ @Override
+ public int hashCode() {
+ final HashCodeBuilder hcb = new HashCodeBuilder(31, 47);
+ hcb.append(keepers).append(timeout);
+ if (null != scheme) {
+ hcb.append(scheme);
+ }
+ if (null != auth) {
+ hcb.append(auth);
+ }
+ return hcb.toHashCode();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof ZooKeeperConnectionInfo) {
+ ZooKeeperConnectionInfo other = (ZooKeeperConnectionInfo) o;
+ if (!keepers.equals(other.keepers) || timeout != other.timeout) {
+ return false;
+ }
+
+ if (null != scheme) {
+ if (null == other.scheme) {
+ // Ours is non-null, theirs is null
+ return false;
+ } else if (!scheme.equals(other.scheme)) {
+ // Both non-null but not equal
+ return false;
+ }
+ }
+
+ if (null != auth) {
+ if (null == other.auth) {
+ return false;
+ } else if (!Arrays.equals(auth, other.auth)) {
+ // both non-null but not equal
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(64);
+ sb.append("zookeepers=").append(keepers);
+ sb.append(", timeout=").append(timeout);
+ sb.append(", scheme=").append(scheme);
+ sb.append(", auth=").append(null == auth ? "null" : "REDACTED");
+ return sb.toString();
+ }
}
public static final List<ACL> PRIVATE;
@@ -206,8 +267,7 @@ public class ZooUtil {
}
public static boolean putPersistentData(ZooKeeperConnectionInfo info, String zPath, byte[] data, int version, NodeExistsPolicy policy)
- throws KeeperException,
- InterruptedException {
+ throws KeeperException, InterruptedException {
return putData(info, zPath, data, CreateMode.PERSISTENT, version, policy, PUBLIC);
}
@@ -216,8 +276,7 @@ public class ZooUtil {
return putData(info, zPath, data, CreateMode.PERSISTENT, version, policy, acls);
}
- private static boolean putData(ZooKeeperConnectionInfo info, String zPath, byte[] data, CreateMode mode, int version,
- NodeExistsPolicy policy, List<ACL> acls)
+ private static boolean putData(ZooKeeperConnectionInfo info, String zPath, byte[] data, CreateMode mode, int version, NodeExistsPolicy policy, List<ACL> acls)
throws KeeperException, InterruptedException {
if (policy == null)
policy = NodeExistsPolicy.FAIL;
@@ -347,8 +406,9 @@ public class ZooUtil {
}
retry.waitForNextAttempt();
}
- for (String child : children)
+ for (String child : children) {
recursiveCopyPersistent(info, source + "/" + child, destination + "/" + child, policy);
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/15e83709/fate/src/test/java/org/apache/accumulo/fate/zookeeper/ZooKeeperConnectionInfoTest.java
----------------------------------------------------------------------
diff --git a/fate/src/test/java/org/apache/accumulo/fate/zookeeper/ZooKeeperConnectionInfoTest.java b/fate/src/test/java/org/apache/accumulo/fate/zookeeper/ZooKeeperConnectionInfoTest.java
new file mode 100644
index 0000000..a54f236
--- /dev/null
+++ b/fate/src/test/java/org/apache/accumulo/fate/zookeeper/ZooKeeperConnectionInfoTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.accumulo.fate.zookeeper;
+
+import org.apache.accumulo.fate.zookeeper.ZooUtil.ZooKeeperConnectionInfo;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ZooKeeperConnectionInfoTest {
+
+ @Test
+ public void testEquality() {
+ Assert.assertEquals(new ZooKeeperConnectionInfo("localhost:2181", 60000, null, null), new ZooKeeperConnectionInfo("localhost:2181", 60000, null, null));
+ Assert.assertEquals(new ZooKeeperConnectionInfo("localhost:2181", 60000, null, null).hashCode(), new ZooKeeperConnectionInfo("localhost:2181", 60000, null,
+ null).hashCode());
+ }
+}