1 8 package test.ozoneDB.core.storage.gammaStore; 9 10 import junit.framework.Test; 11 import junit.framework.TestResult; 12 import junit.framework.TestSuite; 13 import junit.textui.TestRunner; 14 import org.ozoneDB.core.storage.gammaStore.AsyncExec; 15 import test.OzoneTestCase; 16 import test.OzoneTestRunner; 17 18 21 public class AsyncExecTest extends OzoneTestCase { 22 23 private AsyncExec asyncExec = new AsyncExec("test", Thread.MAX_PRIORITY, true); 24 25 private Object lock = new Object (); 26 27 private volatile int taskCount = 0; 28 29 public AsyncExecTest() { 30 super("testAsyncExec"); 31 } 32 33 public static Test suite() { 34 TestSuite suite = new TestSuite(); 35 36 suite.addTest(new LocTest()); 37 return suite; 38 } 39 40 public void testAsyncExec() { 41 Object key1 = new Integer (0); 42 Object key2 = new Integer (1); 43 synchronized (lock){ 44 asyncExec.put(key1, new Task()); 45 asyncExec.put(key2, new Task()); 46 try { 47 lock.wait(); 48 } catch (InterruptedException ignore) { 49 } 50 assertNotNull(asyncExec.get(key2)); 51 assertEquals(taskCount, 0); 52 assertNull(asyncExec.get(key1)); 53 assertEquals(taskCount, 1); 54 try { 55 lock.wait(); 56 } catch (InterruptedException ignore) { 57 } 58 assertNull(asyncExec.get(key2)); 59 assertEquals(taskCount, 2); 60 asyncExec.stopWhenReady(); 61 } 62 } 63 64 public static void main(String [] args) { 65 TestRunner testRunner = new TestRunner(); 66 testRunner.run(AsyncExecTest.class); 67 } 68 69 private class Task implements Runnable { 70 71 public void run() { 72 synchronized (lock) { 73 lock.notifyAll(); 74 } 75 try { 76 Thread.sleep(1000); 77 } catch (InterruptedException ignore) { 78 } 79 taskCount++; 80 } 81 82 } 83 } 84 | Popular Tags |