Java Code Examples for org.apache.helix.model.CurrentState#getTriggerHost()

The following examples show how to use org.apache.helix.model.CurrentState#getTriggerHost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestP2PNoDuplicatedMessage.java    From helix with Apache License 2.0 6 votes vote down vote up
private void verifyP2PDisabled() {
  ResourceControllerDataProvider dataCache = new ResourceControllerDataProvider(CLUSTER_NAME);
  dataCache.refresh(_accessor);
  Map<String, LiveInstance> liveInstanceMap = dataCache.getLiveInstances();

  for (LiveInstance instance : liveInstanceMap.values()) {
    Map<String, CurrentState> currentStateMap =
        dataCache.getCurrentState(instance.getInstanceName(), instance.getEphemeralOwner());
    Assert.assertNotNull(currentStateMap);
    for (CurrentState currentState : currentStateMap.values()) {
      for (String partition : currentState.getPartitionStateMap().keySet()) {
        String state = currentState.getState(partition);
        if (state.equalsIgnoreCase("MASTER")) {
          String triggerHost = currentState.getTriggerHost(partition);
          Assert.assertEquals(triggerHost, _controllerName,
              state + " of " + partition + " on " + instance.getInstanceName()
                  + " was triggered by " + triggerHost);
        }
      }
    }
  }
}
 
Example 2
Source File: TestP2PNoDuplicatedMessage.java    From helix with Apache License 2.0 6 votes vote down vote up
private void verifyP2PEnabled(long startTime) {
  ResourceControllerDataProvider dataCache = new ResourceControllerDataProvider(CLUSTER_NAME);
  dataCache.refresh(_accessor);
  Map<String, LiveInstance> liveInstanceMap = dataCache.getLiveInstances();

  for (LiveInstance instance : liveInstanceMap.values()) {
    Map<String, CurrentState> currentStateMap =
        dataCache.getCurrentState(instance.getInstanceName(), instance.getEphemeralOwner());
    Assert.assertNotNull(currentStateMap);
    for (CurrentState currentState : currentStateMap.values()) {
      for (String partition : currentState.getPartitionStateMap().keySet()) {
        String state = currentState.getState(partition);
        long start = currentState.getStartTime(partition);
        if (state.equalsIgnoreCase("MASTER") && start > startTime) {
          String triggerHost = currentState.getTriggerHost(partition);
          if (!triggerHost.equals(_controllerName)) {
            p2pTrigged ++;
          }
          total ++;
        }
      }
    }
  }
}
 
Example 3
Source File: TestP2PMessageSemiAuto.java    From helix with Apache License 2.0 5 votes vote down vote up
private void verifyP2PMessage(String dbName, String instance, String expectedState,
    String expectedTriggerHost, double expectedRatio) {
  ResourceControllerDataProvider dataCache = new ResourceControllerDataProvider(CLUSTER_NAME);
  dataCache.refresh(_accessor);

  Map<String, LiveInstance> liveInstanceMap = dataCache.getLiveInstances();
  LiveInstance liveInstance = liveInstanceMap.get(instance);

  Map<String, CurrentState> currentStateMap =
      dataCache.getCurrentState(instance, liveInstance.getEphemeralOwner());
  Assert.assertNotNull(currentStateMap);
  CurrentState currentState = currentStateMap.get(dbName);
  Assert.assertNotNull(currentState);
  Assert.assertEquals(currentState.getPartitionStateMap().size(), PARTITION_NUMBER);

  int total = 0;
  int expectedHost = 0;
  for (String partition : currentState.getPartitionStateMap().keySet()) {
    String state = currentState.getState(partition);
    Assert.assertEquals(state, expectedState,
        dbName + " Partition " + partition + "'s state is different as expected!");
    String triggerHost = currentState.getTriggerHost(partition);
    if (triggerHost.equals(expectedTriggerHost)) {
      expectedHost++;
    }
    total++;
  }

  double ratio = ((double) expectedHost) / ((double) total);
  Assert.assertTrue(ratio >= expectedRatio,
      String.format(
          "Only %d out of %d percent transitions to Master were triggered by expected host!",
          expectedHost, total));
}