accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [accumulo] branch master updated: Fix #461 Handle race condition in AccumuloMonitorAppenderTest
Date Thu, 03 May 2018 21:07:21 GMT
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 8679827  Fix #461 Handle race condition in AccumuloMonitorAppenderTest
8679827 is described below

commit 8679827e5c14c2147c58cf18d357c591bbe2a161
Author: Christopher Tubbs <ctubbsii@apache.org>
AuthorDate: Thu May 3 16:59:34 2018 -0400

    Fix #461 Handle race condition in AccumuloMonitorAppenderTest
    
    Catch NoSuchElementException and handle it in the
    AccumuloMonitorAppenderTest. This can happen if the test sees the state
    of the appender while it is being updated from the old monitor location
    to the new location.
    
    Updates to the appender occurs in a single thread. Dispatching log
    events are synchronized, and thread-safe, so this only ever affected the
    test itself.
---
 .../monitor/util/AccumuloMonitorAppenderTest.java         | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/server/monitor/src/test/java/org/apache/accumulo/monitor/util/AccumuloMonitorAppenderTest.java
b/server/monitor/src/test/java/org/apache/accumulo/monitor/util/AccumuloMonitorAppenderTest.java
index 91f9b96..4b03abc 100644
--- a/server/monitor/src/test/java/org/apache/accumulo/monitor/util/AccumuloMonitorAppenderTest.java
+++ b/server/monitor/src/test/java/org/apache/accumulo/monitor/util/AccumuloMonitorAppenderTest.java
@@ -20,6 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.fail;
 
 import java.util.Enumeration;
+import java.util.NoSuchElementException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
@@ -168,11 +169,13 @@ public class AccumuloMonitorAppenderTest {
   }
 
   private static void updateLocAndVerify(AtomicLong currentLoc, AccumuloMonitorAppender parent,
-      int newLoc) {
+      int newLoc) throws InterruptedException {
     // set the new location
     currentLoc.set(newLoc);
     // wait for the appender to notice the change
-    while (!verifyAppender(parent, newLoc == 0 ? null : ("loc" + newLoc))) {}
+    while (!verifyAppender(parent, newLoc == 0 ? null : ("loc" + newLoc))) {
+      Thread.sleep(10);
+    }
   }
 
   private static boolean verifyAppender(AccumuloMonitorAppender parent, String newLocName)
{
@@ -183,7 +186,13 @@ public class AccumuloMonitorAppenderTest {
     if (childAppenders == null || !childAppenders.hasMoreElements()) {
       return false;
     }
-    AppenderSkeleton child = (AppenderSkeleton) childAppenders.nextElement();
+    AppenderSkeleton child = null;
+    try {
+      child = (AppenderSkeleton) childAppenders.nextElement();
+    } catch (NoSuchElementException e) {
+      // Enumeration not thread safe; appender for old loc was removed after we did hasMoreElements
+      return false;
+    }
     if (childAppenders.hasMoreElements()) {
       Assert.fail("Appender should never have more than one child");
     }

-- 
To stop receiving notification emails like this one, please contact
ctubbsii@apache.org.

Mime
View raw message