Author: etnu
Date: Wed Nov 26 10:55:53 2008
New Revision: 720943

URL: http://svn.apache.org/viewvc?rev=720943&view=rev
Log:
Fixed thread accounting bug in one of the test cases.


Modified:
    
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/ConcurrentPreloaderServiceTest.java

Modified: 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/ConcurrentPreloaderServiceTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/ConcurrentPreloaderServiceTest.java?rev=720943&r1=720942&r2=720943&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/ConcurrentPreloaderServiceTest.java
 (original)
+++ 
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/ConcurrentPreloaderServiceTest.java
 Wed Nov 26 10:55:53 2008
@@ -18,9 +18,9 @@
 package org.apache.shindig.gadgets.preload;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import org.apache.shindig.common.testing.TestExecutorService;
 import org.apache.shindig.gadgets.GadgetContext;
@@ -99,20 +99,19 @@
 
     service.preload(null, null);
 
-    TestPreloadCallable first = 
(TestPreloadCallable)preloader.tasks.get(PRELOAD_STRING_KEY);
-    TestPreloadCallable second = 
(TestPreloadCallable)preloader.tasks.get(PRELOAD_NUMERIC_KEY);
-    TestPreloadCallable third = 
(TestPreloadCallable)preloader.tasks.get(PRELOAD_MAP_KEY);
-
-    assertFalse("Multiple preloads executed in the same thread",
-        first.executedThread == second.executedThread ||
-        first.executedThread == third.executedThread ||
-        second.executedThread == third.executedThread);
-
-    Thread current = Thread.currentThread();
-    assertTrue("No preloads executed in the current thread.",
-        current == first.executedThread ||
-        current == second.executedThread ||
-        current == third.executedThread);
+    TestPreloadCallable ranInSameThread = null;
+    for (Callable<PreloadedData> callable : preloader.tasks.values()) {
+      TestPreloadCallable preloadCallable = (TestPreloadCallable)callable;
+      if (ranInSameThread != null) {
+        fail("More than one request ran in the current thread.");
+      }
+
+      if (preloadCallable.executedThread == Thread.currentThread()) {
+        ranInSameThread = preloadCallable;
+      }
+    }
+
+    assertNotNull("No preloads executed in the current thread. ", 
ranInSameThread);
   }
 
   @Test
@@ -125,10 +124,10 @@
 
     service.preload(null, null);
 
-    TestPreloadCallable first = 
(TestPreloadCallable)preloader.tasks.get(PRELOAD_STRING_KEY);
+    TestPreloadCallable callable = 
(TestPreloadCallable)preloader.tasks.get(PRELOAD_STRING_KEY);
 
     assertSame("Single request not run in current thread",
-        Thread.currentThread(), first.executedThread);
+        Thread.currentThread(), callable.executedThread);
   }
 
   @Test(expected = PreloadException.class)


Reply via email to