Search in sources :

Example 6 with SimpleTestServerConnection

use of com.linkedin.databus2.test.container.SimpleTestServerConnection in project databus by linkedin.

the class TestHttpResponseProcessor method setUpClass.

@BeforeClass
public void setUpClass() {
    TestUtil.setupLoggingWithTimestampedFile(true, "/tmp/TestGenericHttpResponseHandler_", ".log", Level.INFO);
    InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
    _dummyServer = new SimpleTestServerConnection(ByteOrder.BIG_ENDIAN, SimpleTestServerConnection.ServerType.NIO);
    _dummyServer.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new HttpServerCodec());
        }
    });
    _dummyServer.start(SERVER_ADDRESS_ID);
    _logLevel = org.apache.log4j.Level.INFO;
}
Also used : SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) HttpServerCodec(org.jboss.netty.handler.codec.http.HttpServerCodec) Log4JLoggerFactory(org.jboss.netty.logging.Log4JLoggerFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) DatabusException(com.linkedin.databus2.core.DatabusException) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with SimpleTestServerConnection

use of com.linkedin.databus2.test.container.SimpleTestServerConnection in project databus by linkedin.

the class TestNettyHttpDatabusBootstrapConnection method setUpClass.

@BeforeClass
public void setUpClass() throws InvalidConfigException {
    TestUtil.setupLoggingWithTimestampedFile(true, "/tmp/TestNettyHttpDatabusBootstrapConnection_", ".log", Level.INFO);
    InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
    _dummyServer = new SimpleTestServerConnection(new DbusEventV2Factory().getByteOrder(), SimpleTestServerConnection.ServerType.NIO);
    _dummyServer.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new LoggingHandler(InternalLogLevel.DEBUG), new HttpServerCodec(), new LoggingHandler(InternalLogLevel.DEBUG), new SimpleObjectCaptureHandler());
        }
    });
    _dummyServer.start(SERVER_ADDRESS_ID);
    DatabusHttpClientImpl.Config clientCfgBuilder = new DatabusHttpClientImpl.Config();
    clientCfgBuilder.getContainer().setReadTimeoutMs(DEFAULT_READ_TIMEOUT_MS);
    clientCfgBuilder.getContainer().setWriteTimeoutMs(DEFAULT_WRITE_TIMEOUT_MS);
    CONN_FACTORY = new NettyHttpConnectionFactory(BOSS_POOL, IO_POOL, null, NETWORK_TIMER, clientCfgBuilder.getContainer().getWriteTimeoutMs(), clientCfgBuilder.getContainer().getReadTimeoutMs(), clientCfgBuilder.getContainer().getBstReadTimeoutMs(), // protocolVersion
    4, MAX_EVENT_VERSION, TEST_CHANNELS_GROUP);
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SimpleObjectCaptureHandler(com.linkedin.databus2.test.container.SimpleObjectCaptureHandler) HttpServerCodec(org.jboss.netty.handler.codec.http.HttpServerCodec) Log4JLoggerFactory(org.jboss.netty.logging.Log4JLoggerFactory) DbusEventV2Factory(com.linkedin.databus.core.DbusEventV2Factory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) BeforeClass(org.testng.annotations.BeforeClass)

Example 8 with SimpleTestServerConnection

use of com.linkedin.databus2.test.container.SimpleTestServerConnection in project databus by linkedin.

the class TestDatabusV2ClusterRegistrationImpl method setUpClass.

