use of com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture in project pinot by linkedin.
the class NettySingleConnectionIntegrationTest method testSingleSmallRequestResponse.
@Test
public /**
* Test Single small request response
* @throws Exception
*/
void testSingleSmallRequestResponse() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
Timer timer = new HashedWheelTimer();
MyServer server = new MyServer();
Thread.sleep(1000);
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
NettyTCPClientConnection clientConn = new NettyTCPClientConnection(server.getServerInstance(), eventLoopGroup, timer, metric);
try {
LOGGER.info("About to connect the client !!");
boolean connected = clientConn.connect();
LOGGER.info("Client connected !!");
Assert.assertTrue(connected, "connected");
Thread.sleep(1000);
String request = "dummy request";
LOGGER.info("Sending the request !!");
ResponseFuture serverRespFuture = clientConn.sendRequest(Unpooled.wrappedBuffer(request.getBytes()), 1L, 5000L);
LOGGER.info("Request sent !!");
ByteBuf serverResp = serverRespFuture.getOne();
byte[] b2 = new byte[serverResp.readableBytes()];
serverResp.readBytes(b2);
String gotResponse = new String(b2);
Assert.assertEquals(gotResponse, server.getResponseStr(), "Response Check at client");
Assert.assertEquals(server.getHandler().getRequest(), request, "Request Check at server");
// System.out.println(metric);
} finally {
if (null != clientConn) {
clientConn.close();
}
server.shutdown();
}
}
use of com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture in project pinot by linkedin.
the class NettySingleConnectionIntegrationTest method test10KSmallRequestResponses.
@Test
public /**
* Send 10K small sized request in sequence. Verify each request and response.
* @throws Exception
*/
void test10KSmallRequestResponses() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
MyServer server = new MyServer(null);
Thread.sleep(1000);
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
NettyTCPClientConnection clientConn = new NettyTCPClientConnection(server.getServerInstance(), eventLoopGroup, new HashedWheelTimer(), metric);
try {
LOGGER.info("About to connect the client !!");
boolean connected = clientConn.connect();
LOGGER.info("Client connected !!");
Assert.assertTrue(connected, "connected");
Thread.sleep(1000);
for (int i = 0; i < 10000; i++) {
String request = "dummy request :" + i;
String response = "dummy response :" + i;
server.getHandler().setResponse(response);
LOGGER.info("Sending the request (" + request + ")");
ResponseFuture serverRespFuture = clientConn.sendRequest(Unpooled.wrappedBuffer(request.getBytes()), 1L, 5000L);
LOGGER.info("Request sent !!");
ByteBuf serverResp = serverRespFuture.getOne();
if (null == serverResp) {
LOGGER.error("Got unexpected error while trying to get response.", serverRespFuture.getError());
}
byte[] b2 = new byte[serverResp.readableBytes()];
serverResp.readBytes(b2);
String gotResponse = new String(b2);
Assert.assertEquals(gotResponse, response, "Response Check at client");
Assert.assertEquals(server.getHandler().getRequest(), request, "Request Check at server");
}
} finally {
if (null != clientConn) {
clientConn.close();
}
server.shutdown();
}
}
use of com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture in project pinot by linkedin.
the class NettySingleConnectionIntegrationTest method testCancelOutstandingRequest.
@Test
public void testCancelOutstandingRequest() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
CountDownLatch latch = new CountDownLatch(1);
MyServer server = new MyServer();
Thread.sleep(1000);
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
NettyTCPClientConnection clientConn = new NettyTCPClientConnection(server.getServerInstance(), eventLoopGroup, new HashedWheelTimer(), metric);
LOGGER.info("About to connect the client !!");
boolean connected = clientConn.connect();
LOGGER.info("Client connected !!");
Assert.assertTrue(connected, "connected");
Thread.sleep(1000);
String request = "dummy request";
LOGGER.info("Sending the request !!");
ResponseFuture serverRespFuture = clientConn.sendRequest(Unpooled.wrappedBuffer(request.getBytes()), 1L, 5000L);
serverRespFuture.cancel(false);
latch.countDown();
ByteBuf serverResp = serverRespFuture.getOne();
Assert.assertNull(serverResp);
Assert.assertTrue(serverRespFuture.isCancelled(), "Is Cancelled");
clientConn.close();
server.shutdown();
}
Aggregations