use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.
the class TestDatabusV2RegistrationImpl method testMultiConsumerRegistrationOps.
@Test
public void testMultiConsumerRegistrationOps() throws Exception {
DatabusHttpClientImpl client = null;
try {
DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
clientConfig.getContainer().getJmx().setRmiEnabled(false);
clientConfig.getContainer().setHttpPort(12003);
client = new DatabusHttpClientImpl(clientConfig);
registerRelay(1, "relay1", new InetSocketAddress("localhost", 8888), "S1,S2", client);
registerRelay(2, "relay2", new InetSocketAddress("localhost", 7777), "S1,S3", client);
registerRelay(3, "relay1.1", new InetSocketAddress("localhost", 8887), "S1,S2", client);
registerRelay(4, "relay3", new InetSocketAddress("localhost", 6666), "S3,S4,S5", client);
TestConsumer listener1 = new TestConsumer();
TestConsumer listener2 = new TestConsumer();
List<DatabusCombinedConsumer> listeners = new ArrayList<DatabusCombinedConsumer>();
listeners.add(listener1);
listeners.add(listener2);
DatabusRegistration reg = client.register(listeners, "S1", "S2");
assertEquals("Registered State", RegistrationState.REGISTERED, reg.getState());
assertEquals("Component Name", "Status_TestConsumer_922c5e28", reg.getStatus().getComponentName());
assertEquals("Component Status", Status.INITIALIZING, reg.getStatus().getStatus());
// Start
boolean started = reg.start();
assertEquals("Started", true, started);
assertEquals("Registered State", RegistrationState.STARTED, reg.getState());
assertEquals("Component Status", Status.RUNNING, reg.getStatus().getStatus());
//Start again
started = reg.start();
assertEquals("Started", false, started);
assertEquals("Registered State", RegistrationState.STARTED, reg.getState());
// Pause
reg.pause();
assertEquals("Registered State", RegistrationState.PAUSED, reg.getState());
assertEquals("Component Status", Status.PAUSED, reg.getStatus().getStatus());
// resume
reg.resume();
assertEquals("Registered State", RegistrationState.RESUMED, reg.getState());
assertEquals("Component Status", Status.RUNNING, reg.getStatus().getStatus());
// suspend due to error
reg.suspendOnError(new Exception("dummy"));
assertEquals("Registered State", RegistrationState.SUSPENDED_ON_ERROR, reg.getState());
assertEquals("Component Status", Status.SUSPENDED_ON_ERROR, reg.getStatus().getStatus());
// SHutdown
reg.shutdown();
assertEquals("Registered State", RegistrationState.SHUTDOWN, reg.getState());
assertEquals("Component Status", Status.SHUTDOWN, reg.getStatus().getStatus());
reg.deregister();
} finally {
if (null != client)
client.shutdown();
}
}
use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.
the class DatabusHttpClientImpl method registerDatabusBootstrapListener.
/**
*
* @param listeners
* @param sources
* @param filter
* @throws DatabusClientException
*/
public synchronized void registerDatabusBootstrapListener(DatabusBootstrapConsumer[] listeners, List<String> sources, DbusKeyCompositeFilterConfig filter) throws DatabusClientException {
List<DatabusBootstrapConsumer> listenersList = Arrays.asList(listeners);
List<SelectingDatabusCombinedConsumer> sdccListenersList = SelectingDatabusCombinedConsumerFactory.convertListOfBootstrapConsumers(listenersList);
List<DatabusCombinedConsumer> dccListenersList = new ArrayList<DatabusCombinedConsumer>();
for (SelectingDatabusCombinedConsumer sdcc : sdccListenersList) {
dccListenersList.add(sdcc);
}
DatabusV2ConsumerRegistration consumerReg = new DatabusV2ConsumerRegistration(dccListenersList, sources, filter);
registerDatabusListener(consumerReg, _relayGroups, getRelayGroupBootstrapConsumers(), DatabusSubscription.createSubscriptionList(sources));
}
use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.
the class DatabusHttpClientImpl method registerDatabusStreamListener.
/**
*
* @param listeners
* @param sources
* @param filterConfig
* @throws DatabusClientException
*/
public synchronized void registerDatabusStreamListener(DatabusStreamConsumer[] listeners, List<String> sources, DbusKeyCompositeFilterConfig filterConfig) throws DatabusClientException {
List<DatabusStreamConsumer> listenersList = Arrays.asList(listeners);
List<SelectingDatabusCombinedConsumer> sdccListenersList = SelectingDatabusCombinedConsumerFactory.convertListOfStreamConsumers(listenersList);
List<DatabusCombinedConsumer> dccListenersList = new ArrayList<DatabusCombinedConsumer>();
for (SelectingDatabusCombinedConsumer sdcc : sdccListenersList) {
dccListenersList.add(sdcc);
}
DatabusV2ConsumerRegistration consumerReg = new DatabusV2ConsumerRegistration(dccListenersList, sources, filterConfig);
registerDatabusListener(consumerReg, _relayGroups, getRelayGroupStreamConsumers(), DatabusSubscription.createSubscriptionList(sources));
}
use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.
the class TestConsumerRegistration method testSingleConsumer.
@Test
public void testSingleConsumer() throws Exception {
DatabusCombinedConsumer logConsumer = new LoggingConsumer();
List<String> sources = new ArrayList<String>();
ConsumerRegistration consumerReg = new ConsumerRegistration(logConsumer, sources, null);
Assert.assertEquals(logConsumer, consumerReg.getConsumer());
return;
}
use of com.linkedin.databus.client.pub.DatabusCombinedConsumer in project databus by linkedin.
the class TestMultiConsumerCallback method test3GroupedStreamConsumersHappyPath.
@Test(groups = { "small", "functional" })
public void test3GroupedStreamConsumersHappyPath() {
LOG.info("\n\nstarting test3GroupedStreamConsumersHappyPath()");
Hashtable<Long, AtomicInteger> keyCounts = new Hashtable<Long, AtomicInteger>();
DbusEventBuffer eventsBuf = new DbusEventBuffer(_generic100KBufferStaticConfig);
eventsBuf.start(0);
eventsBuf.startEvents();
initBufferWithEvents(eventsBuf, 1, 1, (short) 1, keyCounts);
initBufferWithEvents(eventsBuf, 2, 2, (short) 3, keyCounts);
eventsBuf.endEvents(100L);
DatabusStreamConsumer mockConsumer1 = EasyMock.createStrictMock("consumer1", DatabusStreamConsumer.class);
EasyMock.makeThreadSafe(mockConsumer1, true);
DatabusStreamConsumer mockConsumer2 = EasyMock.createStrictMock("consumer2", DatabusStreamConsumer.class);
EasyMock.makeThreadSafe(mockConsumer2, true);
DatabusStreamConsumer mockConsumer3 = EasyMock.createStrictMock("consumer3", DatabusStreamConsumer.class);
EasyMock.makeThreadSafe(mockConsumer3, true);
DatabusCombinedConsumer sdccMockConsumer1 = new SelectingDatabusCombinedConsumer(mockConsumer1);
DatabusCombinedConsumer sdccMockConsumer2 = new SelectingDatabusCombinedConsumer(mockConsumer2);
DatabusCombinedConsumer sdccMockConsumer3 = new SelectingDatabusCombinedConsumer(mockConsumer3);
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);
}
DatabusV2ConsumerRegistration consumerReg1 = new DatabusV2ConsumerRegistration(Arrays.asList(sdccMockConsumer1, sdccMockConsumer2, sdccMockConsumer3), sources, null);
List<DatabusV2ConsumerRegistration> allRegistrations = Arrays.asList(consumerReg1);
MultiConsumerCallback callback = new MultiConsumerCallback(allRegistrations, Executors.newCachedThreadPool(), 1000, new StreamConsumerCallbackFactory(null, null), null, null, null, null);
callback.setSourceMap(sourcesMap);
DbusEventBuffer.DbusEventIterator iter = eventsBuf.acquireIterator("myIter1");
assert iter.hasNext() : "unable to read event";
DbusEvent event1 = iter.next();
assert iter.hasNext() : "unable to read event";
DbusEvent event2 = iter.next();
assert iter.hasNext() : "unable to read event";
DbusEvent event3 = iter.next();
initMockStreamConsumer3OptEventFullLifecycle(mockConsumer1, event1, event2, event3, keyCounts);
initMockStreamConsumer3OptEventFullLifecycle(mockConsumer2, event1, event2, event3, keyCounts);
initMockStreamConsumer3OptEventFullLifecycle(mockConsumer3, event1, event2, event3, keyCounts);
assert3EventFullLifecycle(callback, event1, event2, event3);
EasyMock.verify(mockConsumer1);
EasyMock.verify(mockConsumer2);
EasyMock.verify(mockConsumer3);
assert (keyCounts.get(1L).get() + keyCounts.get(2L).get() + keyCounts.get(3L).get()) == 3 : "invalid number of calls: " + keyCounts.get(1L).get() + "," + keyCounts.get(2L).get() + "," + keyCounts.get(3L).get();
}
Aggregations