Search in sources :

Example 1 with VcrClusterParticipant

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));
}
Also used : VcrClusterAgentsFactory(com.github.ambry.clustermap.VcrClusterAgentsFactory) Arrays(java.util.Arrays) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VcrClusterAgentsFactory(com.github.ambry.clustermap.VcrClusterAgentsFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test) Collectors(java.util.stream.Collectors) CloudConfig(com.github.ambry.config.CloudConfig) List(java.util.List) VcrClusterParticipant(com.github.ambry.clustermap.VcrClusterParticipant) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) Assert(org.junit.Assert) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Before(org.junit.Before) VcrClusterParticipant(com.github.ambry.clustermap.VcrClusterParticipant) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) CloudConfig(com.github.ambry.config.CloudConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 2 with VcrClusterParticipant

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();
}
Also used : StrictMatchExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier) VcrClusterParticipant(com.github.ambry.clustermap.VcrClusterParticipant) Test(org.junit.Test)

Aggregations

VcrClusterParticipant (com.github.ambry.clustermap.VcrClusterParticipant)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 MockClusterAgentsFactory (com.github.ambry.clustermap.MockClusterAgentsFactory)1 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)1 VcrClusterAgentsFactory (com.github.ambry.clustermap.VcrClusterAgentsFactory)1 CloudConfig (com.github.ambry.config.CloudConfig)1 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)1 VerifiableProperties (com.github.ambry.config.VerifiableProperties)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1 StrictMatchExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.StrictMatchExternalViewVerifier)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1