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.91 by jsr166, Sun Oct 4 03:27:46 2015 UTC vs.
Revision 1.96 by jsr166, Sun Oct 4 06:39:13 2015 UTC

# Line 1070 | Line 1070 | public class ThreadPoolExecutorTest exte
1070       * submit(runnable) throws RejectedExecutionException if saturated.
1071       */
1072      public void testSaturatedSubmitRunnable() {
1073 <        ThreadPoolExecutor p =
1073 >        final ThreadPoolExecutor p =
1074              new ThreadPoolExecutor(1, 1,
1075                                     LONG_DELAY_MS, MILLISECONDS,
1076                                     new ArrayBlockingQueue<Runnable>(1));
# Line 1099 | Line 1099 | public class ThreadPoolExecutorTest exte
1099       * submit(callable) throws RejectedExecutionException if saturated.
1100       */
1101      public void testSaturatedSubmitCallable() {
1102 <        ThreadPoolExecutor p =
1102 >        final ThreadPoolExecutor p =
1103              new ThreadPoolExecutor(1, 1,
1104                                     LONG_DELAY_MS, MILLISECONDS,
1105                                     new ArrayBlockingQueue<Runnable>(1));
# Line 1184 | Line 1184 | public class ThreadPoolExecutorTest exte
1184       * executor using DiscardOldestPolicy drops oldest task if saturated.
1185       */
1186      public void testSaturatedExecute4() {
1187 <        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
1187 >        final CountDownLatch done = new CountDownLatch(1);
1188 >        LatchAwaiter r1 = awaiter(done);
1189 >        LatchAwaiter r2 = awaiter(done);
1190 >        LatchAwaiter r3 = awaiter(done);
1191          final ThreadPoolExecutor p =
1192              new ThreadPoolExecutor(1, 1,
1193                                     LONG_DELAY_MS, MILLISECONDS,
1194                                     new ArrayBlockingQueue<Runnable>(1),
1195 <                                   h);
1196 <        try {
1197 <            p.execute(new TrackedLongRunnable());
1198 <            TrackedLongRunnable r2 = new TrackedLongRunnable();
1195 >                                   new ThreadPoolExecutor.DiscardOldestPolicy());
1196 >        try (PoolCleaner cleaner = cleaner(p)) {
1197 >            assertEquals(LatchAwaiter.NEW, r1.state);
1198 >            assertEquals(LatchAwaiter.NEW, r2.state);
1199 >            assertEquals(LatchAwaiter.NEW, r3.state);
1200 >            p.execute(r1);
1201              p.execute(r2);
1202              assertTrue(p.getQueue().contains(r2));
1198            TrackedNoOpRunnable r3 = new TrackedNoOpRunnable();
1203              p.execute(r3);
1204              assertFalse(p.getQueue().contains(r2));
1205              assertTrue(p.getQueue().contains(r3));
1206 <            try { p.shutdownNow(); } catch (SecurityException ok) { return; }
1203 <        } finally {
1204 <            joinPool(p);
1206 >            done.countDown();
1207          }
1208 +        assertEquals(LatchAwaiter.DONE, r1.state);
1209 +        assertEquals(LatchAwaiter.NEW, r2.state);
1210 +        assertEquals(LatchAwaiter.DONE, r3.state);
1211      }
1212  
1213      /**
1214       * execute throws RejectedExecutionException if shutdown
1215       */
1216      public void testRejectedExecutionExceptionOnShutdown() {
1217 <        ThreadPoolExecutor p =
1217 >        final ThreadPoolExecutor p =
1218              new ThreadPoolExecutor(1, 1,
1219                                     LONG_DELAY_MS, MILLISECONDS,
1220                                     new ArrayBlockingQueue<Runnable>(1));
1221          try { p.shutdown(); } catch (SecurityException ok) { return; }
1222 <        try {
1223 <            p.execute(new NoOpRunnable());
1224 <            shouldThrow();
1225 <        } catch (RejectedExecutionException success) {}
1226 <
1227 <        joinPool(p);
1222 >        try (PoolCleaner cleaner = cleaner(p)) {
1223 >            try {
1224 >                p.execute(new NoOpRunnable());
1225 >                shouldThrow();
1226 >            } catch (RejectedExecutionException success) {}
1227 >        }
1228      }
1229  
1230      /**
# Line 1233 | Line 1238 | public class ThreadPoolExecutorTest exte
1238                                     new ArrayBlockingQueue<Runnable>(1), h);
1239  
1240          try { p.shutdown(); } catch (SecurityException ok) { return; }
1241 <        try {
1241 >        try (PoolCleaner cleaner = cleaner(p)) {
1242              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1243              p.execute(r);
1244              assertFalse(r.done);
1240        } finally {
1241            joinPool(p);
1245          }
1246      }
1247  
# Line 1246 | Line 1249 | public class ThreadPoolExecutorTest exte
1249       * execute using DiscardPolicy drops task on shutdown
1250       */
1251      public void testDiscardOnShutdown() {
1252 <        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
1250 <        ThreadPoolExecutor p =
1252 >        final ThreadPoolExecutor p =
1253              new ThreadPoolExecutor(1, 1,
1254                                     LONG_DELAY_MS, MILLISECONDS,
1255                                     new ArrayBlockingQueue<Runnable>(1),
1256 <                                   h);
1256 >                                   new ThreadPoolExecutor.DiscardPolicy());
1257  
1258          try { p.shutdown(); } catch (SecurityException ok) { return; }
1259 <        try {
1259 >        try (PoolCleaner cleaner = cleaner(p)) {
1260              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1261              p.execute(r);
1262              assertFalse(r.done);
1261        } finally {
1262            joinPool(p);
1263          }
1264      }
1265  
# Line 1267 | Line 1267 | public class ThreadPoolExecutorTest exte
1267       * execute using DiscardOldestPolicy drops task on shutdown
1268       */
1269      public void testDiscardOldestOnShutdown() {
1270 <        RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();
1271 <        ThreadPoolExecutor p =
1270 >        final ThreadPoolExecutor p =
1271              new ThreadPoolExecutor(1, 1,
1272                                     LONG_DELAY_MS, MILLISECONDS,
1273                                     new ArrayBlockingQueue<Runnable>(1),
1274 <                                   h);
1274 >                                   new ThreadPoolExecutor.DiscardOldestPolicy());
1275  
1276          try { p.shutdown(); } catch (SecurityException ok) { return; }
1277 <        try {
1277 >        try (PoolCleaner cleaner = cleaner(p)) {
1278              TrackedNoOpRunnable r = new TrackedNoOpRunnable();
1279              p.execute(r);
1280              assertFalse(r.done);
1282        } finally {
1283            joinPool(p);
1281          }
1282      }
1283  
# Line 1288 | Line 1285 | public class ThreadPoolExecutorTest exte
1285       * execute(null) throws NPE
1286       */
1287      public void testExecuteNull() {
1288 <        ThreadPoolExecutor p =
1289 <            new ThreadPoolExecutor(1, 2, 1L, SECONDS,
1288 >        final ThreadPoolExecutor p =
1289 >            new ThreadPoolExecutor(1, 2,
1290 >                                   1L, SECONDS,
1291                                     new ArrayBlockingQueue<Runnable>(10));
1292 <        try {
1293 <            p.execute(null);
1294 <            shouldThrow();
1295 <        } catch (NullPointerException success) {}
1296 <
1297 <        joinPool(p);
1292 >        try (PoolCleaner cleaner = cleaner(p)) {
1293 >            try {
1294 >                p.execute(null);
1295 >                shouldThrow();
1296 >            } catch (NullPointerException success) {}
1297 >        }
1298      }
1299  
1300      /**
1301       * setCorePoolSize of negative value throws IllegalArgumentException
1302       */
1303      public void testCorePoolSizeIllegalArgumentException() {
1304 <        ThreadPoolExecutor p =
1304 >        final ThreadPoolExecutor p =
1305              new ThreadPoolExecutor(1, 2,
1306                                     LONG_DELAY_MS, MILLISECONDS,
1307                                     new ArrayBlockingQueue<Runnable>(10));
# Line 1322 | Line 1320 | public class ThreadPoolExecutorTest exte
1320       * given a value less the core pool size
1321       */
1322      public void testMaximumPoolSizeIllegalArgumentException() {
1323 <        ThreadPoolExecutor p =
1323 >        final ThreadPoolExecutor p =
1324              new ThreadPoolExecutor(2, 3,
1325                                     LONG_DELAY_MS, MILLISECONDS,
1326                                     new ArrayBlockingQueue<Runnable>(10));
# Line 1341 | Line 1339 | public class ThreadPoolExecutorTest exte
1339       * if given a negative value
1340       */
1341      public void testMaximumPoolSizeIllegalArgumentException2() {
1342 <        ThreadPoolExecutor p =
1342 >        final ThreadPoolExecutor p =
1343              new ThreadPoolExecutor(2, 3,
1344                                     LONG_DELAY_MS, MILLISECONDS,
1345                                     new ArrayBlockingQueue<Runnable>(10));
# Line 1360 | Line 1358 | public class ThreadPoolExecutorTest exte
1358       * max pool size result in IllegalArgumentException.
1359       */
1360      public void testPoolSizeInvariants() {
1361 <        ThreadPoolExecutor p =
1361 >        final ThreadPoolExecutor p =
1362              new ThreadPoolExecutor(1, 1,
1363                                     LONG_DELAY_MS, MILLISECONDS,
1364                                     new ArrayBlockingQueue<Runnable>(10));
# Line 1388 | Line 1386 | public class ThreadPoolExecutorTest exte
1386       * when given a negative value
1387       */
1388      public void testKeepAliveTimeIllegalArgumentException() {
1389 <        ThreadPoolExecutor p =
1389 >        final ThreadPoolExecutor p =
1390              new ThreadPoolExecutor(2, 3,
1391                                     LONG_DELAY_MS, MILLISECONDS,
1392                                     new ArrayBlockingQueue<Runnable>(10));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines