use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testTransition_StreamResponseSuccessHappyPath.
@Test
public /** Test bootstrap transition: Stream_Response_Success - Happy Path */
void testTransition_StreamResponseSuccessHappyPath() throws Exception {
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, 12000, 1);
Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
//TODO remove
//cp.setSnapshotSource("source1");
//cp.setCatchupSource("source1");
//cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
cp.setBootstrapServerInfo(_serverInfoName);
bsPuller.getComponentStatus().start();
ConnectionState connState = bsPuller.getConnectionState();
connState.switchToBootstrap(cp);
testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
bsPuller.getMessageQueue().clear();
Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();
entries.put(1L, new ArrayList<RegisterResponseEntry>());
connState.setSourcesSchemas(entries);
testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
bsPuller.getMessageQueue().clear();
connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);
}
use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testTransition_StreamResponsePhaseNotCompleted.
@Test
public /** Test bootstrap transition: Stream_Response_Done - when phase not yet completed */
void testTransition_StreamResponsePhaseNotCompleted() throws Exception {
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, false);
Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
//TODO remove
//cp.setSnapshotSource("source1");
//cp.setCatchupSource("source1");
//cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
cp.setBootstrapServerInfo(_serverInfoName);
bsPuller.getComponentStatus().start();
ConnectionState connState = bsPuller.getConnectionState();
connState.switchToBootstrap(cp);
testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
bsPuller.getMessageQueue().clear();
Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();
entries.put(1L, new ArrayList<RegisterResponseEntry>());
connState.setSourcesSchemas(entries);
testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
bsPuller.getMessageQueue().clear();
connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);
bsPuller.getMessageQueue().clear();
cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
// non -1 value
cp.setSnapshotOffset(10);
testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_STREAM, null);
}
use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testTransition_TargetScnSuccessError.
@Test
public /** Test bootstrap transition: Target_Scn_Success to Error */
void testTransition_TargetScnSuccessError() throws Exception {
// targetScn = 50 < 100 = startScn
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true, 100, 50);
Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
//TODO remove
//cp.setSnapshotSource("source1");
//cp.setCatchupSource("source1");
//cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
cp.setBootstrapServerInfo(_serverInfoName);
bsPuller.getComponentStatus().start();
ConnectionState connState = bsPuller.getConnectionState();
connState.switchToBootstrap(cp);
testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
bsPuller.getMessageQueue().clear();
Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();
entries.put(1L, new ArrayList<RegisterResponseEntry>());
connState.setSourcesSchemas(entries);
testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
bsPuller.getMessageQueue().clear();
connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);
bsPuller.getMessageQueue().clear();
cp.setSnapshotOffset(-1);
testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
Assert.assertFalse(cp.isBootstrapTargetScnSet());
bsPuller.getMessageQueue().clear();
// testTransitionCase(bsPuller, StateId.REQUEST_TARGET_SCN, StateId.TARGET_SCN_RESPONSE_SUCCESS, null);
testTransitionCase(bsPuller, StateId.REQUEST_TARGET_SCN, StateId.TARGET_SCN_RESPONSE_ERROR, null);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.TARGET_SCN_RESPONSE_ERROR, StateId.PICK_SERVER, null);
Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
Assert.assertFalse(cp.isBootstrapTargetScnSet());
Assert.assertEquals(cp.getBootstrapTargetScn().longValue(), Checkpoint.UNSET_BOOTSTRAP_TARGET_SCN);
}
use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class ConnectionState method setSourcesIds.
public void setSourcesIds(List<IdNamePair> sources) {
_sources = sources;
_sourcesIdMap.clear();
_sourcesNameMap.clear();
for (IdNamePair source : _sources) {
_sourcesIdMap.put(source.getId(), source);
_sourcesNameMap.put(source.getName(), source);
}
expandSubscriptions();
}
use of com.linkedin.databus.core.util.IdNamePair 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