Revision: 1238
Author: dhanji
Date: Wed Sep 15 22:53:17 2010
Log: Fixed a small bug in the async service multi-threaded test.
http://code.google.com/p/google-guice/source/detail?r=1238

Modified:
/trunk/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java

=======================================
--- /trunk/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java Wed Sep 15 22:32:53 2010 +++ /trunk/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java Wed Sep 15 22:53:17 2010
@@ -17,29 +17,34 @@
public final void testAsyncServiceLifecycle() throws InterruptedException {
     ExecutorService executor = Executors.newSingleThreadExecutor();

-    final CountDownLatch latch = new CountDownLatch(2);
+    final CountDownLatch startLatch = new CountDownLatch(1);
+    final CountDownLatch stopLatch = new CountDownLatch(1);
     AsyncService service = new AsyncService(executor) {
       @Override protected void onStart() {
-        assertEquals(2, latch.getCount());
-
-        latch.countDown();
+        assertEquals(1, startLatch.getCount());
+        assertEquals(1, stopLatch.getCount());
+
+        startLatch.countDown();
       }

       @Override protected void onStop() {
-        assertEquals(1, latch.getCount());
-
-        latch.countDown();
+        assertEquals(0, startLatch.getCount());
+        assertEquals(1, stopLatch.getCount());
+
+        stopLatch.countDown();
       }
     };

     service.start();
-    latch.await(2, TimeUnit.SECONDS);
+    // This should not pass!
+    assertTrue(startLatch.await(2, TimeUnit.SECONDS));

     service.stop();
-    latch.await(2, TimeUnit.SECONDS);
+    assertTrue(stopLatch.await(2, TimeUnit.SECONDS));

     executor.shutdown();
-    assertEquals(0, latch.getCount());
+    assertEquals(0, startLatch.getCount());
+    assertEquals(0, stopLatch.getCount());
   }

   public final void testAsyncServiceBlockingLifecycle()

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to