Package com.linkedin.databus.core.util

Examples of com.linkedin.databus.core.util.IdNamePair


      }
      LOG.info("Relay order:" + sb.toString());
    }

    List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
    sourcesResponse.add(new IdNamePair(1L, "source1"));

    Map<Long, List<RegisterResponseEntry>> registerSourcesResponse = new HashMap<Long, List<RegisterResponseEntry>>();
    List<RegisterResponseEntry> regResponse = new ArrayList<RegisterResponseEntry>();
    regResponse.add(new RegisterResponseEntry(1L, (short)1, SCHEMA$.toString()));
    registerSourcesResponse.put(1L, regResponse);
View Full Code Here


        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}}]";
 
View Full Code Here

          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_SOURCES");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff Check");

          // Now Response arrives
          List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
          sourcesResponse.add(new IdNamePair(1L, "source1"));
          connState.switchToSourcesSuccess(sourcesResponse, _HOSTNAME, _SVCNAME);
          testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_SUCCESS, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");
          validateConnState(connState);
        }
      }

      // When on SOURCES-REQUEST-SENT and SOURCES_RESPONSE_ERROR
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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, "");

        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.SOURCES_REQUEST_SENT, "ServerSetChange while SOURCES_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while SOURCES_REQUEST_SENT");
        }

        // ServerSetChange when New Set excludes CurrentServer and SOURCES_RESPONSE_ERROR
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.SOURCES_REQUEST_SENT, "ServerSetChange while REQUEST_SOURCES");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_SOURCES");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          // Now Response arrives
          List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
          sourcesResponse.add(new IdNamePair(1L, "source1"));
          connState.switchToSourcesResponseError();
          testTransitionCase(relayPuller, StateId.SOURCES_RESPONSE_ERROR, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");
        }
      }

      // When on SOURCES-REQUEST-SENT and SOURCES_REQUEST_ERROR
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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, "");

        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.SOURCES_REQUEST_SENT, "ServerSetChange while SOURCES_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while SOURCES_REQUEST_SENT");
        }

        // ServerSetChange when New Set excludes CurrentServer and SOURCES_REQUEST_ERROR
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.SOURCES_REQUEST_SENT, "ServerSetChange while REQUEST_SOURCES");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_SOURCES");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          // Now Response arrives
          List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
          sourcesResponse.add(new IdNamePair(1L, "source1"));
          connState.switchToSourcesRequestError();
          testTransitionCase(relayPuller, StateId.SOURCES_REQUEST_ERROR, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");

        }
      }

      // When on Request Register
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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);

        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REQUEST_REGISTER, "ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [REQUEST_REGISTER]", "Queue :ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");
        }

        // ServerSetChange when New Set excludes CurrentServer
        {
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.PICK_SERVER, "ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [PICK_SERVER]", "Queue :ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");
        }
      }

      // When on REGISTER-REQUEST-SENT and REGISTER_RESPONSE_ERROR
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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,"");


        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REGISTER_REQUEST_SENT, "ServerSetChange while REGISTER_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REGISTER_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");
        }

        // ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REGISTER_REQUEST_SENT, "ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          connState.switchToRegisterResponseError();
          testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_ERROR, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");

        }
      }

      // When on REGISTER-REQUEST-SENT and REGISTER_REQUEST_ERROR
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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,"");


        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REGISTER_REQUEST_SENT, "ServerSetChange while REGISTER_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REGISTER_REQUEST_SENT");
        }

        // ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REGISTER_REQUEST_SENT, "ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          connState.switchToSourcesRequestError();
          testTransitionCase(relayPuller, StateId.REGISTER_REQUEST_ERROR, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");

        }
      }

      // When on REGISTER-REQUEST-SENT and Response Successful
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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);
        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,"");


        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REGISTER_REQUEST_SENT, "ServerSetChange while REGISTER_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REGISTER_REQUEST_SENT");
        }

        // ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REGISTER_REQUEST_SENT, "ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_REGISTER");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          // Now Response arrives
          MockRelayConnection conn = (MockRelayConnection)connState.getRelayConnection();
          connState.switchToRegisterSuccess(conn.getRegisterResponse(), conn.getRegisterResponse(), conn.getRegisterMetadataResponse());
          testTransitionCase(relayPuller, StateId.REGISTER_RESPONSE_SUCCESS, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");

        }
      }

      // when on REQUEST_STREAM
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, false);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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);

        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.REQUEST_STREAM, "ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [REQUEST_STREAM]", "Queue :ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");
        }

        // ServerSetChange when New Set excludes CurrentServer
        {
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.PICK_SERVER, "ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: [PICK_SERVER]", "Queue :ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");
        }
      }

      // When on STREAM_REQUEST_SENT and response successful
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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, "");


        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.STREAM_REQUEST_SENT, "ServerSetChange while STREAM_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while STREAM_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");
        }

        // ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.STREAM_REQUEST_SENT, "ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          // Now Response arrives
          conn = (MockRelayConnection)connState.getRelayConnection();
          connState.switchToStreamSuccess(conn.getStreamResponse());
          testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");
        }
      }

      // When on STREAM_REQUEST_SENT and STREAM_RESPONSE_ERROR
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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, "");


        // ServerSetChange when New Set includes CurrentServer
        {
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer() != null, true, "Current Server not Null");
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(true, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.STREAM_REQUEST_SENT, "ServerSetChange while STREAM_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while STREAM_REQUEST_SENT");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");
        }

        // ServerSetChange when New Set excludes CurrentServer and StreamResponse Error
        {
          int oldServerIndex = relayPuller.getCurrentServerIdx();
          ServerInfo oldServer = relayPuller.getCurentServer();
          Assert.assertEquals(relayPuller.getServers(),expServerInfo2,"Server Set");
          doExecuteAndChangeState(relayPuller,createSetServerMessage(false, relayPuller));
          Assert.assertEquals(relayPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
          Assert.assertEquals(relayPuller.getCurentServer(), oldServer, "Current Server unchanged");
          Assert.assertEquals(relayPuller.getServers(),expServerInfo3,"Server Set");
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
          Assert.assertEquals(connState.getStateId(),StateId.STREAM_REQUEST_SENT, "ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while REQUEST_STREAM");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), true, "Relay FellOff CHeck");

          // Now Response arrives
          connState.switchToStreamResponseError();
          testTransitionCase(relayPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.PICK_SERVER);
          Assert.assertEquals(relayPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
          Assert.assertEquals(relayPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
          Assert.assertEquals(relayPuller.getCurentServer() == null, true, "Current Server Null");
          Assert.assertEquals(relayPuller.getConnectionState().isRelayFellOff(), false, "Relay FellOff CHeck");
        }
      }

      // When on STREAM_REQUEST_SENT and STREAM_REQUEST_ERROR
      {
        RelayPullThreadBuilder bldr = new RelayPullThreadBuilder(false, true);
        RelayPullThread relayPuller = bldr.createFellOffRelayPullThread();
        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);
        relayPuller.getMessageQueue().clear();
