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