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

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.26 by jsr166, Sat Nov 21 02:07:27 2009 UTC vs.
Revision 1.31 by jsr166, Sat Oct 9 18:40:41 2010 UTC

# Line 14 | Line 14 | import java.util.concurrent.atomic.*;
14  
15   public class ScheduledExecutorTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20          return new TestSuite(ScheduledExecutorTest.class);
# Line 25 | Line 25 | public class ScheduledExecutorTest exten
25       * execute successfully executes a runnable
26       */
27      public void testExecute() throws InterruptedException {
28 <        TrackedShortRunnable runnable =new TrackedShortRunnable();
28 >        TrackedShortRunnable runnable = new TrackedShortRunnable();
29          ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1);
30          p1.execute(runnable);
31          assertFalse(runnable.done);
# Line 137 | Line 137 | public class ScheduledExecutorTest exten
137  
138  
139      /**
140 <     *  execute (null) throws NPE
140 >     *  execute(null) throws NPE
141       */
142      public void testExecuteNull() throws InterruptedException {
143          ScheduledThreadPoolExecutor se = null;
# Line 151 | Line 151 | public class ScheduledExecutorTest exten
151      }
152  
153      /**
154 <     * schedule (null) throws NPE
154 >     * schedule(null) throws NPE
155       */
156      public void testScheduleNull() throws InterruptedException {
157          ScheduledThreadPoolExecutor se = new ScheduledThreadPoolExecutor(1);
# Line 178 | Line 178 | public class ScheduledExecutorTest exten
178          }
179  
180          joinPool(se);
181
181      }
182  
183      /**
# Line 659 | Line 658 | public class ScheduledExecutorTest exten
658       * invokeAny(c) throws NPE if c has null elements
659       */
660      public void testInvokeAny3() throws Exception {
661 <        final CountDownLatch latch = new CountDownLatch(1);
661 >        CountDownLatch latch = new CountDownLatch(1);
662          ExecutorService e = new ScheduledThreadPoolExecutor(2);
663 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
664 +        l.add(latchAwaitingStringTask(latch));
665 +        l.add(null);
666          try {
665            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
666            l.add(new Callable<String>() {
667                      public String call() {
668                          try {
669                              latch.await();
670                          } catch (InterruptedException ok) {}
671                          return TEST_STRING;
672                      }});
673            l.add(null);
667              e.invokeAny(l);
668              shouldThrow();
669          } catch (NullPointerException success) {
# Line 685 | Line 678 | public class ScheduledExecutorTest exten
678       */
679      public void testInvokeAny4() throws Exception {
680          ExecutorService e = new ScheduledThreadPoolExecutor(2);
681 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
682 +        l.add(new NPETask());
683          try {
689            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
690            l.add(new NPETask());
684              e.invokeAny(l);
685              shouldThrow();
686          } catch (ExecutionException success) {
# Line 703 | Line 696 | public class ScheduledExecutorTest exten
696      public void testInvokeAny5() throws Exception {
697          ExecutorService e = new ScheduledThreadPoolExecutor(2);
698          try {
699 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
699 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
700              l.add(new StringTask());
701              l.add(new StringTask());
702              String result = e.invokeAny(l);
# Line 745 | Line 738 | public class ScheduledExecutorTest exten
738       */
739      public void testInvokeAll3() throws Exception {
740          ExecutorService e = new ScheduledThreadPoolExecutor(2);
741 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
742 +        l.add(new StringTask());
743 +        l.add(null);
744          try {
749            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
750            l.add(new StringTask());
751            l.add(null);
745              e.invokeAll(l);
746              shouldThrow();
747          } catch (NullPointerException success) {
# Line 762 | Line 755 | public class ScheduledExecutorTest exten
755       */
756      public void testInvokeAll4() throws Exception {
757          ExecutorService e = new ScheduledThreadPoolExecutor(2);
758 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
759 +        l.add(new NPETask());
760 +        List<Future<String>> futures = e.invokeAll(l);
761 +        assertEquals(1, futures.size());
762          try {
763 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
767 <            l.add(new NPETask());
768 <            List<Future<String>> result = e.invokeAll(l);
769 <            assertEquals(1, result.size());
770 <            for (Future<String> future : result)
771 <                future.get();
763 >            futures.get(0).get();
764              shouldThrow();
765          } catch (ExecutionException success) {
766              assertTrue(success.getCause() instanceof NullPointerException);
# Line 783 | Line 775 | public class ScheduledExecutorTest exten
775      public void testInvokeAll5() throws Exception {
776          ExecutorService e = new ScheduledThreadPoolExecutor(2);
777          try {
778 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
778 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
779              l.add(new StringTask());
780              l.add(new StringTask());
781 <            List<Future<String>> result = e.invokeAll(l);
782 <            assertEquals(2, result.size());
783 <            for (Future<String> future : result)
781 >            List<Future<String>> futures = e.invokeAll(l);
782 >            assertEquals(2, futures.size());
783 >            for (Future<String> future : futures)
784                  assertSame(TEST_STRING, future.get());
785          } finally {
786              joinPool(e);
# Line 814 | Line 806 | public class ScheduledExecutorTest exten
806       */
807      public void testTimedInvokeAnyNullTimeUnit() throws Exception {
808          ExecutorService e = new ScheduledThreadPoolExecutor(2);
809 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
810 +        l.add(new StringTask());
811          try {
818            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
819            l.add(new StringTask());
812              e.invokeAny(l, MEDIUM_DELAY_MS, null);
813              shouldThrow();
814          } catch (NullPointerException success) {
# Line 843 | Line 835 | public class ScheduledExecutorTest exten
835       * timed invokeAny(c) throws NPE if c has null elements
836       */
837      public void testTimedInvokeAny3() throws Exception {
838 <        final CountDownLatch latch = new CountDownLatch(1);
838 >        CountDownLatch latch = new CountDownLatch(1);
839          ExecutorService e = new ScheduledThreadPoolExecutor(2);
840 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
841 +        l.add(latchAwaitingStringTask(latch));
842 +        l.add(null);
843          try {
849            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
850            l.add(new Callable<String>() {
851                      public String call() {
852                          try {
853                              latch.await();
854                          } catch (InterruptedException ok) {}
855                          return TEST_STRING;
856                      }});
857            l.add(null);
844              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
845              shouldThrow();
846          } catch (NullPointerException success) {
# Line 869 | Line 855 | public class ScheduledExecutorTest exten
855       */
856      public void testTimedInvokeAny4() throws Exception {
857          ExecutorService e = new ScheduledThreadPoolExecutor(2);
858 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
859 +        l.add(new NPETask());
860          try {
873            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
874            l.add(new NPETask());
861              e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
862              shouldThrow();
863          } catch (ExecutionException success) {
# Line 887 | Line 873 | public class ScheduledExecutorTest exten
873      public void testTimedInvokeAny5() throws Exception {
874          ExecutorService e = new ScheduledThreadPoolExecutor(2);
875          try {
876 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
876 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
877              l.add(new StringTask());
878              l.add(new StringTask());
879              String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS);
# Line 916 | Line 902 | public class ScheduledExecutorTest exten
902       */
903      public void testTimedInvokeAllNullTimeUnit() throws Exception {
904          ExecutorService e = new ScheduledThreadPoolExecutor(2);
905 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
906 +        l.add(new StringTask());
907          try {
920            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
921            l.add(new StringTask());
908              e.invokeAll(l, MEDIUM_DELAY_MS, null);
909              shouldThrow();
910          } catch (NullPointerException success) {
# Line 945 | Line 931 | public class ScheduledExecutorTest exten
931       */
932      public void testTimedInvokeAll3() throws Exception {
933          ExecutorService e = new ScheduledThreadPoolExecutor(2);
934 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
935 +        l.add(new StringTask());
936 +        l.add(null);
937          try {
949            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
950            l.add(new StringTask());
951            l.add(null);
938              e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
939              shouldThrow();
940          } catch (NullPointerException success) {
# Line 962 | Line 948 | public class ScheduledExecutorTest exten
948       */
949      public void testTimedInvokeAll4() throws Exception {
950          ExecutorService e = new ScheduledThreadPoolExecutor(2);
951 +        List<Callable<String>> l = new ArrayList<Callable<String>>();
952 +        l.add(new NPETask());
953 +        List<Future<String>> futures =
954 +            e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
955 +        assertEquals(1, futures.size());
956          try {
957 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
967 <            l.add(new NPETask());
968 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
969 <            assertEquals(1, result.size());
970 <            for (Future<String> future : result)
971 <                future.get();
957 >            futures.get(0).get();
958              shouldThrow();
959          } catch (ExecutionException success) {
960              assertTrue(success.getCause() instanceof NullPointerException);
# Line 983 | Line 969 | public class ScheduledExecutorTest exten
969      public void testTimedInvokeAll5() throws Exception {
970          ExecutorService e = new ScheduledThreadPoolExecutor(2);
971          try {
972 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
972 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
973              l.add(new StringTask());
974              l.add(new StringTask());
975 <            List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
976 <            assertEquals(2, result.size());
977 <            for (Future<String> future : result)
975 >            List<Future<String>> futures =
976 >                e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS);
977 >            assertEquals(2, futures.size());
978 >            for (Future<String> future : futures)
979                  assertSame(TEST_STRING, future.get());
980          } finally {
981              joinPool(e);
# Line 1001 | Line 988 | public class ScheduledExecutorTest exten
988      public void testTimedInvokeAll6() throws Exception {
989          ExecutorService e = new ScheduledThreadPoolExecutor(2);
990          try {
991 <            ArrayList<Callable<String>> l = new ArrayList<Callable<String>>();
991 >            List<Callable<String>> l = new ArrayList<Callable<String>>();
992              l.add(new StringTask());
993              l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING));
994              l.add(new StringTask());
995 <            List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
996 <            assertEquals(3, result.size());
997 <            Iterator<Future<String>> it = result.iterator();
995 >            List<Future<String>> futures =
996 >                e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS);
997 >            assertEquals(3, futures.size());
998 >            Iterator<Future<String>> it = futures.iterator();
999              Future<String> f1 = it.next();
1000              Future<String> f2 = it.next();
1001              Future<String> f3 = it.next();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines