use of com.linkedin.databus.core.ScnNotFoundException in project databus by linkedin.
the class MockRemoteExceptionHandler method testRelayTransition.
@Test(groups = { "small", "functional" })
public void testRelayTransition() throws Exception {
final Logger log = Logger.getLogger("TestRelayPullThread.testRelayTransition");
log.info("---------- start ---------------");
// Test Case : Initial State Check
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
//RelayPullThread relayPuller = createRelayPullThread(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
Assert.assertEquals(relayPuller.getConnectionState().getStateId(), StateId.INITIAL, "Initial State Check");
//Let the show begin
Thread relayPullerThread = new Thread(relayPuller);
relayPullerThread.setDaemon(false);
relayPullerThread.start();
relayPuller.enqueueMessage(LifecycleMessage.createStartMessage());
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
}
for (int i = 0; i < 100; i++) {
try {
Thread.sleep(5);
Assert.assertTrue(relayPuller.getConnectionState().getStateId() != StateId.INITIAL, "StateId can never be INITIAL once started");
} catch (InterruptedException ie) {
}
}
//EasyMock.verify(mockConnFactory);
relayPuller.enqueueMessage(LifecycleMessage.createShutdownMessage());
relayPuller.awaitShutdown();
}
// Main Transition Test (Without Server-Set Change)
{
// PICK_SERVER - Happy Path
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
}
// PICK_SERVER - Relays exhausted
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(true, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.PICK_SERVER, "SUSPEND_ON_ERROR");
}
// PICK_SERVER - No Servers
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
relayPuller.getServers().clear();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.PICK_SERVER, "SUSPEND_ON_ERROR");
}
// Request_Sources to Re Sources_Request_Sent
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_REQUEST_SENT, "");
}
// Request_Sources to Sources_Response_Success
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
}
// Sources_Response_Success - Happy Path
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_REQUEST_SENT, "");
List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
sourcesResponse.add(new IdNamePair(1L, "source1"));
connState.switchToSourcesSuccess(sourcesResponse, _HOSTNAME, _SVCNAME);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
validateConnState(connState);
String expSubsListStr = "[{\"physicalSource\":{\"uri\":\"databus:physical-source:ANY\",\"role\":\"ANY\"},\"physicalPartition\":{\"id\":-1,\"name\":\"*\"},\"logicalPartition\":{\"source\":{\"id\":1,\"name\":\"source1\"},\"id\":-1}}]";
String expSourcesIdListStr = "1";
Assert.assertEquals(connState.getSourcesIdListString(), expSourcesIdListStr, "SourcesId Added");
String subsListStr = connState.getSubsListString();
Assert.assertEquals(subsListStr, expSubsListStr);
}
// Sources_Response_Success - When source not found in server
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_REQUEST_SENT, "");
List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
sourcesResponse.add(new IdNamePair(1L, "source1"));
connState.switchToSourcesSuccess(sourcesResponse, _HOSTNAME, _SVCNAME);
relayPuller.getMessageQueue().clear();
connState.getSourcesNameMap().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.PICK_SERVER);
validateConnState(connState);
}
// Request_Register to Register_Request_Sent
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_REQUEST_SENT, "");
List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
sourcesResponse.add(new IdNamePair(1L, "source1"));
connState.switchToSourcesSuccess(sourcesResponse, _HOSTNAME, _SVCNAME);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
String subsListString = "[{\"physicalSource\":{\"uri\":\"databus:physical-source:ANY\",\"role\":\"MASTER\"},\"physicalPartition\":{\"id\":-1,\"name\":\"*\"},\"logicalPartition\":{\"source\":{\"id\":0,\"name\":\"source1\"},\"id\":-1}}]";
String sourcesIdListString = "1";
connState.switchToRequestSourcesSchemas(sourcesIdListString, subsListString);
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_REQUEST_SENT, "");
validateConnState(connState);
}
// Request_Register to Register_Response_success
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
}
// Register_Response_Success : Error Case
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
connState.getSourcesSchemas().clear();
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.PICK_SERVER);
}
// Register_Response_Success to Request Stream
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
Assert.assertEquals(relayPuller.getConnectionState().isSCNRegress(), false, "SCN Regress check");
}
// Register_Response_Success to Request Stream, when partially consumed window
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
Checkpoint cp = new Checkpoint();
cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
cp.setWindowScn(100L);
cp.setWindowOffset(20);
cp.setPrevScn(80L);
relayPuller.getConnectionState().setCheckpoint(cp);
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
Assert.assertEquals(relayPuller.getConnectionState().getCheckpoint().getWindowScn(), 80L, "WindowSCN check");
Assert.assertEquals(relayPuller.getConnectionState().getCheckpoint().getWindowOffset(), new Long(-1), "WindowOffset check");
Assert.assertEquals(relayPuller.getConnectionState().isSCNRegress(), true, "SCN Regress check");
}
// Register_Response_Success, No PrevSCN for partially consumed window
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
Checkpoint cp = new Checkpoint();
cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
cp.setWindowScn(100L);
cp.setWindowOffset(20);
relayPuller.getConnectionState().setCheckpoint(cp);
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REGISTER_RESPONSE_SUCCESS, "SUSPEND_ON_ERROR");
}
// Register_Response_Success to Bootstrap ( when checkpoint is Bootstrap_SnapShot
{
//RelayPullThread relayPuller = createRelayPullThread(false, false, true);
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Is Relay FellOff");
Checkpoint cp = new Checkpoint();
cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
connState.setCheckpoint(cp);
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.BOOTSTRAP);
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
Assert.assertEquals(relayPuller.getConnectionState().isSCNRegress(), false, "SCN Regress check");
}
// Register_Response_Success to Bootstrap ( when checkpoint is Bootstrap_Catchup
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Is Relay FellOff");
Checkpoint cp = new Checkpoint();
cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_CATCHUP);
connState.setCheckpoint(cp);
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.BOOTSTRAP);
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
Assert.assertEquals(relayPuller.getConnectionState().isSCNRegress(), false, "SCN Regress check");
}
// Request_Stream to Request_Stream_Sent
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_REQUEST_SENT, "");
List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
sourcesResponse.add(new IdNamePair(1L, "source1"));
connState.switchToSourcesSuccess(sourcesResponse, _HOSTNAME, _SVCNAME);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
String subsListString = "[{\"physicalSource\":{\"uri\":\"databus:physical-source:ANY\",\"role\":\"MASTER\"},\"physicalPartition\":{\"id\":-1,\"name\":\"*\"},\"logicalPartition\":{\"source\":{\"id\":0,\"name\":\"source1\"},\"id\":-1}}]";
String sourcesIdListString = "1";
connState.switchToRequestSourcesSchemas(sourcesIdListString, subsListString);
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_REQUEST_SENT, "");
relayPuller.getMessageQueue().clear();
MockRelayConnection conn = (MockRelayConnection) connState.getRelayConnection();
connState.switchToRegisterSuccess(conn.getRegisterResponse(), conn.getRegisterResponse(), conn.getRegisterMetadataResponse());
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SENT, "");
validateConnState(connState);
}
// Request_Stream to Stream_Response_Success
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
}
//Stream_Request_Success to Stream_Request_Done
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE);
}
//Stream_Request_Success : ScnNotFoundException but retries set to 5 and bootstrap enabled
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName()).setNumRetriesOnFellOff(5);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
for (int i = 1; i <= 6; i++) {
System.out.println("Iteration :" + i);
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
if (i < 6) {
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.PICK_SERVER);
Assert.assertEquals(relayPuller.getRetryonFallOff().getRemainingRetriesNum(), 6 - i, "Retry State");
} else {
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
//reset
Assert.assertEquals(relayPuller.getRetryonFallOff().getRemainingRetriesNum(), 5, "Retry State");
}
relayPuller.getMessageQueue().clear();
}
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "RelayFellOff State");
}
//Stream_Request_Success : ScnNotFoundException and bootstrap enabled
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
}
//Stream_Request_Success : ScnNotFoundException but retries set to 5, bootstrap disabled and readLatestScnOnFallOff enabled.
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(false).setReadLatestScnEnabled(true).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName()).setNumRetriesOnFellOff(5);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
for (int i = 1; i <= 6; i++) {
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
if (i < 6) {
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.PICK_SERVER);
Assert.assertEquals(relayPuller.getRetryonFallOff().getRemainingRetriesNum(), 6 - i, "Retry State");
} else {
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE);
//reset
Assert.assertEquals(relayPuller.getRetryonFallOff().getRemainingRetriesNum(), 5, "Retry State");
}
relayPuller.getMessageQueue().clear();
}
MockRelayConnection conn = (MockRelayConnection) connState.getRelayConnection();
Assert.assertEquals(conn.isReadFromLatestScn(), true, "ReadFromLatestScn set");
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "RelayFellOff State");
}
//Stream_Request_Success : ScnNotFoundException, bootstrap disabled and readLatestScnOnFallOff enabled.
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(false).setReadLatestScnEnabled(true).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE);
MockRelayConnection conn = (MockRelayConnection) connState.getRelayConnection();
Assert.assertEquals(conn.isReadFromLatestScn(), true, "ReadFromLatestScn set");
}
//Stream_Request_Success : ScnNotFoundException but retries set to 5, bootstrap disabled and readLatestScnOnFallOff disabled.
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(false).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName()).setNumRetriesOnFellOff(5);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
for (int i = 1; i <= 6; i++) {
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
if (i < 6) {
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.PICK_SERVER);
Assert.assertEquals(relayPuller.getRetryonFallOff().getRemainingRetriesNum(), 6 - i, "Retry State");
} else {
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_REQUEST_SUCCESS, "SUSPEND_ON_ERROR");
//reset
Assert.assertEquals(relayPuller.getRetryonFallOff().getRemainingRetriesNum(), 5, "Retry State");
}
relayPuller.getMessageQueue().clear();
}
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "RelayFellOff State");
}
//Stream_Request_Success : ScnNotFoundException, bootstrap disabled and readLatestScnOnFallOff disabled.
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(false).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_REQUEST_SUCCESS, "SUSPEND_ON_ERROR");
}
//Stream_Request_Success : Non-ScnNotFoundException
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName("DummyError");
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_ERROR);
}
//Stream_Request_Done to Request_Stream
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_STREAM);
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Is Relay FellOff");
}
// Bootstrap to Bootstrap_Requested
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
testTransitionCase(relayPuller, StateId.BOOTSTRAP, StateId.BOOTSTRAP_REQUESTED, "");
}
//Exception while doBootstrap()
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(true).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Is Relay FellOff");
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
testTransitionCase(relayPuller, StateId.BOOTSTRAP, StateId.BOOTSTRAP, "SUSPEND_ON_ERROR");
}
// Bootstrap Failed : Case 1
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
testTransitionCase(relayPuller, StateId.BOOTSTRAP, StateId.BOOTSTRAP_REQUESTED, "");
BootstrapResultMessage msg = BootstrapResultMessage.createBootstrapFailedMessage(new Exception("Dummy"));
doExecuteAndChangeState(relayPuller, msg);
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
Assert.assertEquals(connState.getStateId(), StateId.BOOTSTRAP, "BOOTSTRAP_REQUESTED to BOOTSTRAP");
Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [BOOTSTRAP]", "Queue :BOOTSTRAP_REQUESTED to BOOTSTRAP");
}
// Bootstrap Failed : Case 2
{
//RelayPullThread relayPuller = createRelayPullThread(false, false, true, false, false, true, ScnNotFoundException.class.getName());
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
testTransitionCase(relayPuller, StateId.BOOTSTRAP, StateId.BOOTSTRAP_REQUESTED, "");
BootstrapResultMessage msg = BootstrapResultMessage.createBootstrapCompleteMessage(null);
doExecuteAndChangeState(relayPuller, msg);
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
Assert.assertEquals(connState.getStateId(), StateId.BOOTSTRAP, "BOOTSTRAP_REQUESTED to BOOTSTRAP");
Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [BOOTSTRAP]", "Queue :BOOTSTRAP_REQUESTED to BOOTSTRAP");
}
// Bootstrap Success
{
//RelayPullThread relayPuller = createRelayPullThread(false, false, true, false, false, true, ScnNotFoundException.class.getName());
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_SOURCES, StateId.SOURCES_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.REQUEST_REGISTER);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_REGISTER, StateId.REGISTER_RESPONSE_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.REQUEST_STREAM);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS);
relayPuller.getMessageQueue().clear();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.BOOTSTRAP);
relayPuller.getMessageQueue().clear();
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Is Relay FellOff");
testTransitionCase(relayPuller, StateId.BOOTSTRAP, StateId.BOOTSTRAP_REQUESTED, "");
BootstrapResultMessage msg = BootstrapResultMessage.createBootstrapCompleteMessage(new Checkpoint());
doExecuteAndChangeState(relayPuller, msg);
Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Is Relay FellOff");
Assert.assertEquals(connState.getStateId(), StateId.REQUEST_STREAM, "BOOTSTRAP_REQUESTED to REQUEST_STREAM");
Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [REQUEST_STREAM]", "Queue :BOOTSTRAP_REQUESTED to REQUEST_STREAM");
}
// Error States to Pick_Server
{
RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
bldr.setBootstrapEnabled(true).setReadLatestScnEnabled(false).setReadDataThrowException(false).setReadDataException(true).setExceptionName(ScnNotFoundException.class.getName());
RelayPullThread relayPuller = bldr.createRelayPullThread();
relayPuller.getComponentStatus().start();
ConnectionState connState = relayPuller.getConnectionState();
connState.switchToPickServer();
testTransitionCase(relayPuller, StateId.PICK_SERVER, StateId.REQUEST_SOURCES);
relayPuller.getMessageQueue().clear();
connState.switchToSourcesRequestError();
testTransitionCase(relayPuller, StateId.SOURCES_REQUEST_ERROR, StateId.PICK_SERVER);
relayPuller.getMessageQueue().clear();
connState.switchToSourcesResponseError();
testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_ERROR, StateId.PICK_SERVER);
relayPuller.getMessageQueue().clear();
connState.switchToRegisterRequestError();
testTransitionCase(relayPuller, StateId.REGISTER_REQUEST_ERROR, StateId.PICK_SERVER);
relayPuller.getMessageQueue().clear();
connState.switchToRegisterResponseError();
testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_ERROR, StateId.PICK_SERVER);
relayPuller.getMessageQueue().clear();
connState.switchToStreamRequestError();
testTransitionCase(relayPuller, StateId.STREAM_REQUEST_ERROR, StateId.PICK_SERVER);
relayPuller.getMessageQueue().clear();
connState.switchToStreamResponseError();
testTransitionCase(relayPuller, StateId.STREAM_RESPONSE_ERROR, StateId.PICK_SERVER);
}
}
log.info("--------- end -------------");
}
Aggregations