View Full Code Here

    Set<ServerInfo> relays = clientRtConf.getRelaysSet()// just one relay defined in our clientProps
    List<ServerInfo> relayOrder = new ArrayList<ServerInfo>(relays);

    List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
    sourcesResponse.add(new IdNamePair(1L, "source1"));

    RegisterResponseEntry rre1 = new RegisterResponseEntry(1L, (short)1, SCHEMA$.toString());
    final HashMap<Long, List<RegisterResponseEntry>> registerResponseSources =
        new HashMap<Long, List<RegisterResponseEntry>>()// mapping of sourceId to list of schema versions for that ID
    registerResponseSources.put(1L, Arrays.asList(rre1));
View Full Code Here

    //This guy always fails on /sources
    final MockRelayConnection mockFailConn = new MockRelayConnection(null, null, null, serverIdx);

    List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
    sourcesResponse.add(new IdNamePair(1L, "source1"));

    //This guy succeeds on /sources but fails on /register
    final MockRelayConnection mockSuccessConn =
        new MockRelayConnection(sourcesResponse, null, null, serverIdx);
View Full Code Here

      }
      LOG.info("Relay order:" + sb.toString());
    }

    List<IdNamePair> sourcesResponse = new ArrayList<IdNamePair>();
    sourcesResponse.add(new IdNamePair(1L, "source1"));

    RegisterResponseEntry rre1 = new RegisterResponseEntry(1L, (short)1, SCHEMA$.toString());
    final HashMap<Long, List<RegisterResponseEntry>> registerResponse =
        new HashMap<Long, List<RegisterResponseEntry>>();
    registerResponse.put(1L, Arrays.asList(rre1));
View Full Code Here

        } else if (srcNames.contains(srcName)) {
          throw new RuntimeException("Duplicate Source name (" + srcName + ") present in the file :" + _idNameMapFile);
        }
        srcIds.add(srcId);
        srcNames.add(srcName);
        pairCollection.add(new IdNamePair(Long.valueOf(srcId), srcName));
      }
      _idNameRegistry.updateFromIdNamePairs(pairCollection);
    } finally {
      if ( null != reader)
        reader.close();
View Full Code Here

      s = new TreeSet<String>();
      _physicalToLogicalSrcMap.put(dbName,s);
    }

    s.add(srcName);
    IdNamePair pair = new IdNamePair(Long.valueOf(_maxSrcId), srcName);
    LogicalSource src = new LogicalSource(pair);
    List<LogicalSource> newSources = new ArrayList<LogicalSource>();
    newSources.add(src);
    _idNameRegistry.add(newSources);
View Full Code Here

        sb.append(',');
      DatabusSubscription realSub = sub;
      LogicalSource ls = sub.getLogicalSource();
      if (!ls.idKnown() && !ls.isWildcard())
      {
        IdNamePair sourceEntry = sourceNameMap.get(ls.getName());
        if (null == sourceEntry)
        {
          //this should never happen
          throw new RuntimeException("FATAL! unable to find logical source " + ls.getName() + " in "
                                     + sourceNameMap);
        }
        realSub = new DatabusSubscription(
            sub.getPhysicalSource(), sub.getPhysicalPartition(),
            new LogicalSourceId(new LogicalSource(sourceEntry.getId().intValue(), ls.getName()),
                                sub.getLogicalPartition().getId()));
      }
      sb.append(realSub.toJsonString());
      first = false;
    }
View Full Code Here

      // Generate the list of sources for the sources= parameter to the /stream call.
      // This is needed only for version 2 of the protocol.  For version 3 and higher,
      // we pass a list of subscriptions.
      for (String sourceName: _sourcesConn.getSourcesNames())
      {
        IdNamePair source = sourceNameMap.get(sourceName);
        if (null == source)
        {
          _log.error("Source not found on server: " + sourceName);
          error = true;
          break;
        }
        else
        {
          if (! firstSource) sb.append(',');
          sb.append(source.getId().toString());
          firstSource = false;
          sourcesList.add(source);
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.linkedin.databus.core.util.IdNamePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.