Package com.linkedin.databus.core

Examples of com.linkedin.databus.core.Checkpoint


  /** Tests ServerSet change when in Target_Scn_Request_Sent */
  public void testServerSetChange_TargetScnRequestSent() throws Exception
  {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true);

    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
    //TODO remove
//    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
//    cp.setSnapshotSource("source1");
//    cp.setCatchupSource("source1");

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);

    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
    bsPuller.getMessageQueue().clear();
    Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();

    entries.put(1L, new ArrayList<RegisterResponseEntry>());
    connState.setSourcesSchemas(entries);
    connState.setCurrentBSServerInfo(bsPuller.getCurentServer());

    testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
    bsPuller.getMessageQueue().clear();

    connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
    connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
    testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);

    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);

    bsPuller.getMessageQueue().clear();
    cp.setSnapshotOffset(-1);
    testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
    Assert.assertTrue(cp.isSnapShotSourceCompleted(), "Phase completed");
    Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
    Assert.assertFalse(cp.isBootstrapTargetScnSet());

    bsPuller.getMessageQueue().clear();
    MockBootstrapConnection mockConn = (MockBootstrapConnection) connState.getBootstrapConnection();
    mockConn.setMuteTransition(true);
    testTransitionCase(bsPuller, StateId.REQUEST_TARGET_SCN, StateId.TARGET_SCN_REQUEST_SENT, "", null);

    // ServerSetChange when New Set includes CurrentServer
    {
      Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
      Assert.assertEquals(bsPuller.getCurentServer() != null, true, "Current Server not Null");
      ServerInfo oldServer = bsPuller.getCurentServer();
      Assert.assertEquals(bsPuller.getServers(),EXP_SERVERINFO_1,"Server Set");

      entries = new HashMap<Long, List<RegisterResponseEntry>>();
      entries.put(1L, new ArrayList<RegisterResponseEntry>());
      connState.setSourcesSchemas(entries);

      doExecuteAndChangeState(bsPuller,createSetServerMessage(true, bsPuller));
      Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
      Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
      Assert.assertEquals(bsPuller.getServers(),EXP_SERVERINFO_2,"Server Set");
      Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
      Assert.assertEquals(connState.getStateId(),StateId.TARGET_SCN_REQUEST_SENT, "ServerSetChange while TARGET_SCN_REQUEST_SENT");
      Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while TARGET_SCN_REQUEST_SENT");
      Assert.assertTrue(cp.isSnapShotSourceCompleted(), "Phase completed");
      Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
    }

    // ServerSetChange when New Set excludes CurrentServer and SuccessFul Response
    {
      int oldServerIndex = bsPuller.getCurrentServerIdx();
      ServerInfo oldServer = bsPuller.getCurentServer();
      Assert.assertEquals(bsPuller.getServers(),EXP_SERVERINFO_2,"Server Set");

      entries = new HashMap<Long, List<RegisterResponseEntry>>();
      entries.put(1L, new ArrayList<RegisterResponseEntry>());
      connState.setSourcesSchemas(entries);

      doExecuteAndChangeState(bsPuller,createSetServerMessage(false, bsPuller));
      Assert.assertEquals(bsPuller.getCurrentServerIdx(), oldServerIndex, "Current Server Index unchanged");
      Assert.assertEquals(bsPuller.getCurentServer(), oldServer, "Current Server unchanged");
      Assert.assertEquals(bsPuller.getServers(),EXP_SERVERINFO_3,"Server Set");
      Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), true, "Tear Conn After Handling Response");
      Assert.assertEquals(connState.getStateId(),StateId.TARGET_SCN_REQUEST_SENT, "ServerSetChange while TARGET_SCN_REQUEST_SENT");
      Assert.assertEquals(bsPuller.getQueueListString(), "RelayPuller queue: []", "Queue :ServerSetChange while TARGET_SCN_REQUEST_SENT");

      // Now Response arrives
      connState.switchToStartScnSuccess(cp, null, null);
      testTransitionCase(bsPuller, StateId.TARGET_SCN_REQUEST_SENT, StateId.PICK_SERVER, null);
      Assert.assertEquals(bsPuller.toTearConnAfterHandlingResponse(), false, "Tear Conn After Handling Response");
      Assert.assertEquals(bsPuller.getCurrentServerIdx() == -1, true, "Current Server Index undefined");
      Assert.assertEquals(bsPuller.getCurentServer() == null, true, "Current Server Null");
      Assert.assertTrue(cp.isSnapShotSourceCompleted(), "Phase completed");
      Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
    }
  }