@BeforeClass
public void setUpClass() throws InvalidConfigException {
    //setup logging
    TestUtil.setupLogging(true, null, Level.INFO);
    InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
    //initialize relays
    for (int relayN = 0; relayN < RELAY_PORT.length; ++relayN) {
        _dummyServer[relayN] = new SimpleTestServerConnection(new DbusEventV2Factory().getByteOrder(), SimpleTestServerConnection.ServerType.NIO);
        _dummyServer[relayN].setPipelineFactory(new ChannelPipelineFactory() {

            @Override
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new LoggingHandler(InternalLogLevel.DEBUG), new HttpServerCodec(), new LoggingHandler(InternalLogLevel.DEBUG), new SimpleObjectCaptureHandler());
            }
        });
        _dummyServer[relayN].start(RELAY_PORT[relayN]);
    }
    //create standard client config
    DatabusHttpClientImpl.Config clientCfgBuilder = new DatabusHttpClientImpl.Config();
    clientCfgBuilder.getContainer().setHttpPort(CLIENT_PORT);
    clientCfgBuilder.getContainer().getJmx().setRmiEnabled(false);
    clientCfgBuilder.getContainer().setReadTimeoutMs(10000000);
    clientCfgBuilder.getConnectionDefaults().getPullerRetries().setInitSleep(10);
    clientCfgBuilder.getRuntime().getBootstrap().setEnabled(false);
    clientCfgBuilder.getCheckpointPersistence().setClearBeforeUse(true);
    for (int i = 0; i < RELAY_PORT.length; ++i) {
        clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setHost("localhost");
        clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setPort(RELAY_PORT[i]);
        clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setSources(SOURCE1_NAME);
    }
    _stdClientCfgBuilder = clientCfgBuilder;
    _stdClientCfg = clientCfgBuilder.build();
    //create standard relay buffer config
    DbusEventBuffer.Config bufCfgBuilder = new DbusEventBuffer.Config();
    bufCfgBuilder.setAllocationPolicy(AllocationPolicy.HEAP_MEMORY.toString());
    bufCfgBuilder.setMaxSize(100000);
    bufCfgBuilder.setScnIndexSize(128);
    bufCfgBuilder.setAverageEventSize(1);
    _bufCfg = bufCfgBuilder.build();
}
Also used : LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer) SimpleObjectCaptureHandler(com.linkedin.databus2.test.container.SimpleObjectCaptureHandler) HttpServerCodec(org.jboss.netty.handler.codec.http.HttpServerCodec) Log4JLoggerFactory(org.jboss.netty.logging.Log4JLoggerFactory) DbusEventV2Factory(com.linkedin.databus.core.DbusEventV2Factory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with SimpleTestServerConnection

use of com.linkedin.databus2.test.container.SimpleTestServerConnection in project databus by linkedin.

the class SimpleClientPipelineFactory method testServerSimpleRequestTimeout.

@Test
public /**
   * Simulates the follow communication with no request timeout
   *
   * <table>
   * <th><td>client</td><td>server</td></th>
   * <tr><td>send "hello"</td><td></td></tr>
   * <tr><td></td><td>start read timeout</td></tr>
   * <tr><td>induce timeout</td><td></td></tr>
   * <tr><td>generate read timeout</td><td></td></tr>
   * <tr><td></td><td>disconnect client</td></tr>
   * <tr><td>send "eom"</td><td></td></tr>
   * <tr><td>detect it has been disconnected</td><td></td></tr>
   * </table>
   */
void testServerSimpleRequestTimeout() {
    SimpleTestServerConnection srvConn = new SimpleTestServerConnection(_eventFactory.getByteOrder());
    srvConn.setPipelineFactory(new SimpleServerPipelineFactory());
    boolean serverStarted = srvConn.startSynchronously(3, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(serverStarted, "server started");
    SimpleTestClientConnection clientConn = new SimpleTestClientConnection(_eventFactory.getByteOrder());
    clientConn.setPipelineFactory(new SimpleClientPipelineFactory());
    boolean clientConnected = clientConn.startSynchronously(3, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(clientConnected, "client connected");
    //hook in to key places in the server pipeline
    ChannelPipeline lastSrvConnPipeline = srvConn.getLastConnChannel().getPipeline();
    ExtendedReadTimeoutHandler srvTimeoutHandler = (ExtendedReadTimeoutHandler) lastSrvConnPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    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();
    ExtendedReadTimeoutHandler clientTimeoutHandler = (ExtendedReadTimeoutHandler) clientPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    ExceptionListenerTestHandler clientExceptionListener = (ExceptionListenerTestHandler) clientPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
    //send a request
    ChannelBuffer msg = ChannelBuffers.wrappedBuffer("hello".getBytes(Charset.defaultCharset()));
    ChannelFuture writeFuture = clientConn.getChannel().write(msg);
    //wait for the request to propagate
    try {
        writeFuture.await(10);
    } catch (InterruptedException ie) {
    }
    ;
    Assert.assertTrue(writeFuture.isDone(), "write completed");
    Assert.assertTrue(writeFuture.isSuccess(), "write successful");
    Assert.assertNull(srvExceptionListener.getLastException(), "no server read timeout");
    Assert.assertNull(clientExceptionListener.getLastException(), "no client read timeout");
    Assert.assertEquals(srvMsgReader.getMsg(), "hello", "message read");
    //start server read timeout
    srvTimeoutHandler.start(lastSrvConnPipeline.getContext(srvTimeoutHandler));
    //Timeout
    try {
        Thread.sleep(300);
    } catch (InterruptedException ie) {
    }
    ;
    ChannelBuffer msg2 = ChannelBuffers.wrappedBuffer("eom".getBytes(Charset.defaultCharset()));
    writeFuture = clientConn.getChannel().write(msg2);
    //wait for the respomse to propagate
    try {
        writeFuture.await(10);
    } catch (InterruptedException ie) {
    }
    ;
    //start the client timeout handler
    clientTimeoutHandler.start(clientPipeline.getContext(clientTimeoutHandler));
    Assert.assertTrue(srvExceptionListener.getLastException() instanceof ReadTimeoutException, "server read timeout");
    Assert.assertTrue(clientExceptionListener.getLastException() instanceof ClosedChannelException, "failed write");
    Assert.assertTrue(!lastSrvConnPipeline.getChannel().isConnected(), "client has been disconnected");
    Assert.assertTrue(!clientPipeline.getChannel().isConnected(), "disconnected from server");
    //stop server read timeout
    srvTimeoutHandler.stop();
    //stop client read timeout
    clientTimeoutHandler.stop();
    clientConn.stop();
    srvConn.stop();
}
Also used : SimpleTestClientConnection(com.linkedin.databus2.test.container.SimpleTestClientConnection) ChannelFuture(org.jboss.netty.channel.ChannelFuture) ClosedChannelException(java.nio.channels.ClosedChannelException) SimpleTestMessageReader(com.linkedin.databus2.test.container.SimpleTestMessageReader) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) ExceptionListenerTestHandler(com.linkedin.databus2.test.container.ExceptionListenerTestHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.testng.annotations.Test)

Example 10 with SimpleTestServerConnection

use of com.linkedin.databus2.test.container.SimpleTestServerConnection in project databus by linkedin.

the class SimpleClientPipelineFactory method testServerSimpleResponseTimeout.

@Test
public /**
   * Simulates the follow communication with no request timeout
   *
   * <table>
   * <th><td>client</td><td>server</td></th>
   * <tr><td>send "hello"</td><td></td></tr>
   * <tr><td></td><td>start read timeout</td></tr>
   * <tr><td>generate read timeout</td><td></td></tr>
   * <tr><td></td><td>induce timeout</td></tr>
   * <tr><td>disconnect from server</td><td></td></tr>
   * <tr><td></td><td>send "hi there"</td></tr>
   * <tr><td></td><td>detect it has been disconnected</td></tr>
   * </table>
   */
void testServerSimpleResponseTimeout() {
    SimpleTestServerConnection srvConn = new SimpleTestServerConnection(_eventFactory.getByteOrder());
    srvConn.setPipelineFactory(new SimpleServerPipelineFactory());
    boolean serverStarted = srvConn.startSynchronously(4, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(serverStarted, "server started");
    SimpleTestClientConnection clientConn = new SimpleTestClientConnection(_eventFactory.getByteOrder());
    clientConn.setPipelineFactory(new SimpleClientPipelineFactory());
    boolean clientConnected = clientConn.startSynchronously(4, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(clientConnected, "client connected");
    //hook in to key places in the server pipeline
    ChannelPipeline lastSrvConnPipeline = srvConn.getLastConnChannel().getPipeline();
    ExtendedReadTimeoutHandler srvTimeoutHandler = (ExtendedReadTimeoutHandler) lastSrvConnPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    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();
    ExtendedReadTimeoutHandler clientTimeoutHandler = (ExtendedReadTimeoutHandler) clientPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    ExceptionListenerTestHandler clientExceptionListener = (ExceptionListenerTestHandler) clientPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
    //send a request
    ChannelBuffer msg = ChannelBuffers.wrappedBuffer("hello".getBytes(Charset.defaultCharset()));
    clientConn.getChannel().write(msg);
    //wait for the request to propagate
    try {
        Thread.sleep(10);
    } catch (InterruptedException ie) {
    }
    ;
    Assert.assertNull(srvExceptionListener.getLastException(), "no server read timeout");
    Assert.assertNull(clientExceptionListener.getLastException(), "no client read timeout");
    Assert.assertEquals(srvMsgReader.getMsg(), "hello", "message read");
    //start server read timeout
    srvTimeoutHandler.start(lastSrvConnPipeline.getContext(srvTimeoutHandler));
    ChannelBuffer msg2 = ChannelBuffers.wrappedBuffer("eom".getBytes(Charset.defaultCharset()));
    clientConn.getChannel().write(msg2);
    //start the client timeout handler
    clientTimeoutHandler.start(clientPipeline.getContext(clientTimeoutHandler));
    Assert.assertNull(srvExceptionListener.getLastException(), "no server read timeout");
    Assert.assertNull(clientExceptionListener.getLastException(), "no client read timeout");
    Assert.assertEquals(srvMsgReader.getMsg(), "eom", "message read");
    //stop server read timeout
    srvTimeoutHandler.stop();
    ChannelBuffer resp = ChannelBuffers.wrappedBuffer("hi there".getBytes(Charset.defaultCharset()));
    //Induce timeout
    try {
        Thread.sleep(500);
    } catch (InterruptedException ie) {
    }
    ;
    lastSrvConnPipeline.getChannel().write(resp);
    //wait for the response to propagate
    try {
        Thread.sleep(10);
    } catch (InterruptedException ie) {
    }
    ;
    Assert.assertTrue(srvExceptionListener.getLastException() instanceof ClosedChannelException, "no server read timeout but client has disconnected");
    Assert.assertTrue(clientExceptionListener.getLastException() instanceof ReadTimeoutException, "client read timeout");
    Assert.assertTrue(!lastSrvConnPipeline.getChannel().isConnected(), "client has disconnected");
    Assert.assertTrue(!clientPipeline.getChannel().isConnected(), "closed connection to server");
    //stop client read timeout
    clientTimeoutHandler.stop();
    clientConn.stop();
    srvConn.stop();
}
Also used : SimpleTestClientConnection(com.linkedin.databus2.test.container.SimpleTestClientConnection) ClosedChannelException(java.nio.channels.ClosedChannelException) SimpleTestMessageReader(com.linkedin.databus2.test.container.SimpleTestMessageReader) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) ExceptionListenerTestHandler(com.linkedin.databus2.test.container.ExceptionListenerTestHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.testng.annotations.Test)

Aggregations

SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)17 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)17 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)11 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)11 Test (org.testng.annotations.Test)11 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)10 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)9 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)8 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)8 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)8 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)8 Checkpoint (com.linkedin.databus.core.Checkpoint)7 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)7 NettyHttpDatabusRelayConnection (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection)6 NettyHttpDatabusRelayConnectionInspector (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnectionInspector)6 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)6 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)6 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)6 InetSocketAddress (java.net.InetSocketAddress)6 SocketAddress (java.net.SocketAddress)6