Search in sources :

Example 6 with DatabusRelayConnectionStateMessage

use of com.linkedin.databus.client.DatabusRelayConnectionStateMessage in project databus by linkedin.

the class TestResponseProcessors method testSourceExceptionAfterFinishResponse.

@Test
public void testSourceExceptionAfterFinishResponse() 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.addTrailer(httpChunkTrailer);
    processor.finishResponse();
    processor.channelException(new Exception("dummy exception"));
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_EXCEPTION, 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_SUCCESS, gotMsg._state);
    Assert.assertEquals("Register Response Id Check", 1, stateMsg._sourcesResponse.size());
    Assert.assertEquals("Register Response Id Check", new Long(301), stateMsg._sourcesResponse.get(0).getId());
}
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 7 with DatabusRelayConnectionStateMessage

use of com.linkedin.databus.client.DatabusRelayConnectionStateMessage in project databus by linkedin.

the class TestResponseProcessors method testSourceHappyPathNonChunked.

@Test
public void testSourceHappyPathNonChunked() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    DefaultHttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage> processor = new SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage>(null, queue, stateMsg, null);
    ChannelBuffer buf = getSourcesResponse();
    httpResponse.setContent(buf);
    httpResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "1000");
    processor.startResponse(httpResponse);
    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));
    System.out.println("Long Max is :" + Long.MAX_VALUE);
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.SOURCES_SUCCESS, gotMsg._state);
    Assert.assertEquals("Register Response Id Check", 1, stateMsg._sourcesResponse.size());
    Assert.assertEquals("Register Response Id Check", new Long(301), stateMsg._sourcesResponse.get(0).getId());
}
Also used : DatabusRelayConnectionStateMessage(com.linkedin.databus.client.DatabusRelayConnectionStateMessage) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.testng.annotations.Test)

Example 8 with DatabusRelayConnectionStateMessage

use of com.linkedin.databus.client.DatabusRelayConnectionStateMessage in project databus by linkedin.

the class TestResponseProcessors method testSourceExceptionAtStart.

@Test
public void testSourceExceptionAtStart() 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.channelException(new Exception("dummy exception"));
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    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 9 with DatabusRelayConnectionStateMessage

use of com.linkedin.databus.client.DatabusRelayConnectionStateMessage in project databus by linkedin.

the class StreamHttpResponseProcessor method onSourcesConnectSuccess.

void onSourcesConnectSuccess() {
    _curState = State.SOURCES_REQUEST_WRITE;
    ChannelPipeline channelPipeline = _channel.getPipeline();
    _readTimeOutHandler = (ExtendedReadTimeoutHandler) channelPipeline.get(GenericHttpClientPipelineFactory.READ_TIMEOUT_HANDLER_NAME);
    _readTimeOutHandler.start(channelPipeline.getContext(_readTimeOutHandler));
    SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage> sourcesResponseProcessor = new SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage>(this, _callback, _callbackStateReuse, _readTimeOutHandler);
    String uriString = "/sources?" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=" + getProtocolVersion();
    LOG.info("Sending " + uriString);
    // Prepare the HTTP request.
    HttpRequest request = createEmptyRequest(uriString);
    sendRequest(request, new SourcesRequestResultListener(), sourcesResponseProcessor);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DatabusRelayConnectionStateMessage(com.linkedin.databus.client.DatabusRelayConnectionStateMessage) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

DatabusRelayConnectionStateMessage (com.linkedin.databus.client.DatabusRelayConnectionStateMessage)9 Test (org.testng.annotations.Test)8 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)7 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)7 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)6 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)6 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)6 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)6 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)6 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)5 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)1