public void testTimerHandleSerialization() throws Exception
{
TimedMockObject to = new TimedMockObject();
TimerService service = createTimerService(to);
Timer timer1 = service.createTimer(500, null);
TimerHandle handle1 = timer1.getHandle();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(handle1);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
TimerHandle handle2 = (TimerHandle)ois.readObject();
Timer timer2 = handle2.getTimer();
assertEquals("Timers are not equal", timer1, timer2);
sleep(1000);
assertTrue("TimedObject not called", 1 == to.getCallCount());
assertEquals("Expected no txtimer", 0, service.getTimers().size());