use of org.jboss.netty.handler.timeout.WriteTimeoutException in project databus by linkedin.
the class MockServerChannelHandler method writeComplete.
// =>=>=> UPstream from server to client
// <=<=<= DNxtream from client to server
@Override
public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception {
Thread t = null;
if (LOG.isDebugEnabled())
LOG.debug("=>=>=>=WRite complete start" + e);
if (_disableWriteComplete) {
LOG.info("Injecting exceptions into writeComplete");
_future.setFailure(new WriteTimeoutException("Mocked WriteTimeout"));
_future.setFailure(new ClosedChannelException());
// 16s sleep
TestUtil.sleep(16000);
} else if (_delayWriteComplete) {
LOG.info("Injecting delay into writeComplete");
t = startExceptionThread(ctx);
LOG.info("waiting for timeout");
TestUtil.sleep(10);
}
super.writeComplete(ctx, e);
LOG.debug("=>=>=> Write complete end");
if (t != null)
// interrupt to close the channel
t.interrupt();
}
use of org.jboss.netty.handler.timeout.WriteTimeoutException in project databus by linkedin.
the class SimpleClientPipelineFactoryWithSleep method testClientSimpleRequestResponse.
@Test
public void testClientSimpleRequestResponse() {
DbusEventFactory eventFactory = new DbusEventV1Factory();
SimpleTestServerConnection srvConn = new SimpleTestServerConnection(eventFactory.getByteOrder());
srvConn.setPipelineFactory(new SimpleServerPipelineFactory());
boolean serverStarted = srvConn.startSynchronously(101, CONNECT_TIMEOUT_MS);
Assert.assertTrue(serverStarted, "server started");
final SimpleTestClientConnection clientConn = new SimpleTestClientConnection(eventFactory.getByteOrder());
clientConn.setPipelineFactory(new SimpleClientPipelineFactoryWithSleep(200));
boolean clientConnected = clientConn.startSynchronously(101, CONNECT_TIMEOUT_MS);
Assert.assertTrue(clientConnected, "client connected");
// hook in to key places in the server pipeline
ChannelPipeline lastSrvConnPipeline = srvConn.getLastConnChannel().getPipeline();
SimpleTestMessageReader srvMsgReader = (SimpleTestMessageReader) lastSrvConnPipeline.get(SimpleTestMessageReader.class.getSimpleName());
ExceptionListenerTestHandler srvExceptionListener = (ExceptionListenerTestHandler) lastSrvConnPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
// hook in to key places in the client pipeline
ChannelPipeline clientPipeline = clientConn.getChannel().getPipeline();
final ExceptionListenerTestHandler clientExceptionListener = (ExceptionListenerTestHandler) clientPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
// System.err.println("Current thread: " + Thread.currentThread());
// send a request in a separate thread because the client will intentionally block to simulate
// a timeout
final ChannelBuffer msg = ChannelBuffers.wrappedBuffer("hello".getBytes(Charset.defaultCharset()));
Thread sendThread1 = new Thread(new Runnable() {
@Override
public void run() {
// System.err.println(Thread.currentThread().toString() + ": sending message");
clientConn.getChannel().write(msg);
}
}, "send msg thread");
sendThread1.start();
// System.err.println(Thread.currentThread().toString() + ": waiting for 10");
try {
Thread.sleep(50);
} catch (InterruptedException ie) {
}
;
// System.err.println(Thread.currentThread().toString() + ": done Waiting for 10");
// make sure the server has not received the message
Assert.assertNull(srvExceptionListener.getLastException(), "no server errors");
Assert.assertNull(clientExceptionListener.getLastException(), "no errors yet");
Assert.assertTrue(!"hello".equals(srvMsgReader.getMsg()), "message not read yet");
// wait for the write timeout
try {
Thread.sleep(300);
} catch (InterruptedException ie) {
}
;
// System.err.println("Done Waiting for 300");
// the client should have timed out and closed the connection
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return null != clientExceptionListener.getLastException();
}
}, "client error", 1000, null);
Assert.assertTrue(null != clientExceptionListener.getLastException(), "client error");
Assert.assertTrue(clientExceptionListener.getLastException() instanceof ClosedChannelException || clientExceptionListener.getLastException() instanceof WriteTimeoutException, "client error test");
Assert.assertTrue(!lastSrvConnPipeline.getChannel().isConnected(), "client has disconnected");
Assert.assertTrue(!clientPipeline.getChannel().isConnected(), "closed connection to server");
}
Aggregations