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

Comparing jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java (file contents):
Revision 1.15 by jsr166, Sat Nov 21 20:17:40 2009 UTC vs.
Revision 1.17 by jsr166, Tue Dec 1 22:51:44 2009 UTC

# Line 529 | Line 529 | public class ThreadPoolExecutorSubclassT
529              try {
530                  l = p1.shutdownNow();
531              } catch (SecurityException ok) { return; }
532
532          }
533          assertTrue(p1.isShutdown());
534          assertTrue(l.size() <= 4);
# Line 1169 | Line 1168 | public class ThreadPoolExecutorSubclassT
1168       * invokeAny(c) throws NPE if c has null elements
1169       */
1170      public void testInvokeAny3() throws Exception {
1171 <        final CountDownLatch latch = new CountDownLatch(1);
1171 >        CountDownLatch latch = new CountDownLatch(1);
1172          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1173 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1174 +        l.add(latchAwaitingStringTask(latch));
1175 +        l.add(null);
1176          try {
1175            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1176            l.add(new Callable<String>() {
1177                      public String call() {
1178                          try {
1179                              latch.await();
1180                          } catch (InterruptedException ok) {}
1181                          return TEST_STRING;
1182                      }});
1183            l.add(null);
1177              e.invokeAny(l);
1178              shouldThrow();
1179          } catch (NullPointerException success) {
# Line 1195 | Line 1188 | public class ThreadPoolExecutorSubclassT
1188       */
1189      public void testInvokeAny4() throws Exception {
1190          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1191 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1192 +        l.add(new NPETask());
1193          try {
1199            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1200            l.add(new NPETask());
1194              e.invokeAny(l);
1195              shouldThrow();
1196          } catch (ExecutionException success) {
# Line 1213 | Line 1206 | public class ThreadPoolExecutorSubclassT
1206      public void testInvokeAny5() throws Exception {
1207          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1208          try {
1209 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1209 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1210              l.add(new StringTask());
1211              l.add(new StringTask());
1212              String result = e.invokeAny(l);
# Line 1255 | Line 1248 | public class ThreadPoolExecutorSubclassT
1248       */
1249      public void testInvokeAll3() throws Exception {
1250          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1251 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1252 +        l.add(new StringTask());
1253 +        l.add(null);
1254          try {
1259            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1260            l.add(new StringTask());
1261            l.add(null);
1255              e.invokeAll(l);
1256              shouldThrow();
1257          } catch (NullPointerException success) {
# Line 1272 | Line 1265 | public class ThreadPoolExecutorSubclassT
1265       */
1266      public void testInvokeAll4() throws Exception {
1267          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1268 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1269 +        l.add(new NPETask());
1270 +        List<Future<String>> futures = e.invokeAll(l);
1271 +        assertEquals(1, futures.size());
1272          try {
1273 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1277 <            l.add(new NPETask());
1278 <            List<Future<String>> result = e.invokeAll(l);
1279 <            assertEquals(1, result.size());
1280 <            for (Future<String> future : result)
1281 <                future.get();
1273 >            futures.get(0).get();
1274              shouldThrow();
1275          } catch (ExecutionException success) {
1276              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1293 | Line 1285 | public class ThreadPoolExecutorSubclassT
1285      public void testInvokeAll5() throws Exception {
1286          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1287          try {
1288 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1288 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1289              l.add(new StringTask());
1290              l.add(new StringTask());
1291 <            List<Future<String>> result = e.invokeAll(l);
1292 <            assertEquals(2, result.size());
1293 <            for (Future<String> future : result)
1291 >            List<Future<String>> futures = e.invokeAll(l);
1292 >            assertEquals(2, futures.size());
1293 >            for (Future<String> future : futures)
1294                  assertSame(TEST_STRING, future.get());
1295          } finally {
1296              joinPool(e);
# Line 1326 | Line 1318 | public class ThreadPoolExecutorSubclassT
1318       */
1319      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
1320          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1321 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1322 +        l.add(new StringTask());
1323          try {
1330            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1331            l.add(new StringTask());
1324              e.invokeAny(l, MEDIUM_DELAY_MS, null);
1325              shouldThrow();
1326          } catch (NullPointerException success) {
# Line 1355 | Line 1347 | public class ThreadPoolExecutorSubclassT
1347       * timed invokeAny(c) throws NPE if c has null elements
1348       */
1349      public void testTimedInvokeAny3() throws Exception {
1350 <        final CountDownLatch latch = new CountDownLatch(1);
1350 >        CountDownLatch latch = new CountDownLatch(1);
1351          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1352 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1353 +        l.add(latchAwaitingStringTask(latch));
1354 +        l.add(null);
1355          try {
1361            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1362            l.add(new Callable<String>() {
1363                      public String call() {
1364                          try {
1365                              latch.await();
1366                          } catch (InterruptedException ok) {}
1367                          return TEST_STRING;
1368                      }});
1369            l.add(null);
1356              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1357              shouldThrow();
1358          } catch (NullPointerException success) {
# Line 1381 | Line 1367 | public class ThreadPoolExecutorSubclassT
1367       */
1368      public void testTimedInvokeAny4() throws Exception {
1369          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1370 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1371 +        l.add(new NPETask());
1372          try {
1385            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1386            l.add(new NPETask());
1373              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
1374              shouldThrow();
1375          } catch (ExecutionException success) {
# Line 1399 | Line 1385 | public class ThreadPoolExecutorSubclassT
1385      public void testTimedInvokeAny5() throws Exception {
1386          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1387          try {
1388 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1388 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1389              l.add(new StringTask());
1390              l.add(new StringTask());
1391              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 1428 | Line 1414 | public class ThreadPoolExecutorSubclassT
1414       */
1415      public void testTimedInvokeAllNullTimeUnit() throws Exception {
1416          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1417 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1418 +        l.add(new StringTask());
1419          try {
1432            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1433            l.add(new StringTask());
1420              e.invokeAll(l, MEDIUM_DELAY_MS, null);
1421              shouldThrow();
1422          } catch (NullPointerException success) {
# Line 1457 | Line 1443 | public class ThreadPoolExecutorSubclassT
1443       */
1444      public void testTimedInvokeAll3() throws Exception {
1445          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1446 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1447 +        l.add(new StringTask());
1448 +        l.add(null);
1449          try {
1461            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1462            l.add(new StringTask());
1463            l.add(null);
1450              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1451              shouldThrow();
1452          } catch (NullPointerException success) {
# Line 1474 | Line 1460 | public class ThreadPoolExecutorSubclassT
1460       */
1461      public void testTimedInvokeAll4() throws Exception {
1462          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1463 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
1464 +        l.add(new NPETask());
1465 +        List<Future<String>> futures =
1466 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1467 +        assertEquals(1, futures.size());
1468          try {
1469 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1479 <            l.add(new NPETask());
1480 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1481 <            assertEquals(1, result.size());
1482 <            for (Future<String> future : result)
1483 <                future.get();
1469 >            futures.get(0).get();
1470              shouldThrow();
1471          } catch (ExecutionException success) {
1472              assertTrue(success.getCause() instanceof NullPointerException);
# Line 1495 | Line 1481 | public class ThreadPoolExecutorSubclassT
1481      public void testTimedInvokeAll5() throws Exception {
1482          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1483          try {
1484 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1484 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1485              l.add(new StringTask());
1486              l.add(new StringTask());
1487 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1488 <            assertEquals(2, result.size());
1489 <            for (Future<String> future : result)
1487 >            List<Future<String>> futures =
1488 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
1489 >            assertEquals(2, futures.size());
1490 >            for (Future<String> future : futures)
1491                  assertSame(TEST_STRING, future.get());
1492          } finally {
1493              joinPool(e);
# Line 1513 | Line 1500 | public class ThreadPoolExecutorSubclassT
1500      public void testTimedInvokeAll6() throws Exception {
1501          ExecutorService e = new CustomTPE(2, 2, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10));
1502          try {
1503 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
1503 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
1504              l.add(new StringTask());
1505              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
1506              l.add(new StringTask());
1507 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1508 <            assertEquals(3, result.size());
1509 <            Iterator<Future<String>> it = result.iterator();
1507 >            List<Future<String>> futures =
1508 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
1509 >            assertEquals(3, futures.size());
1510 >            Iterator<Future<String>> it = futures.iterator();
1511              Future<String> f1 = it.next();
1512              Future<String> f2 = it.next();
1513              Future<String> f3 = it.next();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines