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

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.75 by jsr166, Sat May 13 23:50:00 2017 UTC vs.
Revision 1.80 by jsr166, Sun May 14 04:14:09 2017 UTC

# Line 626 | Line 626 | public class LinkedBlockingDequeTest ext
626                  pleaseTake.countDown();
627                  q.put(86);
628  
629 +                Thread.currentThread().interrupt();
630 +                try {
631 +                    q.put(99);
632 +                    shouldThrow();
633 +                } catch (InterruptedException success) {}
634 +                assertFalse(Thread.interrupted());
635 +
636                  pleaseInterrupt.countDown();
637                  try {
638                      q.put(99);
# Line 648 | Line 655 | public class LinkedBlockingDequeTest ext
655      /**
656       * timed offer times out if full and elements not taken
657       */
658 <    public void testTimedOffer() throws InterruptedException {
658 >    public void testTimedOffer() {
659          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
660          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
661          Thread t = newStartedThread(new CheckedRunnable() {
# Line 658 | Line 665 | public class LinkedBlockingDequeTest ext
665                  long startTime = System.nanoTime();
666                  assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS));
667                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
668 +
669 +                Thread.currentThread().interrupt();
670 +                try {
671 +                    q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
672 +                    shouldThrow();
673 +                } catch (InterruptedException success) {}
674 +                assertFalse(Thread.interrupted());
675 +
676                  pleaseInterrupt.countDown();
677                  try {
678                      q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
679                      shouldThrow();
680                  } catch (InterruptedException success) {}
681 +                assertFalse(Thread.interrupted());
682              }});
683  
684          await(pleaseInterrupt);
# Line 756 | Line 772 | public class LinkedBlockingDequeTest ext
772       */
773      public void testInterruptedTimedPoll() throws InterruptedException {
774          final BlockingQueue<Integer> q = populatedDeque(SIZE);
775 <        final CountDownLatch aboutToWait = new CountDownLatch(1);
775 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
776          Thread t = newStartedThread(new CheckedRunnable() {
777              public void realRun() throws InterruptedException {
778                  long startTime = System.nanoTime();
779 <                for (int i = 0; i < SIZE; ++i) {
779 >                for (int i = 0; i < SIZE; i++)
780                      assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS));
781 <                }
782 <                aboutToWait.countDown();
781 >
782 >                Thread.currentThread().interrupt();
783                  try {
784                      q.poll(LONG_DELAY_MS, MILLISECONDS);
785                      shouldThrow();
786 <                } catch (InterruptedException success) {
787 <                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
788 <                }
786 >                } catch (InterruptedException success) {}
787 >                assertFalse(Thread.interrupted());
788 >
789 >                pleaseInterrupt.countDown();
790 >                try {
791 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
792 >                    shouldThrow();
793 >                } catch (InterruptedException success) {}
794 >                assertFalse(Thread.interrupted());
795 >
796 >                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
797              }});
798  
799 <        await(aboutToWait);
799 >        await(pleaseInterrupt);
800          assertThreadBlocks(t, Thread.State.TIMED_WAITING);
801          t.interrupt();
802          awaitTermination(t);
# Line 876 | Line 900 | public class LinkedBlockingDequeTest ext
900      /**
901       * timed offerFirst times out if full and elements not taken
902       */
903 <    public void testTimedOfferFirst() throws InterruptedException {
903 >    public void testTimedOfferFirst() {
904          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
905          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
906          Thread t = newStartedThread(new CheckedRunnable() {
# Line 886 | Line 910 | public class LinkedBlockingDequeTest ext
910                  long startTime = System.nanoTime();
911                  assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS));
912                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
913 +
914 +                Thread.currentThread().interrupt();
915 +                try {
916 +                    q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
917 +                    shouldThrow();
918 +                } catch (InterruptedException success) {}
919 +                assertFalse(Thread.interrupted());
920 +
921                  pleaseInterrupt.countDown();
922                  try {
923                      q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
924                      shouldThrow();
925                  } catch (InterruptedException success) {}
926 +                assertFalse(Thread.interrupted());
927              }});
928  
929          await(pleaseInterrupt);
# Line 1059 | Line 1092 | public class LinkedBlockingDequeTest ext
1092          Thread t = newStartedThread(new CheckedRunnable() {
1093              public void realRun() throws InterruptedException {
1094                  long startTime = System.nanoTime();
1095 <                for (int i = 0; i < SIZE; ++i) {
1095 >                for (int i = 0; i < SIZE; i++)
1096                      assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
1064                }
1097  
1098                  Thread.currentThread().interrupt();
1099                  try {
# Line 1076 | Line 1108 | public class LinkedBlockingDequeTest ext
1108                      shouldThrow();
1109                  } catch (InterruptedException success) {}
1110                  assertFalse(Thread.interrupted());
1111 +
1112                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1113              }});
1114  
# Line 1113 | Line 1146 | public class LinkedBlockingDequeTest ext
1146                      q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1147                      shouldThrow();
1148                  } catch (InterruptedException success) {}
1149 +                assertFalse(Thread.interrupted());
1150                  assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1151              }});
1152  
# Line 1201 | Line 1235 | public class LinkedBlockingDequeTest ext
1235                  pleaseTake.countDown();
1236                  q.putLast(86);
1237  
1238 +                Thread.currentThread().interrupt();
1239 +                try {
1240 +                    q.putLast(99);
1241 +                    shouldThrow();
1242 +                } catch (InterruptedException success) {}
1243 +                assertFalse(Thread.interrupted());
1244 +
1245                  pleaseInterrupt.countDown();
1246                  try {
1247                      q.putLast(99);
# Line 1223 | Line 1264 | public class LinkedBlockingDequeTest ext
1264      /**
1265       * timed offerLast times out if full and elements not taken
1266       */
1267 <    public void testTimedOfferLast() throws InterruptedException {
1267 >    public void testTimedOfferLast() {
1268          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1269          final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
1270          Thread t = newStartedThread(new CheckedRunnable() {
# Line 1233 | Line 1274 | public class LinkedBlockingDequeTest ext
1274                  long startTime = System.nanoTime();
1275                  assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS));
1276                  assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
1277 +
1278 +                Thread.currentThread().interrupt();
1279 +                try {
1280 +                    q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
1281 +                    shouldThrow();
1282 +                } catch (InterruptedException success) {}
1283 +
1284                  pleaseInterrupt.countDown();
1285                  try {
1286                      q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS);
# Line 1325 | Line 1373 | public class LinkedBlockingDequeTest ext
1373          Thread t = newStartedThread(new CheckedRunnable() {
1374              public void realRun() throws InterruptedException {
1375                  long startTime = System.nanoTime();
1376 <                for (int i = 0; i < SIZE; ++i) {
1376 >                for (int i = 0; i < SIZE; i++)
1377                      assertEquals(SIZE - i - 1,
1378                                   q.pollLast(LONG_DELAY_MS, MILLISECONDS));
1331                }
1379  
1380                  Thread.currentThread().interrupt();
1381                  try {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines