You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/05/31 03:32:41 UTC

[GitHub] ctubbsii closed pull request #505: Catch NoNodeException in MonitorUtil and return null instead #504

ctubbsii closed pull request #505: Catch NoNodeException in MonitorUtil and return null instead #504
URL: https://github.com/apache/accumulo/pull/505
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 e1a97418c6..862d70a112 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.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/test/java/org/apache/accumulo/core/util/MonitorUtilTest.java b/core/src/test/java/org/apache/accumulo/core/util/MonitorUtilTest.java
new file mode 100644
index 0000000000..0eccb2b858
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/MonitorUtilTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.core.util;
+
+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.NoNodeException;
+import org.junit.Test;
+
+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));
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services