Package com.linkedin.databus2.test.container

Examples of com.linkedin.databus2.test.container.SimpleTestServerConnection


    //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();

    //wait for the request to propagate
    //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");

    //System.err.println("Waiting for 300");
    //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");

  }
View Full Code Here


    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();

    //wait for the request to propagate
View Full Code Here

    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();

    //wait for the request to propagate
    //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");

    //System.err.println("Waiting for 300");
    //wait for the write timeout
    try {Thread.sleep(300);} catch (InterruptedException ie){};
    //System.err.println("Done Waiting for 300");
View Full Code Here

  {
    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());
View Full Code Here

  @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());
View Full Code Here

  {
    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),
View Full Code Here

    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),
View Full Code Here

    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),
View Full Code Here

    InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());

    //initialize relays
    for (int relayN = 0; relayN < RELAY_PORT.length; ++relayN)
    {
      _dummyServer[relayN] = new SimpleTestServerConnection(_eventFactory.getByteOrder(),
                                                            SimpleTestServerConnection.ServerType.NIO);
      _dummyServer[relayN].setPipelineFactory(new ChannelPipelineFactory() {
          @Override
          public ChannelPipeline getPipeline() throws Exception {
              return Channels.pipeline(new LoggingHandler(InternalLogLevel.DEBUG),
View Full Code Here

          InetSocketAddress relayAddr = (InetSocketAddress)clientChannel.getRemoteAddress();
          SocketAddress clientAddr = clientChannel.getLocalAddress();
          int relayPort = relayAddr.getPort();
          log.info("relay selected: " + relayPort);

          SimpleTestServerConnection relay = null;
          for (int i = 0; i < RELAY_PORT.length; ++i)
          {
            if (relayPort == RELAY_PORT[i]) relay = _dummyServer[i];
          }
          assertTrue(null != relay);

          final SocketAddress testClientAddr = clientAddr;
          final SimpleTestServerConnection testRelay = relay;
          TestUtil.assertWithBackoff(new ConditionCheck()
          {
            @Override
            public boolean check()
            {
              return null != testRelay.getChildChannel(testClientAddr);
            }
          }, "relay detects new connection", 1000, log);

          Channel serverChannel = relay.getChildChannel(clientAddr);
          assertTrue(null != serverChannel);
View Full Code Here

TOP

Related Classes of com.linkedin.databus2.test.container.SimpleTestServerConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.