1 package org.sapia.taskman; 2 3 import junit.framework.TestCase; 4 5 import java.io.*; 6 7 10 public class TaskManagerTest extends TestCase { 11 16 public TaskManagerTest(String arg0) { 17 super(arg0); 18 } 19 20 public void testShutdown() throws Exception { 21 TaskManager mgr = new TaskManager(); 22 23 mgr.execTaskFor(new PeriodicTaskDescriptor("task2", 10000, 26 new SleepingTask())); 27 mgr.start(); 28 Thread.sleep(1000); 29 mgr.shutdown(); 30 } 31 32 public void testShutdownEmpty() throws Exception { 33 TaskManager mgr = new TaskManager(); 34 mgr.start(); 35 Thread.sleep(1000); 36 mgr.shutdown(); 37 } 38 39 public void testSerialize() throws Exception { 40 TaskManager mgr = new TaskManager(); 41 ByteArrayOutputStream bos; 42 ObjectOutputStream oos = new ObjectOutputStream( 43 bos = new ByteArrayOutputStream()); 44 oos.writeObject(mgr); 45 46 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos 47 .toByteArray())); 48 mgr = (TaskManager) ois.readObject(); 49 } 50 51 public static class SleepingTask implements Task { 52 55 public void exec(TaskContext ctx) { 56 try { 57 Thread.sleep(3000); 59 60 } catch(InterruptedException e) { 62 e.printStackTrace(); 63 } 64 } 65 } 66 } 67 | Popular Tags |