You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2018/05/31 03:32:41 UTC
[accumulo] branch master updated: Catch NoNodeException in
MonitorUtil and return null instead (#505)
This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push:
new 32e8035 Catch NoNodeException in MonitorUtil and return null instead (#505)
32e8035 is described below
commit 32e8035095b0ede9eae7101cb3154a47ee1c08f3
Author: Josh Elser <jo...@gmail.com>
AuthorDate: Wed May 30 23:32:39 2018 -0400
Catch NoNodeException in MonitorUtil and return null instead (#505)
---
.../org/apache/accumulo/core/util/MonitorUtil.java | 19 ++++++++++++---
.../accumulo/core/util/MonitorUtilTest.java} | 27 ++++++++++++++++------
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java b/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java
index e1a9741..862d70a 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java
@@ -23,11 +23,24 @@ import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.zookeeper.ZooUtil;
import org.apache.accumulo.fate.zookeeper.ZooReader;
import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.NoNodeException;
+
+import com.google.common.annotations.VisibleForTesting;
public class MonitorUtil {
public static String getLocation(Instance instance) throws KeeperException, InterruptedException {
- ZooReader zr = new ZooReader(instance.getZooKeepers(), 30000);
- byte[] loc = zr.getData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, null);
- return loc == null ? null : new String(loc, UTF_8);
+ return getLocation(new ZooReader(instance.getZooKeepers(), 30000), instance);
+ }
+
+ @VisibleForTesting
+ static String getLocation(ZooReader zr, Instance instance)
+ throws KeeperException, InterruptedException {
+ try {
+ byte[] loc = zr.getData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, null);
+ return loc == null ? null : new String(loc, UTF_8);
+ } catch (NoNodeException e) {
+ // If there's no node advertising the monitor, there's no monitor.
+ return null;
+ }
}
}
diff --git a/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java b/core/src/test/java/org/apache/accumulo/core/util/MonitorUtilTest.java
similarity index 57%
copy from core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java
copy to core/src/test/java/org/apache/accumulo/core/util/MonitorUtilTest.java
index e1a9741..0eccb2b 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/MonitorUtil.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/MonitorUtilTest.java
@@ -16,18 +16,31 @@
*/
package org.apache.accumulo.core.util;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.mock;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNull;
import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.zookeeper.ZooUtil;
import org.apache.accumulo.fate.zookeeper.ZooReader;
-import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.NoNodeException;
+import org.junit.Test;
-public class MonitorUtil {
- public static String getLocation(Instance instance) throws KeeperException, InterruptedException {
- ZooReader zr = new ZooReader(instance.getZooKeepers(), 30000);
- byte[] loc = zr.getData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, null);
- return loc == null ? null : new String(loc, UTF_8);
+public class MonitorUtilTest {
+
+ @Test
+ public void testNoNodeFound() throws Exception {
+ final String instanceId = "12345";
+
+ ZooReader zr = mock(ZooReader.class);
+ Instance mockInstance = mock(Instance.class);
+ expect(mockInstance.getInstanceID()).andReturn(instanceId);
+ expect(zr.getData(ZooUtil.getRoot(instanceId) + Constants.ZMONITOR_HTTP_ADDR, null))
+ .andThrow(new NoNodeException());
+
+ replay(zr, mockInstance);
+ assertNull(MonitorUtil.getLocation(zr, mockInstance));
}
}
--
To stop receiving notification emails like this one, please contact
ctubbsii@apache.org.