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

Comparing jsr166/src/test/tck/FairSemaphoreTest.java (file contents):
Revision 1.1 by dl, Sun Aug 31 19:24:55 2003 UTC vs.
Revision 1.2 by dl, Sun Sep 7 20:39:11 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 FairSemaphoreTest extends TestCase{
14  
# Line 336 | Line 337 | public class FairSemaphoreTest extends T
337              fail("unexpected exception");
338          }
339      }
340 +
341 +    public void testSerialization() {
342 +        FairSemaphore l = new FairSemaphore(3);
343 +
344 +        try {
345 +            l.acquire();
346 +            l.release();
347 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
348 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
349 +            out.writeObject(l);
350 +            out.close();
351 +
352 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
353 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
354 +            FairSemaphore r = (FairSemaphore) in.readObject();
355 +            assertEquals(3, r.availablePermits());
356 +            r.acquire();
357 +            r.release();
358 +        } catch(Exception e){
359 +            e.printStackTrace();
360 +            fail("unexpected exception");
361 +        }
362 +    }
363  
364   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines