use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.
the class DummySuccessfulErrorCountingConsumer method testDispatcherRetriesExhausted.
@Test
public void testDispatcherRetriesExhausted() throws Exception {
final Logger log = Logger.getLogger("TestDatabusHttpClient.testDispatcherRetriesExhausted");
log.info("start");
DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
clientConfig.getConnectionDefaults().getPullerRetries().setMaxRetryNum(3);
clientConfig.getConnectionDefaults().getDispatcherRetries().setMaxRetryNum(1);
clientConfig.getContainer().getJmx().setRmiEnabled(false);
int port = Utils.getAvailablePort(10100);
clientConfig.getContainer().setHttpPort(0);
final DatabusHttpClientImpl client = new DatabusHttpClientImpl(clientConfig);
port = Utils.getAvailablePort(8898);
@SuppressWarnings("unused") ServerInfo s1 = registerRelay(1, "relay1", new InetSocketAddress("localhost", port), "S1", client);
//DummyStreamConsumer listener1 = new DummyStreamConsumer("consumer1");
final DummySuccessfulErrorCountingConsumer listener1 = new DummySuccessfulErrorCountingConsumer("consumer1", true);
client.registerDatabusStreamListener(listener1, null, "S1");
Thread startThread = new Thread(new Runnable() {
@Override
public void run() {
client.start();
}
}, "client start thread");
startThread.start();
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return client.getRelayConnections().size() == 1;
}
}, "client started", 1000, log);
DatabusSourcesConnection dsc = client.getRelayConnections().get(0);
RelayDispatcher rd = (RelayDispatcher) dsc.getRelayDispatcher();
Assert.assertEquals(true, null != dsc);
List<String> sources = new ArrayList<String>();
Map<Long, IdNamePair> sourcesMap = new HashMap<Long, IdNamePair>();
for (int i = 1; i <= 3; ++i) {
IdNamePair sourcePair = new IdNamePair((long) i, "source" + i);
sources.add(sourcePair.getName());
sourcesMap.put(sourcePair.getId(), sourcePair);
}
HashMap<Long, List<RegisterResponseEntry>> schemaMap = new HashMap<Long, List<RegisterResponseEntry>>();
List<RegisterResponseEntry> l1 = new ArrayList<RegisterResponseEntry>();
List<RegisterResponseEntry> l2 = new ArrayList<RegisterResponseEntry>();
List<RegisterResponseEntry> l3 = new ArrayList<RegisterResponseEntry>();
final String SOURCE1_SCHEMA_STR = "{\"name\":\"source1\",\"type\":\"record\",\"fields\":[{\"name\":\"s\",\"type\":\"string\"}]}";
final String SOURCE2_SCHEMA_STR = "{\"name\":\"source2\",\"type\":\"record\",\"fields\":[{\"name\":\"s\",\"type\":\"string\"}]}";
;
final String SOURCE3_SCHEMA_STR = "{\"name\":\"source3\",\"type\":\"record\",\"fields\":[{\"name\":\"s\",\"type\":\"string\"}]}";
;
l1.add(new RegisterResponseEntry(1L, (short) 1, SOURCE1_SCHEMA_STR));
l2.add(new RegisterResponseEntry(2L, (short) 1, SOURCE2_SCHEMA_STR));
l3.add(new RegisterResponseEntry(3L, (short) 1, SOURCE3_SCHEMA_STR));
schemaMap.put(1L, l1);
schemaMap.put(2L, l2);
schemaMap.put(3L, l3);
int source1EventsNum = 2;
int source2EventsNum = 2;
Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
Hashtable<Short, AtomicInteger> srcidCounts = new Hashtable<Short, AtomicInteger>();
// Send dummy e
DbusEventBuffer eventsBuf = dsc.getDataEventsBuffer();
eventsBuf.start(0);
eventsBuf.startEvents();
initBufferWithEvents(eventsBuf, 1, source1EventsNum, (short) 1, keyCounts, srcidCounts);
initBufferWithEvents(eventsBuf, 1 + source1EventsNum, source2EventsNum, (short) 2, keyCounts, srcidCounts);
eventsBuf.endEvents(100L, null);
rd.enqueueMessage(SourcesMessage.createSetSourcesIdsMessage(sourcesMap.values()));
rd.enqueueMessage(SourcesMessage.createSetSourcesSchemasMessage(schemaMap));
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return listener1._errorCount == 1;
}
}, "error callback", 1000, log);
client.shutdown();
log.info("done");
}
use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.
the class TestClientChannelClose method testTimeoutCase.
@Test
public void testTimeoutCase() throws Exception {
int port = Utils.getAvailablePort(27781);
FakeRelay relay = new FakeRelay(port, 10, true, 100);
TestClientConnectionFactory factory = null;
try {
relay.start();
List<MsgState> msgList = new ArrayList<MsgState>();
DatabusHttpClientImpl.Config conf = new DatabusHttpClientImpl.Config();
conf.getContainer().setReadTimeoutMs(54);
factory = new TestClientConnectionFactory(conf.build());
ServerInfo relayInfo = new ServerInfo("dummy", "dummy", new InetSocketAddress(InetAddress.getLocalHost(), port), "dummy");
for (int i = 0; i < 10; i++) {
TestClientConnection conn = factory.createConnection(relayInfo, msgList);
conn.requestCall();
Thread.sleep(1000);
System.out.println("MsgList is :" + msgList);
//Assert.assertEquals(msgList.size(), 4, "Expected Size Check");
int numMsgEnqueued = 0;
for (MsgState s : msgList) {
if (s == MsgState.MSG_ENQUEUED)
numMsgEnqueued++;
}
Assert.assertEquals(numMsgEnqueued, 1, "Expected NumEnqueued Msgs");
msgList.clear();
}
} finally {
if (null != relay)
relay.shutdown();
if (null != factory)
factory.stop();
}
}
use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.
the class TestDatabusV2ClusterRegistrationImpl method registerRelay.
private ServerInfo registerRelay(int id, String name, InetSocketAddress addr, String sources, DatabusHttpClientImpl client) throws InvalidConfigException {
RuntimeConfigBuilder rtConfigBuilder = (RuntimeConfigBuilder) client.getClientConfigManager().getConfigBuilder();
ServerInfoBuilder relayConfigBuilder = rtConfigBuilder.getRelay(Integer.toString(id));
relayConfigBuilder.setName(name);
relayConfigBuilder.setHost(addr.getHostName());
relayConfigBuilder.setPort(addr.getPort());
relayConfigBuilder.setSources(sources);
ServerInfo si = relayConfigBuilder.build();
client.getClientConfigManager().setNewConfig(rtConfigBuilder.build());
return si;
}
use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.
the class TestDatabusV2RegistrationImpl method registerRelay.
private ServerInfo registerRelay(int id, String name, InetSocketAddress addr, String sources, DatabusHttpClientImpl client) throws InvalidConfigException {
RuntimeConfigBuilder rtConfigBuilder = (RuntimeConfigBuilder) client.getClientConfigManager().getConfigBuilder();
ServerInfoBuilder relayConfigBuilder = rtConfigBuilder.getRelay(Integer.toString(id));
relayConfigBuilder.setName(name);
relayConfigBuilder.setHost(addr.getHostName());
relayConfigBuilder.setPort(addr.getPort());
relayConfigBuilder.setSources(sources);
ServerInfo si = relayConfigBuilder.build();
client.getClientConfigManager().setNewConfig(rtConfigBuilder.build());
return si;
}
use of com.linkedin.databus.client.pub.ServerInfo in project databus by linkedin.
the class RelayEventProducer method createServerInfo.
static Set<ServerInfo> createServerInfo(String serverName, String subscriptions) throws InvalidConfigException {
Set<ServerInfo> serverInfo = new HashSet<ServerInfo>();
ServerInfoBuilder sBuilder = new ServerInfoBuilder();
sBuilder.setAddress(serverName + ":" + subscriptions);
// sBuilder.setSources(subscriptions);
serverInfo.add(sBuilder.build());
return serverInfo;
}
Aggregations