use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class TestDatabusV2ClusterRegistrationImpl method setUpClass.
@BeforeClass
public void setUpClass() throws InvalidConfigException {
//setup logging
TestUtil.setupLogging(true, null, Level.INFO);
InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
//initialize relays
for (int relayN = 0; relayN < RELAY_PORT.length; ++relayN) {
_dummyServer[relayN] = new SimpleTestServerConnection(new DbusEventV2Factory().getByteOrder(), SimpleTestServerConnection.ServerType.NIO);
_dummyServer[relayN].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[relayN].start(RELAY_PORT[relayN]);
}
//create standard client config
DatabusHttpClientImpl.Config clientCfgBuilder = new DatabusHttpClientImpl.Config();
clientCfgBuilder.getContainer().setHttpPort(CLIENT_PORT);
clientCfgBuilder.getContainer().getJmx().setRmiEnabled(false);
clientCfgBuilder.getContainer().setReadTimeoutMs(10000000);
clientCfgBuilder.getConnectionDefaults().getPullerRetries().setInitSleep(10);
clientCfgBuilder.getRuntime().getBootstrap().setEnabled(false);
clientCfgBuilder.getCheckpointPersistence().setClearBeforeUse(true);
for (int i = 0; i < RELAY_PORT.length; ++i) {
clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setHost("localhost");
clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setPort(RELAY_PORT[i]);
clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setSources(SOURCE1_NAME);
}
_stdClientCfgBuilder = clientCfgBuilder;
_stdClientCfg = clientCfgBuilder.build();
//create standard relay buffer config
DbusEventBuffer.Config bufCfgBuilder = new DbusEventBuffer.Config();
bufCfgBuilder.setAllocationPolicy(AllocationPolicy.HEAP_MEMORY.toString());
bufCfgBuilder.setMaxSize(100000);
bufCfgBuilder.setScnIndexSize(128);
bufCfgBuilder.setAverageEventSize(1);
_bufCfg = bufCfgBuilder.build();
}
use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class TestDatabusV2RegistrationImpl method setUpClass.
@BeforeClass
public void setUpClass() throws InvalidConfigException {
//setup logging
TestUtil.setupLogging(true, null, Level.INFO);
InternalLoggerFactory.setDefaultFactory(new Log4JLoggerFactory());
//initialize relays
for (int relayN = 0; relayN < RELAY_PORT.length; ++relayN) {
_dummyServer[relayN] = new SimpleTestServerConnection(new DbusEventV2Factory().getByteOrder(), SimpleTestServerConnection.ServerType.NIO);
_dummyServer[relayN].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[relayN].start(RELAY_PORT[relayN]);
}
//create standard client config
DatabusHttpClientImpl.Config clientCfgBuilder = new DatabusHttpClientImpl.Config();
clientCfgBuilder.getContainer().setHttpPort(CLIENT_PORT);
clientCfgBuilder.getContainer().getJmx().setRmiEnabled(false);
clientCfgBuilder.getContainer().setReadTimeoutMs(10000000);
clientCfgBuilder.getConnectionDefaults().getPullerRetries().setInitSleep(10);
clientCfgBuilder.getRuntime().getBootstrap().setEnabled(false);
clientCfgBuilder.getCheckpointPersistence().setClearBeforeUse(true);
for (int i = 0; i < RELAY_PORT.length; ++i) {
clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setHost("localhost");
clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setPort(RELAY_PORT[i]);
clientCfgBuilder.getRuntime().getRelay(Integer.toString(i)).setSources(SOURCE1_NAME);
}
_stdClientCfgBuilder = clientCfgBuilder;
_stdClientCfg = clientCfgBuilder.build();
//create standard relay buffer config
DbusEventBuffer.Config bufCfgBuilder = new DbusEventBuffer.Config();
bufCfgBuilder.setAllocationPolicy(AllocationPolicy.HEAP_MEMORY.toString());
bufCfgBuilder.setMaxSize(100000);
bufCfgBuilder.setScnIndexSize(128);
bufCfgBuilder.setAverageEventSize(1);
_bufCfg = bufCfgBuilder.build();
}
use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class DummyRemoteExceptionHandler method runRegisterV4.
private void runRegisterV4(final String subtestName, final String protocolVersionHeader, final String responseStr, final TestResponseProcessors.TestConnectionStateMessage.State expectedRegisterState) throws IOException, ScnNotFoundException, OffsetNotFoundException //throws JsonGenerationException, JsonMappingException, IOException, ScnNotFoundException, OffsetNotFoundException
{
final Logger log = Logger.getLogger("TestNettyHttpDatabusRelayConnection." + subtestName);
//log.setLevel(Level.DEBUG);
TestingConnectionCallback callback = TestingConnectionCallback.createAndStart(subtestName);
DummyRemoteExceptionHandler remoteExceptionHandler = new DummyRemoteExceptionHandler();
final NettyHttpDatabusRelayConnection conn = (NettyHttpDatabusRelayConnection) CONN_FACTORY.createRelayConnection(RELAY_SERVER_INFO, callback, remoteExceptionHandler);
// verify the version - current DBUS_EVENT_V1
Assert.assertEquals(MAX_EVENT_VERSION, conn.getMaxEventVersion());
try {
// 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 /sources request
HttpResponse sourcesResp = runHappyPathSources(log, callback, remoteExceptionHandler, clientAddr, objCapture);
// send /register and check result
doRegisterV4(log, callback, remoteExceptionHandler, conn, msg, clientAddr, objCapture, sourcesResp, protocolVersionHeader, responseStr, expectedRegisterState);
callback.clearLastMsg();
objCapture.clear();
} finally {
conn.close();
callback.shutdown();
}
}
use of com.linkedin.databus2.test.container.SimpleObjectCaptureHandler in project databus by linkedin.
the class DummyRemoteExceptionHandler method runServerRegisterReadTimeoutIteration.
private void runServerRegisterReadTimeoutIteration(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);
conn.requestRegister("1", msg);
//verify server gets the /register request
HttpRequest msgReq = captureRequest(objCapture);
Assert.assertTrue(msgReq.getUri().startsWith("/register"));
//Trigger a read timeout
TestUtil.sleep(DEFAULT_READ_TIMEOUT_MS + 100);
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 runServerStreamDisconnectIteration.
private void runServerStreamDisconnectIteration(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"));
serverChannel.close();
waitForCallback(callback, TestResponseProcessors.TestConnectionStateMessage.State.STREAM_RESPONSE_ERROR, log);
Assert.assertNull(remoteExceptionHandler.getLastException());
Assert.assertEquals(1, callback.getAllMsgs().size());
callback.clearLastMsg();
objCapture.clear();
}
Aggregations