View Full Code Here


  {
    boolean success = true;

    if (event.isCheckpointMessage())
    {
      Checkpoint ckpt = null;
      try
      {
        ckpt = DbusEventUtils.getCheckpointFromEvent(event);
        DbusClientMode bootstrapMode = ckpt.getConsumptionMode();

        if (bootstrapMode != DbusClientMode.ONLINE_CONSUMPTION)
        {
          if(_bootstrapPuller == null) {
            _log.error("Checkpoint specifies that the consumer is bootstrapping, but bootstrapPuller is not present (Is bootstrap disabled ?)");
            return false;
          }
          ckpt.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
          if (curState.getStateId() != DispatcherState.StateId.EXPECT_EVENT_WINDOW)
          {
            _log.warn("The current state of the dispatcher is NOT as expected (" + DispatcherState.StateId.EXPECT_EVENT_WINDOW.name() + "). State prior to this: " + curState.getStateId().name());
            //Fixing bug that caused TestRelayBootstrapSwitch to fail; no apparent need to rollback
            //curState.switchToRollback();
View Full Code Here

  /** Test ServerSet change when in Target_Scn_Response_ Success state */
  public void testServerSetChange_TargetScnResponseSuccess() throws Exception
  {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false, false, false, null, 12000, 1, true);

    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);
    //TODO remove
//    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
//    cp.setSnapshotSource("source1");
//    cp.setCatchupSource("source1");

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);

    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.REQUEST_START_SCN, StateId.START_SCN_RESPONSE_SUCCESS, null);
    bsPuller.getMessageQueue().clear();
    Map<Long, List<RegisterResponseEntry>> entries = new HashMap<Long, List<RegisterResponseEntry>>();

    entries.put(1L, new ArrayList<RegisterResponseEntry>());
    connState.setSourcesSchemas(entries);
    connState.setCurrentBSServerInfo(bsPuller.getCurentServer());

    testTransitionCase(bsPuller, StateId.START_SCN_RESPONSE_SUCCESS, StateId.REQUEST_STREAM, null);
    bsPuller.getMessageQueue().clear();

    connState.getSourcesNameMap().put("source1", new IdNamePair(1L, "source1"));
    connState.getSourceIdMap().put(1L, new IdNamePair(1L, "source1"));
    testTransitionCase(bsPuller, StateId.REQUEST_STREAM, StateId.STREAM_REQUEST_SUCCESS, null);

    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.STREAM_REQUEST_SUCCESS, StateId.STREAM_RESPONSE_DONE, null);

    bsPuller.getMessageQueue().clear();
    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    cp.setSnapshotOffset(-1);
    testTransitionCase(bsPuller, StateId.STREAM_RESPONSE_DONE, StateId.REQUEST_TARGET_SCN, null);
    Assert.assertTrue(cp.isSnapShotSourceCompleted(), "Phase completed");
    Assert.assertEquals(cp.getConsumptionMode(), DbusClientMode.BOOTSTRAP_SNAPSHOT, "Consumption Mode check");
    Assert.assertFalse(cp.isBootstrapTargetScnSet());

    bsPuller.getMessageQueue().clear();
    testTransitionCase(bsPuller, StateId.REQUEST_TARGET_SCN, StateId.TARGET_SCN_RESPONSE_SUCCESS, null);
    Assert.assertTrue(cp.isBootstrapTargetScnSet());
    Assert.assertEquals(cp.getBootstrapTargetScn().longValue(), 10L);

    // ServerSetChange when New Set includes CurrentServer
    {
      Assert.assertEquals(bsPuller.getCurrentServerIdx() != -1, true, "Current Server Index defined");
      Assert.assertEquals(bsPuller.getCurentServer() != null, true, "Current Server not Null");
View Full Code Here

        long targetScn = Long.parseLong(scnString);

        _stateReuse.switchToTargetScnSuccess();

        // make sure we are in the expected mode -- sanity checks
        Checkpoint ckpt = _checkpoint;
        if (ckpt.getConsumptionMode() != DbusClientMode.BOOTSTRAP_SNAPSHOT)
        {
          throw new InvalidCheckpointException("TargetScnResponseProcessor:"
                                     + " expecting in client mode: " + DbusClientMode.BOOTSTRAP_SNAPSHOT,
                                     ckpt);
        }
        else if (! ckpt.isSnapShotSourceCompleted())
        {
          throw new InvalidCheckpointException("TargetScnResponseProcessor: current snapshot source not completed",
                                               ckpt);
        }

        LOG.info("Target SCN "
                 + targetScn
                 + " received for bootstrap catchup source "
                 + ckpt.getCatchupSource()
                 + " after completion of snapshot source "
                 + ckpt.getSnapshotSource());
        ckpt.setBootstrapTargetScn(targetScn);
      }
    }
    catch (Exception ex)
    {
      LOG.error("/targetScn response error:" + ex.getMessage(), ex);
View Full Code Here

          LOG.error("Unable to extract Boostrap Server info from StartSCN response. ServerInfo was :" + serverHostPort, ex);
        }

        LOG.info("Response startScn:" + scnString + ", from bootstrap Server :" + serverHostPort);
        long startScn = Long.parseLong(scnString);
        Checkpoint ckpt = _checkpoint;

        if (startScn < 0)
        {
          LOG.error("unexpected value for startSCN: " + startScn);
          _stateReuse.switchToStartScnResponseError();
        }
        else if (ckpt.getConsumptionMode() != DbusClientMode.BOOTSTRAP_SNAPSHOT)
        {
          LOG.error("StartScnResponseProcessor:" + " expecting in client mode: " + DbusClientMode.BOOTSTRAP_SNAPSHOT
                    + " while in the incorrect mode: " + ckpt.getConsumptionMode());
        }
        else
        {
          LOG.info("Start SCN "
                    + startScn
                    + " received for bootstrap snapshot source "
                    + ckpt.getSnapshotSource());
          ckpt.setBootstrapStartScn(startScn);
          ckpt.setBootstrapServerInfo(serverHostPort);

          /*
           * No need to create a seperate BootstrapConnection as we are guaranteed to have a bootstrap Connection
           * at this point.
           */
 
View Full Code Here

  @Test
  /** Test BOOTSTRAP transitions - Happy Path without startScn */
  public void testTransition_HappyPathWithoutStartScn() throws Exception
  {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 0L);

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
View Full Code Here

  @Test
  /** Test BOOTSTRAP transitions - Happy Path with startScn */
  public void testTransition_HappyPathWithStartScn() throws Exception
  {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 50L);
    //TODO remove
    //cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    cp.setBootstrapServerInfo(_serverInfoName);
    cp.setBootstrapStartScn(100L);

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    //cp.setBootstrapSinceScn(50L);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_STREAM, cp);
    ServerInfo bstServerInfo = ServerInfo.buildServerInfoFromHostPort(cp.getBootstrapServerInfo(),
                                                                      DbusConstants.HOSTPORT_DELIMITER);
    Assert.assertEquals(bsPuller.getConnectionState().getCurrentBSServerInfo(), bstServerInfo);
    Assert.assertEquals(cp.getBootstrapStartScn().longValue(), 100L, "Cleared Bootstrap StartSCN");
    Assert.assertEquals(cp.getBootstrapSinceScn().longValue(), 50L, "Cleared Bootstrap SinceSCN");
    String actualHost = bsPuller.getCurentServer().getAddress().getHostName();
    int actualPort = bsPuller.getCurentServer().getAddress().getPort();
    Assert.assertEquals(actualHost, _host, "Current Server Host Check");
    Assert.assertEquals(actualPort, _port, "Server Port Check");
    int numRetries = bsPuller.getRetriesBeforeCkptCleanup().getRemainingRetriesNum();
View Full Code Here

  @Test
  /** Test BOOTSTRAP transitions - Bootstrap Restart since no serverInfo */
  public void testTransition_RestartWithNoServerInfo() throws Exception
  {
    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 50L);
    cp.setBootstrapStartScn(1111L);

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
    Assert.assertEquals(cp.getBootstrapStartScn().longValue(),
                        Checkpoint.UNSET_BOOTSTRAP_START_SCN, "Cleared Bootstrap StartSCN");
    Assert.assertEquals(cp.getBootstrapSinceScn().longValue(), 50L, "Cleared Bootstrap SinceSCN");
    int numRetries = bsPuller.getRetriesBeforeCkptCleanup().getRemainingRetriesNum();
    Assert.assertEquals(numRetries, 1000, "NumRetries Check");
  }
