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

Comparing jsr166/src/test/tck/SemaphoreTest.java (file contents):
Revision 1.1 by dl, Sun Aug 31 19:24:55 2003 UTC vs.
Revision 1.3 by dl, Sun Sep 14 20:42:40 2003 UTC

# Line 8 | Line 8
8   import junit.framework.*;
9   import java.util.*;
10   import java.util.concurrent.*;
11 + import java.io.*;
12  
13 < public class SemaphoreTest extends TestCase{
13 > public class SemaphoreTest extends JSR166TestCase {
14  
15      public static void main(String[] args) {
16          junit.textui.TestRunner.run (suite());  
# Line 19 | Line 20 | public class SemaphoreTest extends TestC
20          return new TestSuite(SemaphoreTest.class);
21      }
22  
22    private static long SHORT_DELAY_MS = 100;
23    private static long MEDIUM_DELAY_MS = 1000;
24    private static long LONG_DELAY_MS = 10000;
25
26
23      public void testConstructor1() {
24          Semaphore s = new Semaphore(0);
25          assertEquals(0, s.availablePermits());
# Line 91 | Line 87 | public class SemaphoreTest extends TestC
87                          s.release();
88                          s.acquire();
89                      }catch(InterruptedException ie){
90 <                        fail("unexpected exception");
90 >                        threadFail("unexpected exception");
91                      }
92                  }
93              });
# Line 132 | Line 128 | public class SemaphoreTest extends TestC
128                  public void run(){
129                      try{
130                          s.release();
131 <                        assertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
131 >                        threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
132                          s.release();
133 <                        assertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
133 >                        threadAssertTrue(s.tryAcquire(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
134  
135                      }catch(InterruptedException ie){
136 <                        fail("unexpected exception");
136 >                        threadFail("unexpected exception");
137                      }
138                  }
139              });
# Line 159 | Line 155 | public class SemaphoreTest extends TestC
155                  public void run(){
156                      try{
157                          s.acquire();
158 <                        fail("should throw");
158 >                        threadFail("should throw");
159                      }catch(InterruptedException success){}
160                  }
161              });
# Line 179 | Line 175 | public class SemaphoreTest extends TestC
175                  public void run(){
176                      try{
177                          s.tryAcquire(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS);
178 <                        fail("should throw");
178 >                        threadFail("should throw");
179                      }catch(InterruptedException success){
180                      }
181                  }
# Line 193 | Line 189 | public class SemaphoreTest extends TestC
189              fail("unexpected exception");
190          }
191      }
192 +
193 +    public void testSerialization() {
194 +        Semaphore l = new Semaphore(3);
195 +        try {
196 +            l.acquire();
197 +            l.release();
198 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
199 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
200 +            out.writeObject(l);
201 +            out.close();
202 +
203 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
204 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
205 +            Semaphore r = (Semaphore) in.readObject();
206 +            assertEquals(3, r.availablePermits());
207 +            r.acquire();
208 +            r.release();
209 +        } catch(Exception e){
210 +            e.printStackTrace();
211 +            fail("unexpected exception");
212 +        }
213 +    }
214 +
215   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines