use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testTransition_StreamResponseCatchupToSnapshot.
@Test
public /**
* Test bootstrap transition: Stream_Response_Done - when catchup phase completed and going to
* snapshot next table
*/
void testTransition_StreamResponseCatchupToSnapshot() throws Exception {
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true, 50L, 100L, "source1", "source2");
Checkpoint cp = _ckptHandlerTwoSources.createInitialBootstrapCheckpoint(null, 0L);
cp.setBootstrapServerInfo(_serverInfoName);
bsPuller.getComponentStatus().start();
ConnectionState connState = bsPuller.getConnectionState();
connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
connState.getSourcesNameMap().put("source2", new IdNamePair(2L, "source2"));
connState.getSourceIdMap().put(2L, new IdNamePair(2L, "source1"));
connState.getSourceIdMap().put(2L, new IdNamePair(2L, "source1"));
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);
//set the startSCN
testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT);
Assert.assertEquals(cp.getSnapshotSource(), "source1");
Assert.assertFalse(cp.isSnapShotSourceCompleted());
//start snapshot for source1
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
bsPuller.getMessageQueue().clear();
cp.setSnapshotOffset(Checkpoint.FULLY_CONSUMED_WINDOW_OFFSET);
testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);
//finish the snapshot phase for source1
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
//set targetSCN after the snapshot phase for source1
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_TARGET_SCN, StateId.TARGET_SCN_RESPONSE_SUCCESS, null);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.TARGET_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_CATCHUP);
Assert.assertFalse(cp.isCatchupSourceCompleted());
Assert.assertEquals(cp.getWindowScn(), 50L, "WindowSCN Check");
Assert.assertEquals(cp.getCatchupSource(), "source1", "Catchup Source check");
//start catch-up for source1
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
//finish the catch-up phase for source1
cp.setWindowOffset(Checkpoint.FULLY_CONSUMED_WINDOW_OFFSET);
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, cp);
//start the snapshot phase for source2
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_STREAM, null);
Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT);
Assert.assertEquals(cp.getSnapshotSource(), "source2");
Assert.assertFalse(cp.isSnapShotSourceCompleted());
Assert.assertTrue(cp.isCatchupSourceCompleted());
bsPuller.getMessageQueue().clear();
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);
//finish the snapshot phase for source2
bsPuller.getMessageQueue().clear();
cp.setSnapshotOffset(Checkpoint.FULLY_CONSUMED_WINDOW_OFFSET);
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_RequestStreamToStreamRequestSet.
@Test
public /** Test bootstrap transition: Request_Stream to Stream_request_sent */
void testTransition_RequestStreamToStreamRequestSet() 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"));
MockBootstrapConnection mockConn = (MockBootstrapConnection) connState.getBootstrapConnection();
mockConn.setMuteTransition(true);
testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SENT, "", null);
}
use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testTransition_RequestStreamFullBuffer.
@Test
public /** Test bootstrap transition: Request_Stream when not enough space in the buffer */
void testTransition_RequestStreamFullBuffer() throws Exception {
// available space is 10 which is less than the threshold of 10000
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, 10, 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.REQUEST_STREAM, null);
}
use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testServerSetChange_TargetScnResponseSuccess.
@Test
public /** Test ServerSet change when in Target_Scn_Response_ Success state */
void testServerSetChange_TargetScnResponseSuccess() throws Exception {
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true);
Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
//TODO remove
// cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
// cp.setSnapshotSource("source1");
// cp.setCatchupSource("source1");
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);
connState.setCurrentBSServerInfo(bsPuller.getCurentServer());
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);
cp.setSnapshotOffset(-1);
testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
Assert.assertTrue(cp.isSnapShotSourceCompleted(), "Phase completed");
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);
Assert.assertTrue(cp.isBootstrapTargetScnSet());
Assert.assertEquals(cp.getBootstrapTargetScn().longValue(), 10L);
// ServerSetChange when New Set includes CurrentServer
{
Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
Assert.assertEquals(bsPuller.getCurentServer() != null, true, "Current Server not Null");
ServerInfo oldServer = bsPuller.getCurentServer();
Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_1, "Server Set");
entries = new HashMap<Long, List<RegisterResponseEntry>>();
entries.put(1L, new ArrayList<RegisterResponseEntry>());
connState.setSourcesSchemas(entries);
doExecuteAndChangeState(bsPuller, createSetServerMessage(true, bsPuller));
Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_2, "Server Set");
Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
Assert.assertEquals(connState.getStateId(), StateId.TARGET_SCN_RESPONSE_SUCCESS, "ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [TARGET_SCN_RESPONSE_SUCCESS]", "Queue :ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
}
// ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
{
int oldServerIndex = bsPuller.getCurrentServerIdx();
ServerInfo oldServer = bsPuller.getCurentServer();
Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_2, "Server Set");
entries = new HashMap<Long, List<RegisterResponseEntry>>();
entries.put(1L, new ArrayList<RegisterResponseEntry>());
connState.setSourcesSchemas(entries);
doExecuteAndChangeState(bsPuller, createSetServerMessage(false, bsPuller));
Assert.assertEquals(bsPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
Assert.assertEquals(bsPuller.getServers(), EXP_SERVERINFO_3, "Server Set");
Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
Assert.assertEquals(connState.getStateId(), StateId.TARGET_SCN_RESPONSE_SUCCESS, "ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: [TARGET_SCN_RESPONSE_SUCCESS]", "Queue :ServerSetChange while TARGET_SCN_RESPONSE_SUCCESS");
// Now Response arrives
connState.switchToStartScnSuccess(cp, null, null);
testTransitionCase(bsPuller, StateId.TARGET_SCN_RESPONSE_SUCCESS, StateId.PICK_SERVER, null);
Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
Assert.assertEquals(bsPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
Assert.assertEquals(bsPuller.getCurentServer() == null, true, "Current Server Null");
}
}
use of com.linkedin.databus.core.util.IdNamePair in project databus by linkedin.
the class MockBootstrapConnection method testTransition_StreamResponseOtherException.
@Test
public /** Test bootstrap transition: Stream_Response_Success - Server returned other exception */
void testTransition_StreamResponseOtherException() throws Exception {
BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, true, "Dummy Exception", 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_ERROR, null);
}
Aggregations