View Full Code Here

  {
    final String dummyHost = "NonExistantHost";
    final String dummyServerInfoName = dummyHost + ":" + _port;

    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 50L);
    //TODO remove
    //cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    //cp.setBootstrapSinceScn(900L);
    cp.setBootstrapStartScn(1111L);
    cp.setBootstrapServerInfo(dummyServerInfoName);

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
    Assert.assertEquals(cp.getBootstrapStartScn().longValue(),
                        Checkpoint.UNSET_BOOTSTRAP_START_SCN, "Cleared Bootstrap StartSCN");
    Assert.assertEquals(cp.getBootstrapSinceScn().longValue(), 50L, "Cleared Bootstrap SinceSCN");
    int numRetries = bsPuller.getRetriesBeforeCkptCleanup().getRemainingRetriesNum();
    Assert.assertEquals(numRetries, 1000, "NumRetries Check");
  }
View Full Code Here

  {
    final String dummyHost = "NonExistantHost";
    final String malformedServerInfoName = dummyHost + _port; // no delim

    BootstrapPullThread bsPuller = createBootstrapPullThread(false, false, false);
    Checkpoint cp = _ckptHandlerSource1.createInitialBootstrapCheckpoint(null, 50L);
    //TODO remove
    //cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    //cp.setBootstrapSinceScn(900L);
    cp.setBootstrapStartScn(1111L);
    cp.setBootstrapServerInfo(malformedServerInfoName);

    bsPuller.getComponentStatus().start();
    ConnectionState connState = bsPuller.getConnectionState();
    connState.switchToBootstrap(cp);
    //cp.setBootstrapSinceScn(50L);
    testTransitionCase(bsPuller, StateId.BOOTSTRAP, StateId.REQUEST_START_SCN, cp);
    Assert.assertEquals(cp.getBootstrapStartScn().longValue(),
                        Checkpoint.UNSET_BOOTSTRAP_START_SCN, "Cleared Bootstrap StartSCN");
    Assert.assertEquals(cp.getBootstrapSinceScn().longValue(), 50L, "Cleared Bootstrap SinceSCN");
    int numRetries = bsPuller.getRetriesBeforeCkptCleanup().getRemainingRetriesNum();
    Assert.assertEquals(numRetries, 1000, "NumRetries Check");
  }
View Full Code Here

TOP

Related Classes of com.linkedin.databus.core.Checkpoint

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.