From 08b6808489213eed6bd9d6531d0febd09eead538 Mon Sep 17 00:00:00 2001 From: Zhe Zhang Date: Wed, 31 Aug 2016 23:43:59 -0700 Subject: [PATCH] Addendum fix for HDFS-10817 to fix failure of the added testFSReadLockLongHoldingReport in branch-2. (cherry picked from commit 6c600360ca469d5fe0f017d681585db06c80c9cc) (cherry picked from commit 776eccd87391767272371586fe7b0ed11b263319) --- .../server/namenode/TestFSNamesystem.java | 50 +++---------------- 1 file changed, 6 insertions(+), 44 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java index 1bd4fd2c634..dedf2ac7e07 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSNamesystem.java @@ -60,6 +60,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException; +import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestFSNamesystem { @@ -432,54 +433,15 @@ public class TestFSNamesystem { t2.start(); t1.join(); t2.join(); + // Look for the differentiating class names in the stack trace + String stackTracePatternString = + String.format("INFO.+%s(.+\n){4}\\Q%%s\\E\\.run", readLockLogStmt); Pattern t1Pattern = Pattern.compile( - String.format("\\Q%s\\E.+%s", t1.getName(), readLockLogStmt)); + String.format(stackTracePatternString, t1.getClass().getName())); assertTrue(t1Pattern.matcher(logs.getOutput()).find()); Pattern t2Pattern = Pattern.compile( - String.format("\\Q%s\\E.+%s", t2.getName(), readLockLogStmt)); + String.format(stackTracePatternString, t2.getClass().getName())); assertFalse(t2Pattern.matcher(logs.getOutput()).find()); - - // Spin up a bunch of threads all grabbing the lock at once; assign some - // to go over threshold and some under. Check that they all log correctly. - logs.clearOutput(); - final int threadCount = 50; - List threads = new ArrayList<>(threadCount); - for (int i = 0; i < threadCount; i++) { - threads.add(new Thread() { - @Override - public void run() { - try { - long sleepTime; - if (this.getName().hashCode() % 2 == 0) { - sleepTime = readLockReportingThreshold + 10; - } else { - sleepTime = readLockReportingThreshold / 2; - } - fsn.readLock(); - Thread.sleep(sleepTime); - fsn.readUnlock(); - } catch (InterruptedException e) { - fail("Interrupted during testing"); - } - } - }); - } - for (Thread t : threads) { - t.start(); - } - for (Thread t : threads) { - t.join(); - } - for (Thread t : threads) { - Pattern p = Pattern.compile( - String.format("\\Q%s\\E.+%s", t.getName(), readLockLogStmt)); - boolean foundLog = p.matcher(logs.getOutput()).find(); - if (t.getName().hashCode() % 2 == 0) { - assertTrue(foundLog); - } else { - assertFalse(foundLog); - } - } } @Test