1 package org.sapia.ubik.net; 2 3 import junit.framework.TestCase; 4 5 6 14 public class SemaphoreTest extends TestCase { 15 19 public SemaphoreTest(String arg0) { 20 super(arg0); 21 } 22 23 public void testAcquire() throws Exception { 24 Semaphore s = new Semaphore(3); 25 s.acquireFor(new Runnable () { 26 public void run() { 27 } 28 }); 29 s.acquireFor(new Runnable () { 30 public void run() { 31 } 32 }); 33 s.acquireFor(new Runnable () { 34 public void run() { 35 } 36 }); 37 38 try { 39 s.acquireFor(new Runnable () { 40 public void run() { 41 } 42 }); 43 throw new Exception ("Thread creation should not have been authorized"); 44 } catch (MaxThreadReachedException e) { 45 } 47 } 48 49 public void testRelease() throws Exception { 50 Semaphore s = new Semaphore(3); 51 Thread t; 52 t = s.acquireFor(new Runnable () { 53 public void run() { 54 } 55 }); 56 t.start(); 57 Thread.sleep(1000); 58 s.acquireFor(new Runnable () { 59 public void run() { 60 } 61 }); 62 s.acquireFor(new Runnable () { 63 public void run() { 64 } 65 }); 66 s.acquireFor(new Runnable () { 67 public void run() { 68 } 69 }); 70 } 71 } 72 | Popular Tags |