Search in sources :

Example 16 with DefaultHttpChunk

use of org.jboss.netty.handler.codec.http.DefaultHttpChunk in project databus by linkedin.

the class DummyRemoteExceptionHandler method runServerPartialStreamTimeoutIteration.

private void runServerPartialStreamTimeoutIteration(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);
    //Trigger a read timeout
    TestUtil.sleep(DEFAULT_READ_TIMEOUT_MS + 100);
    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 17 with DefaultHttpChunk

use of org.jboss.netty.handler.codec.http.DefaultHttpChunk in project databus by linkedin.

the class TestResponseProcessors method testStartSCNHappyPathChunked.

@Test
public void testStartSCNHappyPathChunked() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    DefaultHttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    TestRemoteExceptionHandler remoteExHandler = new TestRemoteExceptionHandler();
    Checkpoint cp = new Checkpoint();
    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    BootstrapStartScnHttpResponseProcessor processor = new BootstrapStartScnHttpResponseProcessor(null, queue, stateMsg, cp, remoteExHandler, null);
    ChannelBuffer buf = getScnResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.finishResponse();
    Assert.assertEquals("Error Handled", false, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.STARTSCN_RESPONSE_SUCCESS, gotMsg._state);
    Assert.assertEquals("StartSCN Response Id Check", new Long(5678912), cp.getBootstrapStartScn());
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Example 18 with DefaultHttpChunk

use of org.jboss.netty.handler.codec.http.DefaultHttpChunk in project databus by linkedin.

the class TestResponseProcessors method testSourceExceptionAfterStartCase2.

@Test
public void testSourceExceptionAfterStartCase2() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage> processor = new SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage>(null, queue, stateMsg, null);
    ChannelBuffer buf = getSourcesResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.channelException(new Exception("dummy exception"));
    processor.addTrailer(httpChunkTrailer);
    processor.finishResponse();
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.SOURCES_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No More CHunks", true, (null == stateMsg._sourcesResponse));
}
Also used : DatabusRelayConnectionStateMessage(com.linkedin.databus.client.DatabusRelayConnectionStateMessage) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Example 19 with DefaultHttpChunk

use of org.jboss.netty.handler.codec.http.DefaultHttpChunk in project databus by linkedin.

the class TestResponseProcessors method testStreamExceptionAfterStartCase3.

@Test
public void testStreamExceptionAfterStartCase3() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    StreamHttpResponseProcessor processor = new StreamHttpResponseProcessor(null, queue, stateMsg, null);
    ChannelBuffer buf = HeapChannelBufferFactory.getInstance().getBuffer(100);
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.channelException(new Exception("dummy exception"));
    processor.finishResponse();
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.STREAM_RESPONSE_SUCCESS, gotMsg._state);
    Assert.assertEquals("No More CHunks", true, stateMsg._channel.hasNoMoreChunks());
}
Also used : DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Example 20 with DefaultHttpChunk

use of org.jboss.netty.handler.codec.http.DefaultHttpChunk in project databus by linkedin.

the class TestResponseProcessors method testRegisterExceptionAfterStartCase3.

@Test
public void testRegisterExceptionAfterStartCase3() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    RegisterHttpResponseProcessor processor = new RegisterHttpResponseProcessor(null, queue, stateMsg, null);
    ChannelBuffer buf = getRegisterResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.channelException(new Exception("dummy exception"));
    processor.finishResponse();
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.REGISTER_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No More CHunks", true, (null == stateMsg._registerResponse));
}
Also used : DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Aggregations

DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)57 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)53 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)52 Test (org.testng.annotations.Test)46 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)45 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)43 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)38 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)34 Checkpoint (com.linkedin.databus.core.Checkpoint)26 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)15 InetSocketAddress (java.net.InetSocketAddress)15 SocketAddress (java.net.SocketAddress)15 Channel (org.jboss.netty.channel.Channel)15 Logger (org.apache.log4j.Logger)12 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)9 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)9 RegisterResponseEntry (com.linkedin.databus2.core.container.request.RegisterResponseEntry)8 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)7 DatabusRelayConnectionStateMessage (com.linkedin.databus.client.DatabusRelayConnectionStateMessage)6