1 package org.sapia.ubik.rmi.server.command; 2 3 import junit.framework.TestCase; 4 5 import org.sapia.ubik.rmi.server.ShutdownException; 6 7 8 17 public class ExecQueueTest extends TestCase { 18 public ExecQueueTest(String name) { 19 super(name); 20 } 21 22 public void testShutdown() throws Exception { 23 ExecQueue queue = new ExecQueue(); 24 queue.add(new Executable() { 25 public Object execute() throws Throwable { 26 return null; 27 } 28 }); 29 30 long start = System.currentTimeMillis(); 31 queue.shutdown(1000); 32 33 try { 34 queue.add(null); 35 throw new Exception ("ShutdownException not thrown"); 36 } catch (ShutdownException e) { 37 } 39 40 super.assertTrue((System.currentTimeMillis() - start) > 700); 41 } 42 43 public void testShutdownWithRemoveAll() throws Exception { 44 final ExecQueue queue = new ExecQueue(); 45 queue.add(new Executable() { 46 public Object execute() throws Throwable { 47 return null; 48 } 49 }); 50 51 Thread remover = new Thread (new Runnable () { 52 public void run() { 53 try { 54 Thread.sleep(700); 55 queue.removeAll(); 56 } catch (Throwable t) { 57 } 58 } 59 }); 60 remover.start(); 61 62 long start = System.currentTimeMillis(); 63 queue.shutdown(2000); 64 super.assertEquals(0, queue.size()); 65 66 try { 67 queue.add(null); 68 throw new Exception ("ShutdownException not thrown"); 69 } catch (ShutdownException e) { 70 } 72 } 73 74 public void testShutdownWithRemove() throws Exception { 75 final ExecQueue queue = new ExecQueue(); 76 queue.add(new Executable() { 77 public Object execute() throws Throwable { 78 return null; 79 } 80 }); 81 82 Thread remover = new Thread (new Runnable () { 83 public void run() { 84 try { 85 Thread.sleep(700); 86 queue.remove(); 87 } catch (Throwable t) { 88 } 89 } 90 }); 91 remover.start(); 92 93 long start = System.currentTimeMillis(); 94 queue.shutdown(2000); 95 super.assertEquals(0, queue.size()); 96 97 try { 98 queue.add(null); 99 throw new Exception ("ShutdownException not thrown"); 100 } catch (ShutdownException e) { 101 } 103 104 super.assertTrue((System.currentTimeMillis() - start) > 700); 105 } 106 } 107 | Popular Tags |