use of com.github.ambry.clustermap.VcrClusterParticipant in project ambry by linkedin.
the class StaticVcrClusterParticipantTest method staticVcrClusterFactoryTest.
@Test
public void staticVcrClusterFactoryTest() throws Exception {
Properties props = new Properties();
String hostName = "localhostTest";
int port = 12345;
List<String> assignedPartitions = Arrays.asList("0", "1");
props.setProperty("clustermap.cluster.name", "test");
props.setProperty("clustermap.datacenter.name", "DC1");
props.setProperty("clustermap.host.name", hostName);
props.setProperty("clustermap.port", Integer.toString(port));
props.setProperty("clustermap.default.partition.class", MockClusterMap.DEFAULT_PARTITION_CLASS);
props.setProperty("clustermap.resolve.hostnames", "false");
props.setProperty("vcr.assigned.partitions", String.join(",", assignedPartitions));
VerifiableProperties vProps = new VerifiableProperties(props);
CloudConfig cloudConfig = new CloudConfig(vProps);
ClusterMapConfig clusterMapConfig = new ClusterMapConfig(vProps);
VcrClusterAgentsFactory factory = new StaticVcrClusterAgentsFactory(cloudConfig, clusterMapConfig, mockClusterMap, null, null, null, new MetricRegistry());
VcrClusterParticipant vcrClusterParticipant = factory.getVcrClusterParticipant();
assertEquals("CloudDataNode host name doesn't match", hostName, vcrClusterParticipant.getCurrentDataNodeId().getHostname());
assertEquals("CloudDataNode port doesn't match", port, vcrClusterParticipant.getCurrentDataNodeId().getPort());
assertTrue("Partition assignment incorrect", assignedPartitions.equals(vcrClusterParticipant.getAssignedPartitionIds().stream().map(partitionId -> partitionId.toPathString()).collect(Collectors.toList())));
assertEquals("Number of CloudDataNode should be 1", 1, vcrClusterParticipant.getAllDataNodeIds().size());
assertEquals("CloudDataNode mismatch", vcrClusterParticipant.getCurrentDataNodeId(), vcrClusterParticipant.getAllDataNodeIds().get(0));
}
use of com.github.ambry.clustermap.VcrClusterParticipant in project ambry by linkedin.
the class HelixVcrClusterParticipantTest method helixVcrClusterParticipant.
/**
* Test addReplica and removeReplica of {@link HelixVcrClusterParticipant}
*/
@Test
public void helixVcrClusterParticipant() throws Exception {
StrictMatchExternalViewVerifier helixBalanceVerifier = new StrictMatchExternalViewVerifier(ZK_CONNECT_STRING, VCR_CLUSTER_NAME, Collections.singleton(VcrTestUtil.helixResource), null);
// Create helixInstance1 and join the cluster. All partitions should be assigned to helixInstance1.
VcrClusterParticipant helixInstance1 = createHelixVcrClusterParticipant(8123, 10123);
Collection<? extends PartitionId> expectedPartitions = Collections.unmodifiableCollection(mockClusterMap.getAllPartitionIds(null));
MockVcrParticipantListener mockVcrListener = new MockVcrParticipantListener();
helixInstance1.addListener(mockVcrListener);
helixInstance1.participate();
TestUtils.checkAndSleep(true, () -> helixInstance1.getAssignedPartitionIds().size() > 0, 1000);
Assert.assertTrue("Helix balance timeout.", helixBalanceVerifier.verify(5000));
Assert.assertTrue("Partition assignment are not correct.", collectionEquals(helixInstance1.getAssignedPartitionIds(), expectedPartitions));
// Create helixInstance2 and join the cluster. Half of partitions should be removed from helixInstance1.
VcrClusterParticipant helixInstance2 = createHelixVcrClusterParticipant(8124, 10124);
helixInstance2.participate();
// Detect any ideal state change first.
TestUtils.checkAndSleep(true, () -> helixInstance1.getAssignedPartitionIds().size() < expectedPartitions.size(), 1000);
Assert.assertTrue("Helix balance timeout.", helixBalanceVerifier.verify(5000));
Assert.assertEquals("Number of partitions removed are not correct.", expectedPartitions.size() / 2, mockVcrListener.getPartitionSet().size());
// Close helixInstance2. All partitions should back to helixInstance1.
helixInstance2.close();
// Detect any ideal state change first.
TestUtils.checkAndSleep(true, () -> helixInstance1.getAssignedPartitionIds().size() > expectedPartitions.size() / 2, 500);
Assert.assertTrue("Helix balance timeout.", helixBalanceVerifier.verify(5000));
Assert.assertTrue("Partition assignment are not correct.", collectionEquals(helixInstance1.getAssignedPartitionIds(), expectedPartitions));
helixInstance1.close();
}
Aggregations