frysk.event
Class EventLoopTestBed

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by frysk.junit.TestCase
              extended by frysk.event.EventLoopTestBed
All Implemented Interfaces:
Test
Direct Known Subclasses:
TestPollEventLoop, TestWaitEventLoop

abstract class EventLoopTestBed
extends TestCase

Framework for testing different event loops.


Nested Class Summary
private  class EventLoopTestBed.EventRequest
          Wrapper class to Request that re-dispatches to the specified event.
private  class EventLoopTestBed.EventThread
          This thread asynchronously adds an event to the event loop.
private  class EventLoopTestBed.Immediate
          Test that multiple requests from the event-loop thread get proccessed immediatly.
private  class EventLoopTestBed.RunnableEvent
           
private  class EventLoopTestBed.RunnableExecuteEvent
           
private  class EventLoopTestBed.RunnableRequestEvent
           
private  class EventLoopTestBed.SignalThread
          This thread asynchronously adds a signal handler, and code to trigger the signal, to the event loop.
private  class EventLoopTestBed.SleepThread
          This thread asynchronously, and after 100 milliseconds, adds a final stop request.
private  class EventLoopTestBed.Throw
           
private  class EventLoopTestBed.TimerThread
          This thread asynchronously adds a timer to the event loop.
 
Field Summary
private  EventLoop eventLoop
           
private  ProcessIdentifier eventTid
           
 
Constructor Summary
EventLoopTestBed()
           
 
Method Summary
protected abstract  EventLoop newEventLoop()
          Return the event loop to be tested.
 void setUp()
          Re-create the event loop ready for the next test.
 void tearDown()
          Reap any stray signals.
 void testAsync()
          Check that asynchronous events wake up the event loop.
 void testCountDownTimersAndSignals()
          Test countdown timers alternating with signals.
 void testExecuteImmediate()
           
 void testExecuteRunnable()
           
 void testExecuteThrow()
           
 void testManyExecutes()
           
 void testManyRequests()
           
 void testPeriodicTimer()
          Test the periodic timer.
 void testRequestImmediate()
           
 void testRequestRunnable()
           
 void testRequestThrow()
           
 void testScheduleBeforeRun()
          Test that events scheduled before run are processed.
 void testSignalHandler()
          Test adding and removing a signal handler.
 void testTimerRemoval()
          Test the removal of a timer.
private  void verifyImmediate(EventLoopTestBed.Immediate immediate)
           
private  void verifyMany(EventLoopTestBed.RunnableEvent request)
          Test that many simultaneous requests, from different threads, are eventually all handled.
private  void verifyRunnableEvent(EventLoopTestBed.RunnableEvent request)
          Test that a simple request is handled by the event-loop thread.
private  void verifyThrow(EventLoopTestBed.Throw request)
          Test that a throw from within the event-loop thread is propogated back to the requesting thread.
 
Methods inherited from class frysk.junit.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, getTimeoutMilliseconds, getTimeoutSeconds, missing32or64, unresolved, unresolvedOffUtrace, unresolvedOn32On64, unresolvedOnIA32, unresolvedOnPPC, unresolvedOnUtrace, unresolvedOnx8664, unsupported
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

eventLoop

private EventLoop eventLoop

eventTid

private ProcessIdentifier eventTid
Constructor Detail

EventLoopTestBed

EventLoopTestBed()
Method Detail

newEventLoop

protected abstract EventLoop newEventLoop()
Return the event loop to be tested.


setUp

public void setUp()
Re-create the event loop ready for the next test. Always include a CNTRL-C handler so that the tests can be aborted.

Overrides:
setUp in class TestCase

tearDown

public void tearDown()
Reap any stray signals.

Overrides:
tearDown in class TestCase

testCountDownTimersAndSignals

public void testCountDownTimersAndSignals()
Test countdown timers alternating with signals.


testPeriodicTimer

public void testPeriodicTimer()
Test the periodic timer.


testTimerRemoval

public void testTimerRemoval()
Test the removal of a timer.


testScheduleBeforeRun

public void testScheduleBeforeRun()
Test that events scheduled before run are processed. This checks that any synchronous events appended before the event loop is started are always run.


testSignalHandler

public void testSignalHandler()
Test adding and removing a signal handler. This adds / removes / adds a SIGCHLD handler (by default SIGCHLD signals are ignored).and then checks that when it is installed the event occurs, but when it is un-installed, the event is lost.


testAsync

public void testAsync()
Check that asynchronous events wake up the event loop. Create a chain of events, each relying on the previous, and each relying on being processed in a timely manner -- the entire operation must complete before the event-loop master timer expires.


verifyRunnableEvent

private void verifyRunnableEvent(EventLoopTestBed.RunnableEvent request)
Test that a simple request is handled by the event-loop thread.


testExecuteRunnable

public void testExecuteRunnable()

testRequestRunnable

public void testRequestRunnable()

verifyMany

private void verifyMany(EventLoopTestBed.RunnableEvent request)
Test that many simultaneous requests, from different threads, are eventually all handled.


testManyExecutes

public void testManyExecutes()

testManyRequests

public void testManyRequests()

verifyThrow

private void verifyThrow(EventLoopTestBed.Throw request)
Test that a throw from within the event-loop thread is propogated back to the requesting thread.


testExecuteThrow

public void testExecuteThrow()

testRequestThrow

public void testRequestThrow()

verifyImmediate

private void verifyImmediate(EventLoopTestBed.Immediate immediate)

testExecuteImmediate

public void testExecuteImmediate()

testRequestImmediate

public void testRequestImmediate()