@Test
public void testExceptionInCallbackWrite() {

	try {
		final AtomicBoolean handlerCalled = new AtomicBoolean();
		
		WriteRequest regularRequest = new WriteRequest() {
			
			@Override
			public void requestDone(IOException ioex) {
				synchronized (handlerCalled) {
					handlerCalled.set(true);
					handlerCalled.notifyAll();
				}
			}
			
			@Override
			public void write() {}
		};
		
		WriteRequest exceptionThrower = new WriteRequest() {
			
			@Override
			public void requestDone(IOException ioex) {
				throw new RuntimeException();
			}
			
			@Override
			public void write() {}
		};
		
		RequestQueue<WriteRequest> rq = ioManager.getWriteRequestQueue(ioManager.createChannel());
		
		// queue first an exception thrower, then a regular request.
		// we check that the regular request gets successfully handled
		rq.add(exceptionThrower);
		rq.add(regularRequest);
		
		synchronized (handlerCalled) {
			while (!handlerCalled.get()) {
				handlerCalled.wait();
			}
		}
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}