ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ThreadPoolExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ThreadPoolExecutorTest.java (file contents):
Revision 1.32 by jsr166, Tue Dec 1 09:48:12 2009 UTC vs.
Revision 1.33 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 1037 | Line 1037 | public class ThreadPoolExecutorTest exte
1037       * invokeAny(c) throws NPE if c has null elements
1038       */
1039      public void testInvokeAny3() throws Exception {
1040 <        final CountDownLatch latch = new CountDownLatch(1);
1040 >        CountDownLatch latch = new CountDownLatch(1);
1041          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1042 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1043 +        l.add(latchAwaitingStringTask(latch));
1044 +        l.add(null);
1045          try {
1043            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1044            l.add(new Callable<String>() {
1045                      public String call() {
1046                          try {
1047                              latch.await();
1048                          } catch (InterruptedException ok) {}
1049                          return TEST_STRING;
1050                      }});
1051            l.add(null);
1046              e.invokeAny(l);
1047              shouldThrow();
1048          } catch (NullPointerException success) {
# Line 1063 | Line 1057 | public class ThreadPoolExecutorTest exte
1057       */
1058      public void testInvokeAny4() throws Exception {
1059          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1060 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1061 +        l.add(new NPETask());
1062          try {
1067            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1068            l.add(new NPETask());
1063              e.invokeAny(l);
1064              shouldThrow();
1065          } catch (ExecutionException success) {
# Line 1081 | Line 1075 | public class ThreadPoolExecutorTest exte
1075      public void testInvokeAny5() throws Exception {
1076          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1077          try {
1078 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1078 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1079              l.add(new StringTask());
1080              l.add(new StringTask());
1081              String result = e.invokeAny(l);
# Line 1123 | Line 1117 | public class ThreadPoolExecutorTest exte
1117       */
1118      public void testInvokeAll3() throws Exception {
1119          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1120 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1121 +        l.add(new StringTask());
1122 +        l.add(null);
1123          try {
1127            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1128            l.add(new StringTask());
1129            l.add(null);
1124              e.invokeAll(l);
1125              shouldThrow();
1126          } catch (NullPointerException success) {
# Line 1141 | Line 1135 | public class ThreadPoolExecutorTest exte
1135      public void testInvokeAll4() throws Exception {
1136          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1137          try {
1138 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1138 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1139              l.add(new NPETask());
1140 <            List<Future<String>> result = e.invokeAll(l);
1141 <            assertEquals(1, result.size());
1142 <            for (Future<String> future : result) {
1143 <                try {
1144 <                    future.get();
1145 <                    shouldThrow();
1146 <                } catch (ExecutionException success) {
1153 <                    Throwable cause = success.getCause();
1154 <                    assertTrue(cause instanceof NullPointerException);
1155 <                }
1140 >            List<Future<String>> futures = e.invokeAll(l);
1141 >            assertEquals(1, futures.size());
1142 >            try {
1143 >                futures.get(0).get();
1144 >                shouldThrow();
1145 >            } catch (ExecutionException success) {
1146 >                assertTrue(success.getCause() instanceof NullPointerException);
1147              }
1148          } finally {
1149              joinPool(e);
# Line 1165 | Line 1156 | public class ThreadPoolExecutorTest exte
1156      public void testInvokeAll5() throws Exception {
1157          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1158          try {
1159 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1159 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1160              l.add(new StringTask());
1161              l.add(new StringTask());
1162 <            List<Future<String>> result = e.invokeAll(l);
1163 <            assertEquals(2, result.size());
1164 <            for (Future<String> future : result)
1162 >            List<Future<String>> futures = e.invokeAll(l);
1163 >            assertEquals(2, futures.size());
1164 >            for (Future<String> future : futures)
1165                  assertSame(TEST_STRING, future.get());
1166          } finally {
1167              joinPool(e);
# Line 1198 | Line 1189 | public class ThreadPoolExecutorTest exte
1189       */
1190      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1191          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1192 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1193 +        l.add(new StringTask());
1194          try {
1202            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1203            l.add(new StringTask());
1195              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1196              shouldThrow();
1197          } catch (NullPointerException success) {
# Line 1227 | Line 1218 | public class ThreadPoolExecutorTest exte
1218       * timed invokeAny(c) throws NPE if c has null elements
1219       */
1220      public void testTimedInvokeAny3() throws Exception {
1221 <        final CountDownLatch latch = new CountDownLatch(1);
1221 >        CountDownLatch latch = new CountDownLatch(1);
1222          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1223 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1224 +        l.add(latchAwaitingStringTask(latch));
1225 +        l.add(null);
1226          try {
1233            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1234            l.add(new Callable<String>() {
1235                      public String call() {
1236                          try {
1237                              latch.await();
1238                          } catch (InterruptedException ok) {}
1239                          return TEST_STRING;
1240                      }});
1241            l.add(null);
1227              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1228              shouldThrow();
1229          } catch (NullPointerException success) {
# Line 1253 | Line 1238 | public class ThreadPoolExecutorTest exte
1238       */
1239      public void testTimedInvokeAny4() throws Exception {
1240          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1241 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1242 +        l.add(new NPETask());
1243          try {
1257            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1258            l.add(new NPETask());
1244              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1245              shouldThrow();
1246          } catch (ExecutionException success) {
# Line 1271 | Line 1256 | public class ThreadPoolExecutorTest exte
1256      public void testTimedInvokeAny5() throws Exception {
1257          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1258          try {
1259 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1259 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1260              l.add(new StringTask());
1261              l.add(new StringTask());
1262              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 1300 | Line 1285 | public class ThreadPoolExecutorTest exte
1285       */
1286      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1287          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1288 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1289 +        l.add(new StringTask());
1290          try {
1304            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1305            l.add(new StringTask());
1291              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1292              shouldThrow();
1293          } catch (NullPointerException success) {
# Line 1329 | Line 1314 | public class ThreadPoolExecutorTest exte
1314       */
1315      public void testTimedInvokeAll3() throws Exception {
1316          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1317 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1318 +        l.add(new StringTask());
1319 +        l.add(null);
1320          try {
1333            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1334            l.add(new StringTask());
1335            l.add(null);
1321              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1322              shouldThrow();
1323          } catch (NullPointerException success) {
# Line 1346 | Line 1331 | public class ThreadPoolExecutorTest exte
1331       */
1332      public void testTimedInvokeAll4() throws Exception {
1333          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1334 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1335 +        l.add(new NPETask());
1336 +        List<Future<String>> futures =
1337 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1338 +        assertEquals(1, futures.size());
1339          try {
1340 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1351 <            l.add(new NPETask());
1352 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1353 <            assertEquals(1, result.size());
1354 <            for (Future<String> future : result)
1355 <                future.get();
1340 >            futures.get(0).get();
1341              shouldThrow();
1342          } catch (ExecutionException success) {
1343              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1367 | Line 1352 | public class ThreadPoolExecutorTest exte
1352      public void testTimedInvokeAll5() throws Exception {
1353          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1354          try {
1355 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1355 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1356              l.add(new StringTask());
1357              l.add(new StringTask());
1358 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1359 <            assertEquals(2, result.size());
1360 <            for (Iterator<Future<String>> it = result.iterator(); it.hasNext();)
1361 <                assertSame(TEST_STRING, it.next().get());
1358 >            List<Future<String>> futures =
1359 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1360 >            assertEquals(2, futures.size());
1361 >            for (Future<String> future : futures)
1362 >                assertSame(TEST_STRING, future.get());
1363          } finally {
1364              joinPool(e);
1365          }
# Line 1385 | Line 1371 | public class ThreadPoolExecutorTest exte
1371      public void testTimedInvokeAll6() throws Exception {
1372          ExecutorService e = new ThreadPoolExecutor(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1373          try {
1374 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1374 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1375              l.add(new StringTask());
1376              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1377              l.add(new StringTask());
1378 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1379 <            assertEquals(3, result.size());
1380 <            Iterator<Future<String>> it = result.iterator();
1378 >            List<Future<String>> futures =
1379 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1380 >            assertEquals(3, futures.size());
1381 >            Iterator<Future<String>> it = futures.iterator();
1382              Future<String> f1 = it.next();
1383              Future<String> f2 = it.next();
1384              Future<String> f3 = it.next();
# Line 1412 | Line 1399 | public class ThreadPoolExecutorTest exte
1399      public void testFailingThreadFactory() throws InterruptedException {
1400          ExecutorService e = new ThreadPoolExecutor(100, 100, LONG_DELAY_MS, MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new FailingThreadFactory());
1401          try {
1402 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1402 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1403              for (int k = 0; k < 100; ++k) {
1404                  e.execute(new NoOpRunnable());
1405              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines