Repository: oozie
Updated Branches:
  refs/heads/master 26db6712b -> 71b668fbe


OOZIE-3242 Flaky test TestXCommand#testXCommandLifecycleLockingFailingToLock 
(pbacsko via gezapeti)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/71b668fb
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/71b668fb
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/71b668fb

Branch: refs/heads/master
Commit: 71b668fbe5c538b1651adf9168f9ffc440ad4332
Parents: 26db671
Author: Gezapeti Cseh <[email protected]>
Authored: Wed May 16 22:41:32 2018 +0200
Committer: Gezapeti Cseh <[email protected]>
Committed: Wed May 16 22:41:32 2018 +0200

----------------------------------------------------------------------
 .../org/apache/oozie/command/TestXCommand.java  | 40 ++++++++++++++------
 release-log.txt                                 |  1 +
 2 files changed, 29 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/71b668fb/core/src/test/java/org/apache/oozie/command/TestXCommand.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/command/TestXCommand.java 
b/core/src/test/java/org/apache/oozie/command/TestXCommand.java
index 434adf2..c93e484 100644
--- a/core/src/test/java/org/apache/oozie/command/TestXCommand.java
+++ b/core/src/test/java/org/apache/oozie/command/TestXCommand.java
@@ -18,6 +18,9 @@
 
 package org.apache.oozie.command;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.oozie.ErrorCode;
 import org.apache.oozie.service.MemoryLocksService;
 import org.apache.oozie.service.Services;
@@ -39,7 +42,7 @@ public class TestXCommand extends XTestCase {
         super.tearDown();
     }
 
-    public static class AXCommand extends XCommand {
+    public static class AXCommand extends XCommand<Void> {
         private boolean lockRequired;
         public boolean eagerLoadState;
         public boolean eagerVerifyPrecondition;
@@ -133,7 +136,7 @@ public class TestXCommand extends XTestCase {
         }
 
         @Override
-        protected Object execute() throws CommandException {
+        protected Void execute() throws CommandException {
             assertTrue(eagerLoadState);
             assertTrue(eagerVerifyPrecondition);
             assertTrue(loadState);
@@ -153,7 +156,7 @@ public class TestXCommand extends XTestCase {
     }
 
     public void testXCommandGetters() throws Exception {
-        XCommand command = new AXCommand(false);
+        XCommand<Void> command = new AXCommand(false);
         assertEquals("name", command.getName());
         assertEquals("type", command.getType());
         assertEquals(1, command.getPriority());
@@ -162,12 +165,13 @@ public class TestXCommand extends XTestCase {
     }
 
     public void testXCommandLifecycleNotLocking() throws Exception {
-        Thread t = new LockGetter();
+        LockGetter t = new LockGetter();
         t.start();
+        t.awaitLockAcquired();
         AXCommand command = new AXCommand(false);
         command.call();
         assertTrue(command.execute);
-        t.interrupt();
+        assertTrue("Lock acquisition failed in the test thread", 
t.isLockSuccessful());
     }
 
     public void testXCommandLifecycleLocking() throws Exception {
@@ -177,9 +181,10 @@ public class TestXCommand extends XTestCase {
     }
 
     public void testXCommandLifecycleLockingFailingToLock() throws Exception {
-        Thread t = new LockGetter();
+        LockGetter t = new LockGetter();
         t.start();
-        sleep(150);
+        t.awaitLockAcquired();
+
         AXCommand command = new AXCommand(true);
         try {
             command.call();
@@ -189,7 +194,8 @@ public class TestXCommand extends XTestCase {
         }
         catch (Exception ex) {
         }
-        t.interrupt();
+
+        assertTrue("Lock acquisition failed in the test thread", 
t.isLockSuccessful());
     }
 
     public void testXCommandeagerVerifyPreconditionFailing() throws Exception {
@@ -231,22 +237,32 @@ public class TestXCommand extends XTestCase {
     }
 
     private static class LockGetter extends Thread {
+        private CountDownLatch lockAcquired = new CountDownLatch(1);
+        private volatile boolean lockSuccessful = false;
 
         @Override
         public void run() {
             try {
                 LockToken lock = 
Services.get().get(MemoryLocksService.class).getWriteLock("key", 1);
-                if (lock == null) {
-                    fail();
+                if (lock != null) {
+                    lockSuccessful = true;
                 }
-                sleep(150);
+                lockAcquired.countDown();
             }
             catch (InterruptedException ex) {
                 // NOP
             }
             catch (Exception ex) {
-                fail();
+                lockSuccessful = false;
             }
         }
+
+        public void awaitLockAcquired() throws InterruptedException {
+            lockAcquired.await(10, TimeUnit.SECONDS);
+        }
+
+        public boolean isLockSuccessful() {
+            return lockSuccessful;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/oozie/blob/71b668fb/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 3760dbf..7f8d651 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 5.1.0 release (trunk - unreleased)
 
+OOZIE-3242 Flaky test TestXCommand#testXCommandLifecycleLockingFailingToLock 
(pbacsko via gezapeti)
 OOZIE-3226 [tools] TestOozieDBCLI#testOozieDBCLI() fails (pbacsko via gezapeti)
 OOZIE-2968 TestJavaActionExecutor.testCredentialsSkip fails intermittently 
(pbacsko via gezapeti)
 OOZIE-3228 [Spark action] Can't load properties from spark-defaults.conf 
(andras.piros)

Reply via email to