Search in sources :

Example 16 with SimpleObjectCaptureHandler

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

the class DummyRemoteExceptionHandler method runServerSourcesDisconnectIteration.

private void runServerSourcesDisconnectIteration(final Logger log, TestingConnectionCallback callback, DummyRemoteExceptionHandler remoteExceptionHandler, final NettyHttpDatabusRelayConnection conn) {
    //connect to server and send /sources
    TestResponseProcessors.TestConnectionStateMessage msg = new TestResponseProcessors.TestConnectionStateMessage();
    conn.requestSources(msg);
    waitForServerConnection(conn, log);
    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();
    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler) serverPipeline.get("3");
    Assert.assertTrue(objCapture.waitForMessage(1000, 0));
    Object msgObj = objCapture.getMessages().get(0);
    Assert.assertTrue(msgObj instanceof HttpRequest);
    HttpRequest msgReq = (HttpRequest) msgObj;
    // now has "?protocolVersion=X" appended
    Assert.assertTrue(msgReq.getUri().startsWith("/sources"));
    serverChannel.close();
    waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.SOURCES_RESPONSE_ERROR, log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
    Assert.assertEquals(1, callback.getAllMsgs().size());
    callback.clearLastMsg();
    objCapture.clear();
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) SimpleObjectCaptureHandler(com.linkedin.databus2.test.container.SimpleObjectCaptureHandler) Channel(org.jboss.netty.channel.Channel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 17 with SimpleObjectCaptureHandler

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

the class DummyRemoteExceptionHandler method runServerPartialStreamIteration.

private void runServerPartialStreamIteration(final Logger log, DbusEventBuffer buf, TestingConnectionCallback callback, DummyRemoteExceptionHandler remoteExceptionHandler, final NettyHttpDatabusRelayConnection conn) throws JsonGenerationException, JsonMappingException, IOException, ScnNotFoundException, OffsetNotFoundException {
    //connect to server and send /sources
    TestResponseProcessors.TestConnectionStateMessage msg = new TestResponseProcessors.TestConnectionStateMessage();
    conn.requestSources(msg);
    waitForServerConnection(conn, log);
    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();
    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler) serverPipeline.get("3");
    //verify server gets the /source request
    HttpResponse sourcesResp = runHappyPathSources(log, callback, remoteExceptionHandler, clientAddr, objCapture);
    //send /register
    runHappyPathRegister(log, callback, remoteExceptionHandler, conn, msg, clientAddr, objCapture, sourcesResp);
    //send partial /stream
    callback.clearLastMsg();
    objCapture.clear();
    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    CheckpointMult cpm = new CheckpointMult();
    cpm.addCheckpoint(PhysicalPartition.ANY_PHYSICAL_PARTITION, cp);
    conn.requestStream("1", null, 1000, cpm, null, msg);
    //////// verify server gets the /stream request
    HttpRequest msgReq = captureRequest(objCapture);
    Assert.assertTrue(msgReq.getUri().startsWith("/stream"));
    ////// send back some partial response
    ChannelBuffer tmpBuf = NettyTestUtils.streamToChannelBuffer(buf, cp, 10000, null);
    _dummyServer.sendServerResponse(clientAddr, sourcesResp, 1000);
    _dummyServer.sendServerResponse(clientAddr, new DefaultHttpChunk(tmpBuf), 1000);
    serverChannel.close();
    waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.STREAM_RESPONSE_SUCCESS, log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
    Assert.assertEquals(1, callback.getAllMsgs().size());
    callback.clearLastMsg();
    objCapture.clear();
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) CheckpointMult(com.linkedin.databus.core.CheckpointMult) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) Channel(org.jboss.netty.channel.Channel) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Checkpoint(com.linkedin.databus.core.Checkpoint) SimpleObjectCaptureHandler(com.linkedin.databus2.test.container.SimpleObjectCaptureHandler) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 18 with SimpleObjectCaptureHandler

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

the class DummyRemoteExceptionHandler method runServerRegisterDisconnectIteration.

