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 |
|
|
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 |
|
} |