use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.
the class TestDatabusRelayMain method testClient.
private void testClient(int relayPort, int fetchSize, long scn, HttpResponseHandler handler) throws Exception {
Checkpoint ckpt = Checkpoint.createOnlineConsumptionCheckpoint(scn);
//TODO why is this needed
//ckpt.setCatchupSource("foo");
String uristr = "/stream?sources=105&output=json&size=" + fetchSize + "&streamFromLatestScn=false&checkPoint=" + ckpt.toString();
ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new HttpClientPipelineFactory(handler));
ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", relayPort));
Channel channel = future.awaitUninterruptibly().getChannel();
Assert.assertTrue(future.isSuccess(), "Cannot connect to relay at localhost:" + relayPort);
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uristr);
request.setHeader(HttpHeaders.Names.HOST, "localhost");
channel.write(request);
channel.getCloseFuture().awaitUninterruptibly();
}
use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.
the class TestHttpResponseProcessor method testConnectFail.
@Test
public void testConnectFail() throws DatabusException {
Logger log = Logger.getLogger("GenericHttpResponseHandler.testConnectFail");
TestHttpResponseProcessor respProcessor = new TestHttpResponseProcessor(log);
TestConnectListener connectListener = new TestConnectListener(log);
TestSendRequestListener requestListener = new TestSendRequestListener(log);
TestCloseListener closeListener = new TestCloseListener(log);
//Need this call to set respProcessor without triggering erroneous check
final GenericHttpResponseHandler responseHandler = new GenericHttpResponseHandler(respProcessor, KeepAliveType.KEEP_ALIVE);
responseHandler.setRequestListener(requestListener);
responseHandler.setConnectionListener(connectListener);
responseHandler.setCloseListener(closeListener);
//use port 0 to generate connect fail
ChannelFuture channelFuture = createChannelFuture(responseHandler, 0);
Channel channel = channelFuture.getChannel();
try {
channel.write(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/test"));
final List<String> respCallbacks = respProcessor.getCallbacks();
final List<String> connectCallbacks = connectListener.getCallbacks();
final List<String> requestCallbacks = requestListener.getCallbacks();
final List<String> closeChannelCallbacks = closeListener.getCallbacks();
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return 1 == closeChannelCallbacks.size();
}
}, "waiting for close channel callback", 1000, null);
//make sure that no new callbacks have showed up
stateSanityCheck(connectCallbacks, requestCallbacks, respCallbacks, closeChannelCallbacks);
Assert.assertEquals(connectCallbacks.size(), 1);
Assert.assertEquals(connectCallbacks.get(0), "onConnectFailure");
Assert.assertEquals(closeChannelCallbacks.size(), 1);
Assert.assertEquals(closeChannelCallbacks.get(0), "onChannelClose");
} finally {
channel.close();
}
}
use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.
the class SimpleTestClientConnection method start.
public void start(final int serverAddr) {
_shutdownRequested = false;
_shutdown = false;
_connected = false;
_thread = new Thread(new Runnable() {
@Override
public void run() {
//System.err.println("Client running on thread: " + Thread.currentThread());
ChannelFuture connectFuture = _clientBootstrap.connect(new LocalAddress(serverAddr));
connectFuture.awaitUninterruptibly();
_channel = connectFuture.getChannel();
_lock.lock();
try {
_connected = connectFuture.isSuccess();
_connectedCondition.signalAll();
while (!_shutdownRequested) {
try {
_shutdownReqCondition.await();
} catch (InterruptedException ie) {
}
}
_shutdown = true;
_shutdownCondition.signalAll();
} finally {
_lock.unlock();
}
}
});
_thread.setDaemon(true);
_thread.start();
}
use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.
the class SimpleTestClientConnection method stop.
public void stop() {
_lock.lock();
try {
_shutdownRequested = true;
_shutdownReqCondition.signalAll();
while (!_shutdown) {
try {
_shutdownCondition.await();
} catch (InterruptedException ie) {
}
}
} finally {
_lock.unlock();
}
ChannelFuture closeFuture = _channel.close();
closeFuture.awaitUninterruptibly();
_clientBootstrap.releaseExternalResources();
}
use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.
the class SimpleDatabusResponse method writeToChannelAsBinary.
@Override
public void writeToChannelAsBinary(ChannelHandlerContext ctx, ChannelFuture future) {
ChannelFuture realFuture = (null != future) ? future : Channels.future(ctx.getChannel());
ChannelBuffer serializedResponse = serializeToBinary();
DownstreamMessageEvent e = new DownstreamMessageEvent(ctx.getChannel(), realFuture, serializedResponse, ctx.getChannel().getRemoteAddress());
ctx.sendDownstream(e);
}
Aggregations