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

Comparing jsr166/src/test/tck/ExchangerTest.java (file contents):
Revision 1.7 by jsr166, Mon Nov 16 04:57:10 2009 UTC vs.
Revision 1.8 by jsr166, Mon Nov 16 05:30:07 2009 UTC

# Line 24 | Line 24 | public class ExchangerTest extends JSR16
24       */
25      public void testExchange() {
26          final Exchanger e = new Exchanger();
27 <        Thread t1 = new Thread(new Runnable(){
28 <                public void run(){
27 >        Thread t1 = new Thread(new Runnable() {
28 >                public void run() {
29                      try {
30                          Object v = e.exchange(one);
31                          threadAssertEquals(v, two);
32                          Object w = e.exchange(v);
33                          threadAssertEquals(w, one);
34 <                    } catch (InterruptedException e){
34 >                    } catch (InterruptedException e) {
35                          threadUnexpectedException();
36                      }
37                  }
38              });
39 <        Thread t2 = new Thread(new Runnable(){
40 <                public void run(){
39 >        Thread t2 = new Thread(new Runnable() {
40 >                public void run() {
41                      try {
42                          Object v = e.exchange(two);
43                          threadAssertEquals(v, one);
44                          Object w = e.exchange(v);
45                          threadAssertEquals(w, two);
46 <                    } catch (InterruptedException e){
46 >                    } catch (InterruptedException e) {
47                          threadUnexpectedException();
48                      }
49                  }
# Line 63 | Line 63 | public class ExchangerTest extends JSR16
63       */
64      public void testTimedExchange() {
65          final Exchanger e = new Exchanger();
66 <        Thread t1 = new Thread(new Runnable(){
67 <                public void run(){
66 >        Thread t1 = new Thread(new Runnable() {
67 >                public void run() {
68                      try {
69                          Object v = e.exchange(one, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
70                          threadAssertEquals(v, two);
71                          Object w = e.exchange(v, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
72                          threadAssertEquals(w, one);
73 <                    } catch (InterruptedException e){
73 >                    } catch (InterruptedException e) {
74                          threadUnexpectedException();
75                      } catch (TimeoutException toe) {
76                          threadUnexpectedException();
77                      }
78                  }
79              });
80 <        Thread t2 = new Thread(new Runnable(){
81 <                public void run(){
80 >        Thread t2 = new Thread(new Runnable() {
81 >                public void run() {
82                      try {
83                          Object v = e.exchange(two, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
84                          threadAssertEquals(v, one);
85                          Object w = e.exchange(v, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
86                          threadAssertEquals(w, two);
87 <                    } catch (InterruptedException e){
87 >                    } catch (InterruptedException e) {
88                          threadUnexpectedException();
89                      } catch (TimeoutException toe) {
90                          threadUnexpectedException();
# Line 104 | Line 104 | public class ExchangerTest extends JSR16
104      /**
105       * interrupt during wait for exchange throws IE
106       */
107 <    public void testExchange_InterruptedException(){
107 >    public void testExchange_InterruptedException() {
108          final Exchanger e = new Exchanger();
109          Thread t = new Thread(new Runnable() {
110 <                public void run(){
110 >                public void run() {
111                      try {
112                          e.exchange(one);
113                          threadShouldThrow();
114 <                    } catch (InterruptedException success){
114 >                    } catch (InterruptedException success) {
115                      }
116                  }
117              });
# Line 128 | Line 128 | public class ExchangerTest extends JSR16
128      /**
129       * interrupt during wait for timed exchange throws IE
130       */
131 <    public void testTimedExchange_InterruptedException(){
131 >    public void testTimedExchange_InterruptedException() {
132          final Exchanger e = new Exchanger();
133          Thread t = new Thread(new Runnable() {
134 <                public void run(){
134 >                public void run() {
135                      try {
136                          e.exchange(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
137                          threadShouldThrow();
138 <                    } catch (InterruptedException success){
139 <                    } catch (Exception e2){
138 >                    } catch (InterruptedException success) {
139 >                    } catch (Exception e2) {
140                          threadFail("should throw IE");
141                      }
142                  }
# Line 145 | Line 145 | public class ExchangerTest extends JSR16
145              t.start();
146              t.interrupt();
147              t.join();
148 <        } catch (InterruptedException ex){
148 >        } catch (InterruptedException ex) {
149              unexpectedException();
150          }
151      }
# Line 153 | Line 153 | public class ExchangerTest extends JSR16
153      /**
154       * timeout during wait for timed exchange throws TOE
155       */
156 <    public void testExchange_TimeOutException(){
156 >    public void testExchange_TimeOutException() {
157          final Exchanger e = new Exchanger();
158          Thread t = new Thread(new Runnable() {
159 <                public void run(){
159 >                public void run() {
160                      try {
161                          e.exchange(null, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
162                          threadShouldThrow();
163 <                    } catch (TimeoutException success){
164 <                    } catch (InterruptedException e2){
163 >                    } catch (TimeoutException success) {
164 >                    } catch (InterruptedException e2) {
165                          threadFail("should throw TOE");
166                      }
167                  }
# Line 169 | Line 169 | public class ExchangerTest extends JSR16
169          try {
170              t.start();
171              t.join();
172 <        } catch (InterruptedException ex){
172 >        } catch (InterruptedException ex) {
173              unexpectedException();
174          }
175      }
# Line 179 | Line 179 | public class ExchangerTest extends JSR16
179       */
180      public void testReplacementAfterExchange() {
181          final Exchanger e = new Exchanger();
182 <        Thread t1 = new Thread(new Runnable(){
183 <                public void run(){
182 >        Thread t1 = new Thread(new Runnable() {
183 >                public void run() {
184                      try {
185                          Object v = e.exchange(one);
186                          threadAssertEquals(v, two);
187                          Object w = e.exchange(v);
188                          threadShouldThrow();
189 <                    } catch (InterruptedException success){
189 >                    } catch (InterruptedException success) {
190                      }
191                  }
192              });
193 <        Thread t2 = new Thread(new Runnable(){
194 <                public void run(){
193 >        Thread t2 = new Thread(new Runnable() {
194 >                public void run() {
195                      try {
196                          Object v = e.exchange(two);
197                          threadAssertEquals(v, one);
198                          Thread.sleep(SMALL_DELAY_MS);
199                          Object w = e.exchange(v);
200                          threadAssertEquals(w, three);
201 <                    } catch (InterruptedException e){
201 >                    } catch (InterruptedException e) {
202                          threadUnexpectedException();
203                      }
204                  }
205              });
206 <        Thread t3 = new Thread(new Runnable(){
207 <                public void run(){
206 >        Thread t3 = new Thread(new Runnable() {
207 >                public void run() {
208                      try {
209                          Thread.sleep(SMALL_DELAY_MS);
210                          Object w = e.exchange(three);
211                          threadAssertEquals(w, one);
212 <                    } catch (InterruptedException e){
212 >                    } catch (InterruptedException e) {
213                          threadUnexpectedException();
214                      }
215                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines