use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class TestNettyHttpDatabusBootstrapConnection method setUpClass.
@BeforeClass
public void setUpClass() throws InvalidConfigException {
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), new HttpServerCodec(), new LoggingHandler(InternalLogLevel.DEBUG), new SimpleObjectCaptureHandler());
}
});
_dummyServer.start(SERVER_ADDRESS_ID);
DatabusHttpClientImpl.Config clientCfgBuilder = new DatabusHttpClientImpl.Config();
clientCfgBuilder.getContainer().setReadTimeoutMs(DEFAULT_READ_TIMEOUT_MS);
clientCfgBuilder.getContainer().setWriteTimeoutMs(DEFAULT_WRITE_TIMEOUT_MS);
CONN_FACTORY = new NettyHttpConnectionFactory(BOSS_POOL, IO_POOL, null, NETWORK_TIMER, clientCfgBuilder.getContainer().getWriteTimeoutMs(), clientCfgBuilder.getContainer().getReadTimeoutMs(), clientCfgBuilder.getContainer().getBstReadTimeoutMs(), // protocolVersion
4, MAX_EVENT_VERSION, TEST_CHANNELS_GROUP);
}
use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class DummyRemoteExceptionHandler method runServerStreamReadTimeoutIteration.
private void runServerStreamReadTimeoutIteration(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
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"));
//Trigger a read timeout
TestUtil.sleep(DEFAULT_READ_TIMEOUT_MS + 100);
waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.STREAM_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 runHappyPathIteration.
private void runHappyPathIteration(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;
final SocketAddress clientAddr = channel.getLocalAddress();
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return null != _dummyServer.getChildChannel(clientAddr);
}
}, "client connection established", 1000, log);
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 /stream
runHappyPathStream(log, buf, callback, remoteExceptionHandler, conn, msg, clientAddr, objCapture, sourcesResp);
callback.clearLastMsg();
objCapture.clear();
}
use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler 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();
}
use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class DummyRemoteExceptionHandler method runServerStreamReqDisconnectIteration.
private void runServerStreamReqDisconnectIteration(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
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();
serverChannel.close();
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);
waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.STREAM_REQUEST_ERROR, log);
Assert.assertNull(remoteExceptionHandler.getLastException());
Assert.assertEquals(1, callback.getAllMsgs().size());
callback.clearLastMsg();
objCapture.clear();
}
Aggregations