use of com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture in project pinot by linkedin.
the class NettySingleConnectionIntegrationTest method testSingleLargeRequestResponse.
@Test
public /**
* Test Single Large ( 2 MB) request response
* @throws Exception
*/
void testSingleLargeRequestResponse() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
final String response_prefix = "response_";
final String response = generatePayload(response_prefix, 1024 * 1024 * 2);
MyServer server = new MyServer(response);
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);
String request_prefix = "request_";
String request = generatePayload(request_prefix, 1024 * 1024 * 2);
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.assertTrue(gotResponse.equals(response), "Response Check at client");
Assert.assertTrue(server.getHandler().getRequest().equals(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 testConcurrentRequestDispatchError.
@Test
public void testConcurrentRequestDispatchError() 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);
boolean gotException = false;
try {
clientConn.sendRequest(Unpooled.wrappedBuffer(request.getBytes()), 1L, 5000L);
} catch (IllegalStateException ex) {
gotException = true;
// Second request should have failed.
LOGGER.info("got exception ", ex);
}
latch.countDown();
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");
clientConn.close();
server.shutdown();
Assert.assertTrue(gotException, "GotException ");
}
use of com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture in project pinot by linkedin.
the class NettySingleConnectionIntegrationTest method test100LargeRequestResponses.
//@Test
//@Ignore
/**
* Send 100 large ( 2MB) sized request in sequence. Verify each request and response.
* @throws Exception
*/
//@Test
public void test100LargeRequestResponses() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
MyServer server = new MyServer(null);
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);
try {
for (int i = 0; i < 100; i++) {
String request_prefix = "request_";
String request = generatePayload(request_prefix, 1024 * 1024 * 20);
String response_prefix = "response_";
String response = generatePayload(response_prefix, 1024 * 1024 * 20);
server.getHandler().setResponse(response);
//LOG.info("Sending the request (" + request + ")");
ResponseFuture serverRespFuture = clientConn.sendRequest(Unpooled.wrappedBuffer(request.getBytes()), 1L, 5000L);
//LOG.info("Request sent !!");
ByteBuf serverResp = serverRespFuture.getOne();
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 NettyCloseChannelTest method testCloseClientChannel.
@Test
public /**
* Client sends a request. Before Server generates the response, the client closes the channel (scenario:as the client is shutting down)
*/
void testCloseClientChannel() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
Timer timer = new HashedWheelTimer();
String response = "dummy response";
int port = 9089;
CountDownLatch latch = new CountDownLatch(1);
MyRequestHandler handler = new MyRequestHandler(response, latch);
MyRequestHandlerFactory handlerFactory = new MyRequestHandlerFactory(handler);
NettyTCPServer serverConn = new NettyTCPServer(port, handlerFactory, null);
Thread serverThread = new Thread(serverConn, "ServerMain");
serverThread.start();
Thread.sleep(1000);
ServerInstance server = new ServerInstance("localhost", port);
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
NettyTCPClientConnection clientConn = new NettyTCPClientConnection(server, eventLoopGroup, timer, metric);
LOGGER.debug("About to connect the client !!");
boolean connected = clientConn.connect();
LOGGER.debug("Client connected !!");
Assert.assertTrue(connected, "connected");
Thread.sleep(1000);
String request = "dummy request";
LOGGER.debug("Sending the request !!");
ResponseFuture serverRespFuture = clientConn.sendRequest(Unpooled.wrappedBuffer(request.getBytes()), 1L, 5000L);
//Close the client
clientConn.close();
latch.countDown();
ByteBuf serverResp = serverRespFuture.getOne();
clientConn.close();
serverConn.shutdownGracefully();
Assert.assertNull(serverResp);
Assert.assertFalse(serverRespFuture.isCancelled(), "Is Cancelled");
Assert.assertTrue(serverRespFuture.getError() != null, "Got Exception");
serverConn.shutdownGracefully();
LOGGER.trace("metrics: {}", metric);
}
use of com.linkedin.pinot.transport.netty.NettyClientConnection.ResponseFuture in project pinot by linkedin.
the class NettyCloseChannelTest method testCloseServerChannel.
@Test
public /**
* Client sends a request. Server closes the channel ( scenario: as it is shutting down)
*/
void testCloseServerChannel() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
Timer timer = new HashedWheelTimer();
int port = 9089;
MyRequestHandler handler = new MyRequestHandler("empty", null);
MyRequestHandlerFactory handlerFactory = new MyRequestHandlerFactory(handler);
NettyTCPServer serverConn = new NettyCloseTCPServer(port, handlerFactory);
Thread serverThread = new Thread(serverConn, "ServerMain");
serverThread.start();
Thread.sleep(1000);
ServerInstance server = new ServerInstance("localhost", port);
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
NettyTCPClientConnection clientConn = new NettyTCPClientConnection(server, eventLoopGroup, timer, 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);
ByteBuf serverResp = serverRespFuture.getOne();
clientConn.close();
serverConn.shutdownGracefully();
Assert.assertNull(serverResp);
Assert.assertFalse(serverRespFuture.isCancelled(), "Is Cancelled");
Assert.assertTrue(serverRespFuture.getError() != null, "Got Exception");
LOGGER.trace("metrics: {}", metric);
}
Aggregations