private void runServerRegisterDisconnectIteration(final Logger log, TestingConnectionCallback callback, DummyRemoteExceptionHandler remoteExceptionHandler, final NettyHttpDatabusRelayConnection conn) throws JsonGenerationException, JsonMappingException, IOException, ScnNotFoundException, OffsetNotFoundException {
    //connect to server and send /sources
    TestResponseProcessors.TestConnectionStateMessage msg = new TestResponseProcessors.TestConnectionStateMessage();
    conn.requestSources(msg);
    waitForServerConnection(conn, log);
    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();
    final SocketAddress finalClientAddr = clientAddr;
    TestUtil.assertWithBackoff(new ConditionCheck() {

        @Override
        public boolean check() {
            return _dummyServer.getChildChannel(finalClientAddr) != null;
        }
    }, "client connected", 100, log);
    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler) serverPipeline.get("3");
    //verify server gets the /source request
    runHappyPathSources(log, callback, remoteExceptionHandler, clientAddr, objCapture);
    callback.clearLastMsg();
    objCapture.clear();
    conn.requestRegister("1", msg);
    //verify server gets the /register request
    HttpRequest msgReq = captureRequest(objCapture);
    Assert.assertTrue(msgReq.getUri().startsWith("/register"));
    serverChannel.close();
    waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.REGISTER_RESPONSE_ERROR, log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
    Assert.assertEquals(1, callback.getAllMsgs().size());
    callback.clearLastMsg();
    objCapture.clear();
}
Also used : ConditionCheck(com.linkedin.databus2.test.ConditionCheck) HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) SimpleObjectCaptureHandler(com.linkedin.databus2.test.container.SimpleObjectCaptureHandler) Channel(org.jboss.netty.channel.Channel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 19 with SimpleObjectCaptureHandler

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

the class DummyRemoteExceptionHandler method runHappyPathRegister.

private void runHappyPathRegister(final Logger log, TestingConnectionCallback callback, DummyRemoteExceptionHandler remoteExceptionHandler, final NettyHttpDatabusRelayConnection conn, TestResponseProcessors.TestConnectionStateMessage msg, SocketAddress clientAddr, SimpleObjectCaptureHandler objCapture, HttpResponse sourcesResp) throws JsonGenerationException, JsonMappingException, IOException {
    HttpRequest msgReq;
    HttpChunk body;
    objCapture.clear();
    conn.requestRegister("1", msg);
    //verify server gets the /register request
    msgReq = captureRequest(objCapture);
    Assert.assertTrue(msgReq.getUri().startsWith("/register"));
    //send back some response
    RegisterResponseEntry entry = new RegisterResponseEntry(1L, (short) 1, SOURCE1_SCHEMA_STR);
    String responseStr = NettyTestUtils.generateRegisterResponse(entry);
    body = new DefaultHttpChunk(ChannelBuffers.wrappedBuffer(responseStr.getBytes(Charset.defaultCharset())));
    NettyTestUtils.sendServerResponses(_dummyServer, clientAddr, sourcesResp, body);
    waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.REGISTER_SUCCESS, log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk)

Example 20 with SimpleObjectCaptureHandler

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

the class DummyRemoteExceptionHandler method runServerRegisterReqDisconnectIteration.

private void runServerRegisterReqDisconnectIteration(final Logger log, TestingConnectionCallback callback, DummyRemoteExceptionHandler remoteExceptionHandler, final NettyHttpDatabusRelayConnection conn) throws JsonGenerationException, JsonMappingException, IOException, ScnNotFoundException, OffsetNotFoundException {
    //connect to server and send /sources
    TestResponseProcessors.TestConnectionStateMessage msg = new TestResponseProcessors.TestConnectionStateMessage();
    conn.requestSources(msg);
    waitForServerConnection(conn, log);
    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();
    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler) serverPipeline.get("3");
    //verify server gets the /source request
    runHappyPathSources(log, callback, remoteExceptionHandler, clientAddr, objCapture);
    callback.clearLastMsg();
    objCapture.clear();
    serverChannel.close();
    conn.requestRegister("1", msg);
    waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.REGISTER_REQUEST_ERROR, log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
    Assert.assertEquals(1, callback.getAllMsgs().size());
    callback.clearLastMsg();
    objCapture.clear();
}
Also used : SimpleObjectCaptureHandler(com.linkedin.databus2.test.container.SimpleObjectCaptureHandler) Channel(org.jboss.netty.channel.Channel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)24 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)24 InetSocketAddress (java.net.InetSocketAddress)19 SocketAddress (java.net.SocketAddress)19 Channel (org.jboss.netty.channel.Channel)19 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)16 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)16 Checkpoint (com.linkedin.databus.core.Checkpoint)12 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)12 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)12 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)11 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)10 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)10 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)10 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)8 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)8 Logger (org.apache.log4j.Logger)7 NettyHttpDatabusRelayConnection (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnection)6 NettyHttpDatabusRelayConnectionInspector (com.linkedin.databus.client.netty.NettyHttpDatabusRelayConnectionInspector)6 DbusEventInfo (com.linkedin.databus.core.DbusEventInfo)6