Source:
public void xidTest() throws Exception { if (useComposite) { return; } clusterManager.close(); MockHelixManagerFactory helixManagerFactory = new MockHelixManagerFactory(helixCluster, null); List<InstanceConfig> instanceConfigs = helixCluster.getAllInstanceConfigs(); int instanceCount = instanceConfigs.size(); InstanceConfig aheadInstanceConfig = instanceConfigs.get(com.github.ambry.utils.TestUtils.RANDOM.nextInt(instanceConfigs.size())); aheadInstanceConfig.getRecord().setSimpleField(XID_STR, Long.toString(CURRENT_XID + 1)); HelixClusterManager clusterManager = new HelixClusterManager(clusterMapConfig, hostname, helixManagerFactory, new MetricRegistry()); assertEquals(instanceCount - 1, clusterManager.getDataNodeIds().size()); for (AmbryDataNode dataNode : clusterManager.getDataNodeIds()) { String instanceName = ClusterMapUtils.getInstanceName(dataNode.getHostname(), dataNode.getPort()); assertFalse(instanceName.equals(aheadInstanceConfig.getInstanceName())); } InstanceConfig ignoreInstanceConfig = instanceConfigs.get(com.github.ambry.utils.TestUtils.RANDOM.nextInt(instanceConfigs.size())); String ignoreInstanceName = ignoreInstanceConfig.getInstanceName(); ignoreInstanceConfig.getRecord().setSimpleField(XID_STR, Long.toString(CURRENT_XID + 2)); AmbryReplica ignoreInstanceReplica = null; for (AmbryDataNode dataNode : clusterManager.getDataNodeIds()) { String instanceName = ClusterMapUtils.getInstanceName(dataNode.getHostname(), dataNode.getPort()); if (instanceName.equals(ignoreInstanceName)) { ignoreInstanceReplica = clusterManager.getReplicaIds(dataNode).get(0); ignoreInstanceConfig.getRecord() .setListField(STOPPED_REPLICAS_STR, Collections.singletonList(ignoreInstanceReplica.getPartitionId().toPathString())); } } helixCluster.triggerInstanceConfigChangeNotification(); assertFalse(ignoreInstanceReplica.isDown()); clusterManager.setCurrentXid(CURRENT_XID + 3); helixCluster.triggerInstanceConfigChangeNotification(); assertTrue(ignoreInstanceReplica.isDown()); }

Target:
public void xidTest() throws Exception { if (useComposite) { return; } clusterManager.close(); MockHelixManagerFactory helixManagerFactory = new MockHelixManagerFactory(helixCluster, null); List<InstanceConfig> instanceConfigs = helixCluster.getAllInstanceConfigs(); int instanceCount = instanceConfigs.size(); InstanceConfig aheadInstanceConfig = instanceConfigs.get(com.github.ambry.utils.TestUtils.RANDOM.nextInt(instanceConfigs.size())); aheadInstanceConfig.getRecord().setSimpleField(XID_STR, Long.toString(CURRENT_XID + 1)); HelixClusterManager clusterManager = new HelixClusterManager(clusterMapConfig, hostname, helixManagerFactory, new MetricRegistry()); assertEquals(instanceCount - 1, clusterManager.getDataNodeIds().size()); for (AmbryDataNode dataNode : clusterManager.getDataNodeIds()) { String instanceName = ClusterMapUtils.getInstanceName(dataNode.getHostname(), dataNode.getPort()); assertFalse(instanceName.equals(aheadInstanceConfig.getInstanceName())); } InstanceConfig ignoreInstanceConfig = instanceConfigs.get(com.github.ambry.utils.TestUtils.RANDOM.nextInt(instanceConfigs.size())); String ignoreInstanceName = ignoreInstanceConfig.getInstanceName(); ignoreInstanceConfig.getRecord().setSimpleField(XID_STR, Long.toString(CURRENT_XID + 2)); AmbryReplica ignoreInstanceReplica = null; for (AmbryDataNode dataNode : clusterManager.getDataNodeIds()) { String instanceName = ClusterMapUtils.getInstanceName(dataNode.getHostname(), dataNode.getPort()); if (instanceName.equals(ignoreInstanceName)) { ignoreInstanceReplica = clusterManager.getReplicaIds(dataNode).get(0); ignoreInstanceConfig.getRecord() .setListField(STOPPED_REPLICAS_STR, Collections.singletonList(ignoreInstanceReplica.getPartitionId().toPathString())); break; } } helixCluster.triggerInstanceConfigChangeNotification(); assertFalse(ignoreInstanceReplica.isDown()); ignoreInstanceConfig.getRecord().setSimpleField(XID_STR, Long.toString(CURRENT_XID - 2)); helixCluster.triggerInstanceConfigChangeNotification(); assertTrue(ignoreInstanceReplica.isDown()); }