use of com.linkedin.databus2.producers.db.EventFactory in project databus by linkedin.
the class SimpleClientPipelineFactoryWithSleep method testClientSimpleRequestResponse.
@Test
public void testClientSimpleRequestResponse() {
DbusEventFactory eventFactory = new DbusEventV1Factory();
SimpleTestServerConnection srvConn = new SimpleTestServerConnection(eventFactory.getByteOrder());
srvConn.setPipelineFactory(new SimpleServerPipelineFactory());
boolean serverStarted = srvConn.startSynchronously(101, CONNECT_TIMEOUT_MS);
Assert.assertTrue(serverStarted, "server started");
final SimpleTestClientConnection clientConn = new SimpleTestClientConnection(eventFactory.getByteOrder());
clientConn.setPipelineFactory(new SimpleClientPipelineFactoryWithSleep(200));
boolean clientConnected = clientConn.startSynchronously(101, CONNECT_TIMEOUT_MS);
Assert.assertTrue(clientConnected, "client connected");
// hook in to key places in the server pipeline
ChannelPipeline lastSrvConnPipeline = srvConn.getLastConnChannel().getPipeline();
SimpleTestMessageReader srvMsgReader = (SimpleTestMessageReader) lastSrvConnPipeline.get(SimpleTestMessageReader.class.getSimpleName());
ExceptionListenerTestHandler srvExceptionListener = (ExceptionListenerTestHandler) lastSrvConnPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
// hook in to key places in the client pipeline
ChannelPipeline clientPipeline = clientConn.getChannel().getPipeline();
final ExceptionListenerTestHandler clientExceptionListener = (ExceptionListenerTestHandler) clientPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
// System.err.println("Current thread: " + Thread.currentThread());
// send a request in a separate thread because the client will intentionally block to simulate
// a timeout
final ChannelBuffer msg = ChannelBuffers.wrappedBuffer("hello".getBytes(Charset.defaultCharset()));
Thread sendThread1 = new Thread(new Runnable() {
@Override
public void run() {
// System.err.println(Thread.currentThread().toString() + ": sending message");
clientConn.getChannel().write(msg);
}
}, "send msg thread");
sendThread1.start();
// System.err.println(Thread.currentThread().toString() + ": waiting for 10");
try {
Thread.sleep(50);
} catch (InterruptedException ie) {
}
;
// System.err.println(Thread.currentThread().toString() + ": done Waiting for 10");
// make sure the server has not received the message
Assert.assertNull(srvExceptionListener.getLastException(), "no server errors");
Assert.assertNull(clientExceptionListener.getLastException(), "no errors yet");
Assert.assertTrue(!"hello".equals(srvMsgReader.getMsg()), "message not read yet");
// wait for the write timeout
try {
Thread.sleep(300);
} catch (InterruptedException ie) {
}
;
// System.err.println("Done Waiting for 300");
// the client should have timed out and closed the connection
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return null != clientExceptionListener.getLastException();
}
}, "client error", 1000, null);
Assert.assertTrue(null != clientExceptionListener.getLastException(), "client error");
Assert.assertTrue(clientExceptionListener.getLastException() instanceof ClosedChannelException || clientExceptionListener.getLastException() instanceof WriteTimeoutException, "client error test");
Assert.assertTrue(!lastSrvConnPipeline.getChannel().isConnected(), "client has disconnected");
Assert.assertTrue(!clientPipeline.getChannel().isConnected(), "closed connection to server");
}
use of com.linkedin.databus2.producers.db.EventFactory in project databus by linkedin.
the class OracleEventProducerFactory method buildOracleMonitoredSourceInfo.
public OracleTriggerMonitoredSourceInfo buildOracleMonitoredSourceInfo(LogicalSourceStaticConfig sourceConfig, PhysicalSourceStaticConfig pConfig, SchemaRegistryService schemaRegistryService) throws DatabusException, EventCreationException, UnsupportedKeyException, InvalidConfigException {
String schema = null;
try {
schema = schemaRegistryService.fetchLatestSchemaBySourceName(sourceConfig.getName());
} catch (NoSuchSchemaException e) {
throw new InvalidConfigException("Unable to load the schema for source (" + sourceConfig.getName() + ").");
}
if (schema == null) {
throw new InvalidConfigException("Unable to load the schema for source (" + sourceConfig.getName() + ").");
}
_log.info("Loading schema for source id " + sourceConfig.getId() + ": " + schema);
String eventViewSchema;
String eventView;
if (sourceConfig.getUri().indexOf('.') != -1) {
String[] parts = sourceConfig.getUri().split("\\.");
eventViewSchema = parts[0];
eventView = parts[1];
} else {
eventViewSchema = null;
eventView = sourceConfig.getUri();
}
if (eventView.toLowerCase().startsWith("sy$")) {
eventView = eventView.substring(3);
}
PartitionFunction partitionFunction = buildPartitionFunction(sourceConfig);
EventFactory factory = createEventFactory(eventViewSchema, eventView, sourceConfig, pConfig, schema, partitionFunction);
EventSourceStatistics statisticsBean = new EventSourceStatistics(sourceConfig.getName());
OracleTriggerMonitoredSourceInfo sourceInfo = new OracleTriggerMonitoredSourceInfo(sourceConfig.getId(), sourceConfig.getName(), eventViewSchema, eventView, factory, statisticsBean, sourceConfig.getRegularQueryHints(), sourceConfig.getChunkedTxnQueryHints(), sourceConfig.getChunkedScnQueryHints(), sourceConfig.isSkipInfinityScn());
return sourceInfo;
}
Aggregations