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.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 SemaphoreTest extends TestCase{
14  
# Line 193 | Line 194 | public class SemaphoreTest extends TestC
194              fail("unexpected exception");
195          }
196      }
197 +
198 +    public void testSerialization() {
199 +        Semaphore l = new Semaphore(3);
200 +
201 +        try {
202 +            l.acquire();
203 +            l.release();
204 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
205 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
206 +            out.writeObject(l);
207 +            out.close();
208 +
209 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
210 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
211 +            Semaphore r = (Semaphore) in.readObject();
212 +            assertEquals(3, r.availablePermits());
213 +            r.acquire();
214 +            r.release();
215 +        } catch(Exception e){
216 +            e.printStackTrace();
217 +            fail("unexpected exception");
218 +        }
219 +    }
220 +
221   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines