From 71b7f1f85fb305886c1ef178c1e17aac0d2e3d28 Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Fri, 15 Apr 2016 14:14:36 +0900 Subject: [PATCH] HADOOP-12989. Some tests in org.apache.hadoop.fs.shell.find occasionally time out. Contributed by Takashi Ohnishi. (cherry picked from commit 6e6b6dd5aaf93cfb373833cd175ee722d2cb708f) (cherry picked from commit 5ae74507c0d64eef4ea65973d798981bc56de61b) --- .../apache/hadoop/fs/shell/find/TestAnd.java | 25 ++++++----- .../fs/shell/find/TestFilterExpression.java | 27 +++++++----- .../apache/hadoop/fs/shell/find/TestFind.java | 3 +- .../hadoop/fs/shell/find/TestIname.java | 17 +++++--- .../apache/hadoop/fs/shell/find/TestName.java | 17 +++++--- .../hadoop/fs/shell/find/TestPrint.java | 9 +++- .../hadoop/fs/shell/find/TestPrint0.java | 9 +++- .../hadoop/fs/shell/find/TestResult.java | 41 +++++++++++-------- 8 files changed, 92 insertions(+), 56 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestAnd.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestAnd.java index d82a25e07b6..bb5ca4ca1c5 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestAnd.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestAnd.java @@ -26,12 +26,17 @@ import java.util.Deque; import java.util.LinkedList; import org.apache.hadoop.fs.shell.PathData; +import org.junit.Rule; +import org.junit.rules.Timeout; import org.junit.Test; public class TestAnd { + @Rule + public Timeout globalTimeout = new Timeout(10000); + // test all expressions passing - @Test(timeout = 1000) + @Test public void testPass() throws IOException { And and = new And(); @@ -56,7 +61,7 @@ public class TestAnd { } // test the first expression failing - @Test(timeout = 1000) + @Test public void testFailFirst() throws IOException { And and = new And(); @@ -80,7 +85,7 @@ public class TestAnd { } // test the second expression failing - @Test(timeout = 1000) + @Test public void testFailSecond() throws IOException { And and = new And(); @@ -105,7 +110,7 @@ public class TestAnd { } // test both expressions failing - @Test(timeout = 1000) + @Test public void testFailBoth() throws IOException { And and = new And(); @@ -129,7 +134,7 @@ public class TestAnd { } // test the first expression stopping - @Test(timeout = 1000) + @Test public void testStopFirst() throws IOException { And and = new And(); @@ -154,7 +159,7 @@ public class TestAnd { } // test the second expression stopping - @Test(timeout = 1000) + @Test public void testStopSecond() throws IOException { And and = new And(); @@ -179,7 +184,7 @@ public class TestAnd { } // test first expression stopping and second failing - @Test(timeout = 1000) + @Test public void testStopFail() throws IOException { And and = new And(); @@ -204,7 +209,7 @@ public class TestAnd { } // test setOptions is called on child - @Test(timeout = 1000) + @Test public void testSetOptions() throws IOException { And and = new And(); Expression first = mock(Expression.class); @@ -224,7 +229,7 @@ public class TestAnd { } // test prepare is called on child - @Test(timeout = 1000) + @Test public void testPrepare() throws IOException { And and = new And(); Expression first = mock(Expression.class); @@ -243,7 +248,7 @@ public class TestAnd { } // test finish is called on child - @Test(timeout = 1000) + @Test public void testFinish() throws IOException { And and = new And(); Expression first = mock(Expression.class); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFilterExpression.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFilterExpression.java index 5986a06b23f..7ad0574e183 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFilterExpression.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFilterExpression.java @@ -26,12 +26,17 @@ import java.util.Deque; import org.apache.hadoop.fs.shell.PathData; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.Timeout; import org.junit.Test; public class TestFilterExpression { private Expression expr; private FilterExpression test; + @Rule + public Timeout globalTimeout = new Timeout(10000); + @Before public void setup() { expr = mock(Expression.class); @@ -40,13 +45,13 @@ public class TestFilterExpression { } // test that the child expression is correctly set - @Test(timeout = 1000) + @Test public void expression() throws IOException { assertEquals(expr, test.expression); } // test that setOptions method is called - @Test(timeout = 1000) + @Test public void setOptions() throws IOException { FindOptions options = mock(FindOptions.class); test.setOptions(options); @@ -55,7 +60,7 @@ public class TestFilterExpression { } // test the apply method is called and the result returned - @Test(timeout = 1000) + @Test public void apply() throws IOException { PathData item = mock(PathData.class); when(expr.apply(item, -1)).thenReturn(Result.PASS).thenReturn(Result.FAIL); @@ -66,7 +71,7 @@ public class TestFilterExpression { } // test that the finish method is called - @Test(timeout = 1000) + @Test public void finish() throws IOException { test.finish(); verify(expr).finish(); @@ -74,7 +79,7 @@ public class TestFilterExpression { } // test that the getUsage method is called - @Test(timeout = 1000) + @Test public void getUsage() { String[] usage = new String[] { "Usage 1", "Usage 2", "Usage 3" }; when(expr.getUsage()).thenReturn(usage); @@ -84,7 +89,7 @@ public class TestFilterExpression { } // test that the getHelp method is called - @Test(timeout = 1000) + @Test public void getHelp() { String[] help = new String[] { "Help 1", "Help 2", "Help 3" }; when(expr.getHelp()).thenReturn(help); @@ -94,7 +99,7 @@ public class TestFilterExpression { } // test that the isAction method is called - @Test(timeout = 1000) + @Test public void isAction() { when(expr.isAction()).thenReturn(true).thenReturn(false); assertTrue(test.isAction()); @@ -104,7 +109,7 @@ public class TestFilterExpression { } // test that the isOperator method is called - @Test(timeout = 1000) + @Test public void isOperator() { when(expr.isAction()).thenReturn(true).thenReturn(false); assertTrue(test.isAction()); @@ -114,7 +119,7 @@ public class TestFilterExpression { } // test that the getPrecedence method is called - @Test(timeout = 1000) + @Test public void getPrecedence() { int precedence = 12345; when(expr.getPrecedence()).thenReturn(precedence); @@ -124,7 +129,7 @@ public class TestFilterExpression { } // test that the addChildren method is called - @Test(timeout = 1000) + @Test public void addChildren() { @SuppressWarnings("unchecked") Deque expressions = mock(Deque.class); @@ -134,7 +139,7 @@ public class TestFilterExpression { } // test that the addArguments method is called - @Test(timeout = 1000) + @Test public void addArguments() { @SuppressWarnings("unchecked") Deque args = mock(Deque.class); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFind.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFind.java index 8bfcec66146..716230aa4c4 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFind.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestFind.java @@ -39,11 +39,12 @@ import org.apache.hadoop.fs.shell.find.FindOptions; import org.apache.hadoop.fs.shell.find.Result; import org.junit.Before; import org.junit.Rule; -import org.junit.Test; import org.junit.rules.Timeout; +import org.junit.Test; import org.mockito.InOrder; public class TestFind { + @Rule public Timeout timeout = new Timeout(10000); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestIname.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestIname.java index 6e42fce58fe..c204322f1e9 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestIname.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestIname.java @@ -25,12 +25,17 @@ import java.io.IOException; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.shell.PathData; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.Timeout; import org.junit.Test; public class TestIname { private FileSystem mockFs; private Name.Iname name; + @Rule + public Timeout globalTimeout = new Timeout(10000); + @Before public void resetMock() throws IOException { mockFs = MockFileSystem.setup(); @@ -44,7 +49,7 @@ public class TestIname { } // test a matching name (same case) - @Test(timeout = 1000) + @Test public void applyMatch() throws IOException { setup("name"); PathData item = new PathData("/directory/path/name", mockFs.getConf()); @@ -52,7 +57,7 @@ public class TestIname { } // test a non-matching name - @Test(timeout = 1000) + @Test public void applyNotMatch() throws IOException { setup("name"); PathData item = new PathData("/directory/path/notname", mockFs.getConf()); @@ -60,7 +65,7 @@ public class TestIname { } // test a matching name (different case) - @Test(timeout = 1000) + @Test public void applyMixedCase() throws IOException { setup("name"); PathData item = new PathData("/directory/path/NaMe", mockFs.getConf()); @@ -68,7 +73,7 @@ public class TestIname { } // test a matching glob pattern (same case) - @Test(timeout = 1000) + @Test public void applyGlob() throws IOException { setup("n*e"); PathData item = new PathData("/directory/path/name", mockFs.getConf()); @@ -76,7 +81,7 @@ public class TestIname { } // test a matching glob pattern (different case) - @Test(timeout = 1000) + @Test public void applyGlobMixedCase() throws IOException { setup("n*e"); PathData item = new PathData("/directory/path/NaMe", mockFs.getConf()); @@ -84,7 +89,7 @@ public class TestIname { } // test a non-matching glob pattern - @Test(timeout = 1000) + @Test public void applyGlobNotMatch() throws IOException { setup("n*e"); PathData item = new PathData("/directory/path/notmatch", mockFs.getConf()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestName.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestName.java index 2c77fe14b72..81a405f4cfd 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestName.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestName.java @@ -25,12 +25,17 @@ import java.io.IOException; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.shell.PathData; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.Timeout; import org.junit.Test; public class TestName { private FileSystem mockFs; private Name name; + @Rule + public Timeout globalTimeout = new Timeout(10000); + @Before public void resetMock() throws IOException { mockFs = MockFileSystem.setup(); @@ -44,7 +49,7 @@ public class TestName { } // test a matching name - @Test(timeout = 1000) + @Test public void applyMatch() throws IOException { setup("name"); PathData item = new PathData("/directory/path/name", mockFs.getConf()); @@ -52,7 +57,7 @@ public class TestName { } // test a non-matching name - @Test(timeout = 1000) + @Test public void applyNotMatch() throws IOException { setup("name"); PathData item = new PathData("/directory/path/notname", mockFs.getConf()); @@ -60,7 +65,7 @@ public class TestName { } // test a different case name - @Test(timeout = 1000) + @Test public void applyMixedCase() throws IOException { setup("name"); PathData item = new PathData("/directory/path/NaMe", mockFs.getConf()); @@ -68,7 +73,7 @@ public class TestName { } // test a matching glob pattern - @Test(timeout = 1000) + @Test public void applyGlob() throws IOException { setup("n*e"); PathData item = new PathData("/directory/path/name", mockFs.getConf()); @@ -76,7 +81,7 @@ public class TestName { } // test a glob pattern with different case - @Test(timeout = 1000) + @Test public void applyGlobMixedCase() throws IOException { setup("n*e"); PathData item = new PathData("/directory/path/NaMe", mockFs.getConf()); @@ -84,7 +89,7 @@ public class TestName { } // test a non-matching glob pattern - @Test(timeout = 1000) + @Test public void applyGlobNotMatch() throws IOException { setup("n*e"); PathData item = new PathData("/directory/path/notmatch", mockFs.getConf()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint.java index 2d276650b96..a5cacc7defb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint.java @@ -23,23 +23,28 @@ import static org.mockito.Mockito.*; import java.io.IOException; import org.apache.hadoop.fs.shell.PathData; -import org.junit.Test; import java.io.PrintStream; import org.apache.hadoop.fs.FileSystem; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.Timeout; +import org.junit.Test; public class TestPrint { private FileSystem mockFs; + @Rule + public Timeout globalTimeout = new Timeout(10000); + @Before public void resetMock() throws IOException { mockFs = MockFileSystem.setup(); } // test the full path is printed to stdout - @Test(timeout = 1000) + @Test public void testPrint() throws IOException { Print print = new Print(); PrintStream out = mock(PrintStream.class); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint0.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint0.java index 3b89438d308..20c9bd69470 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint0.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestPrint0.java @@ -23,23 +23,28 @@ import static org.mockito.Mockito.*; import java.io.IOException; import org.apache.hadoop.fs.shell.PathData; -import org.junit.Test; import java.io.PrintStream; import org.apache.hadoop.fs.FileSystem; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.Timeout; +import org.junit.Test; public class TestPrint0 { private FileSystem mockFs; + @Rule + public Timeout globalTimeout = new Timeout(10000); + @Before public void resetMock() throws IOException { mockFs = MockFileSystem.setup(); } // test the full path is printed to stdout with a '\0' - @Test(timeout = 1000) + @Test public void testPrint() throws IOException { Print.Print0 print = new Print.Print0(); PrintStream out = mock(PrintStream.class); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestResult.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestResult.java index 1139220b94d..999ff598d77 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestResult.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/find/TestResult.java @@ -19,12 +19,17 @@ package org.apache.hadoop.fs.shell.find; import static org.junit.Assert.*; +import org.junit.Rule; +import org.junit.rules.Timeout; import org.junit.Test; public class TestResult { + @Rule + public Timeout globalTimeout = new Timeout(10000); + // test the PASS value - @Test(timeout = 1000) + @Test public void testPass() { Result result = Result.PASS; assertTrue(result.isPass()); @@ -32,7 +37,7 @@ public class TestResult { } // test the FAIL value - @Test(timeout = 1000) + @Test public void testFail() { Result result = Result.FAIL; assertFalse(result.isPass()); @@ -40,7 +45,7 @@ public class TestResult { } // test the STOP value - @Test(timeout = 1000) + @Test public void testStop() { Result result = Result.STOP; assertTrue(result.isPass()); @@ -48,7 +53,7 @@ public class TestResult { } // test combine method with two PASSes - @Test(timeout = 1000) + @Test public void combinePassPass() { Result result = Result.PASS.combine(Result.PASS); assertTrue(result.isPass()); @@ -56,7 +61,7 @@ public class TestResult { } // test the combine method with a PASS and a FAIL - @Test(timeout = 1000) + @Test public void combinePassFail() { Result result = Result.PASS.combine(Result.FAIL); assertFalse(result.isPass()); @@ -64,7 +69,7 @@ public class TestResult { } // test the combine method with a FAIL and a PASS - @Test(timeout = 1000) + @Test public void combineFailPass() { Result result = Result.FAIL.combine(Result.PASS); assertFalse(result.isPass()); @@ -72,7 +77,7 @@ public class TestResult { } // test the combine method with two FAILs - @Test(timeout = 1000) + @Test public void combineFailFail() { Result result = Result.FAIL.combine(Result.FAIL); assertFalse(result.isPass()); @@ -80,7 +85,7 @@ public class TestResult { } // test the combine method with a PASS and STOP - @Test(timeout = 1000) + @Test public void combinePassStop() { Result result = Result.PASS.combine(Result.STOP); assertTrue(result.isPass()); @@ -88,7 +93,7 @@ public class TestResult { } // test the combine method with a STOP and FAIL - @Test(timeout = 1000) + @Test public void combineStopFail() { Result result = Result.STOP.combine(Result.FAIL); assertFalse(result.isPass()); @@ -96,7 +101,7 @@ public class TestResult { } // test the combine method with a STOP and a PASS - @Test(timeout = 1000) + @Test public void combineStopPass() { Result result = Result.STOP.combine(Result.PASS); assertTrue(result.isPass()); @@ -104,7 +109,7 @@ public class TestResult { } // test the combine method with a FAIL and a STOP - @Test(timeout = 1000) + @Test public void combineFailStop() { Result result = Result.FAIL.combine(Result.STOP); assertFalse(result.isPass()); @@ -112,7 +117,7 @@ public class TestResult { } // test the negation of PASS - @Test(timeout = 1000) + @Test public void negatePass() { Result result = Result.PASS.negate(); assertFalse(result.isPass()); @@ -120,7 +125,7 @@ public class TestResult { } // test the negation of FAIL - @Test(timeout = 1000) + @Test public void negateFail() { Result result = Result.FAIL.negate(); assertTrue(result.isPass()); @@ -128,7 +133,7 @@ public class TestResult { } // test the negation of STOP - @Test(timeout = 1000) + @Test public void negateStop() { Result result = Result.STOP.negate(); assertFalse(result.isPass()); @@ -136,7 +141,7 @@ public class TestResult { } // test equals with two PASSes - @Test(timeout = 1000) + @Test public void equalsPass() { Result one = Result.PASS; Result two = Result.PASS.combine(Result.PASS); @@ -144,7 +149,7 @@ public class TestResult { } // test equals with two FAILs - @Test(timeout = 1000) + @Test public void equalsFail() { Result one = Result.FAIL; Result two = Result.FAIL.combine(Result.FAIL); @@ -152,7 +157,7 @@ public class TestResult { } // test equals with two STOPS - @Test(timeout = 1000) + @Test public void equalsStop() { Result one = Result.STOP; Result two = Result.STOP.combine(Result.STOP); @@ -160,7 +165,7 @@ public class TestResult { } // test all combinations of not equals - @Test(timeout = 1000) + @Test public void notEquals() { assertFalse(Result.PASS.equals(Result.FAIL)); assertFalse(Result.PASS.equals(Result.STOP));