You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2014/04/30 22:45:59 UTC

git commit: Fixing flaky unit test.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 9fab2a0cf -> d8301a6de


Fixing flaky unit test.

Reviewed at https://reviews.apache.org/r/20916/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/d8301a6d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/d8301a6d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/d8301a6d

Branch: refs/heads/master
Commit: d8301a6de060b5cc408f9d5ef0c8a908d2b3ed64
Parents: 9fab2a0
Author: Maxim Khutornenko <ma...@apache.org>
Authored: Wed Apr 30 13:45:34 2014 -0700
Committer: Maxim Khutornenko <ma...@apache.org>
Committed: Wed Apr 30 13:45:34 2014 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/base/AsyncUtilTest.java    | 34 ++++++++++++++------
 1 file changed, 24 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d8301a6d/src/test/java/org/apache/aurora/scheduler/base/AsyncUtilTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/base/AsyncUtilTest.java b/src/test/java/org/apache/aurora/scheduler/base/AsyncUtilTest.java
index 2e5875f..443fde3 100644
--- a/src/test/java/org/apache/aurora/scheduler/base/AsyncUtilTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/base/AsyncUtilTest.java
@@ -15,9 +15,8 @@
  */
 package org.apache.aurora.scheduler.base;
 
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
@@ -26,6 +25,7 @@ import java.util.logging.Logger;
 import com.twitter.common.testing.easymock.EasyMockTest;
 
 import org.easymock.EasyMock;
+import org.easymock.IAnswer;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,52 +36,66 @@ import static org.easymock.EasyMock.expectLastCall;
 public class AsyncUtilTest extends EasyMockTest {
   private Logger logger;
   private ScheduledThreadPoolExecutor executor;
+  private CountDownLatch latch;
 
   @Before
   public void setUp() {
     logger = createMock(Logger.class);
+    latch = new CountDownLatch(1);
     executor = AsyncUtil.singleThreadLoggingScheduledExecutor("Test-%d", logger);
   }
 
-  @Test(expected = ExecutionException.class)
+  @Test
   public void testScheduleLogging() throws Exception {
     logger.log(
         eq(Level.SEVERE),
         contains("Expected exception."),
         EasyMock.<ExecutionException>anyObject());
 
-    expectLastCall().times(1);
+    expectLastCall().andAnswer(new IAnswer<Object>() {
+      @Override
+      public Object answer() throws Throwable {
+        latch.countDown();
+        return null;
+      }
+    }).once();
 
     control.replay();
 
-    ScheduledFuture<?> future = executor.schedule(new Runnable() {
+    executor.schedule(new Runnable() {
       @Override
       public void run() {
         throw new IllegalArgumentException("Expected exception.");
       }
     }, 0, TimeUnit.MILLISECONDS);
 
-    future.get();
+    latch.await();
   }
 
-  @Test(expected = ExecutionException.class)
+  @Test
   public void testSubmitLogging() throws Exception {
     logger.log(
         eq(Level.SEVERE),
         contains("Expected exception."),
         EasyMock.<ExecutionException>anyObject());
 
-    expectLastCall().times(1);
+    expectLastCall().andAnswer(new IAnswer<Object>() {
+      @Override
+      public Object answer() throws Throwable {
+        latch.countDown();
+        return null;
+      }
+    }).once();
 
     control.replay();
 
-    Future<?> future = executor.submit(new Runnable() {
+    executor.submit(new Runnable() {
       @Override
       public void run() {
         throw new IllegalArgumentException("Expected exception.");
       }
     });
 
-    future.get();
+    latch.await();
   }
 }