Search in sources :

Example 36 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class DatacenterTest method validation.

@Test
public void validation() throws JSONException {
    JSONObject jsonObject;
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
        // Null HardwareLayout
        jsonObject = TestUtils.getJsonDatacenter("XYZ1", (byte) 1, getDataNodes());
        new Datacenter(null, jsonObject, clusterMapConfig);
        fail("Should have failed validation.");
    } catch (IllegalStateException e) {
    // Expected.
    }
    // Bad datacenter name
    jsonObject = TestUtils.getJsonDatacenter("", (byte) 1, getDataNodes());
    failValidation(jsonObject, clusterMapConfig);
    // Missing rack IDs
    jsonObject = TestUtils.getJsonDatacenter("XYZ1", (byte) 1, getDataNodesPartiallyRackAware());
    failValidation(jsonObject, clusterMapConfig);
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 37 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class DiskTest method basics.

@Test
public void basics() throws JSONException {
    JSONObject jsonObject = TestUtils.getJsonDisk("/mnt1", HardwareState.AVAILABLE, 100 * 1024 * 1024 * 1024L);
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    Disk testDisk = new TestDisk(jsonObject, clusterMapConfig);
    assertEquals(testDisk.getMountPath(), "/mnt1");
    assertEquals(testDisk.getHardState(), HardwareState.AVAILABLE);
    assertEquals(testDisk.getRawCapacityInBytes(), 100 * 1024 * 1024 * 1024L);
    assertEquals(testDisk.toJSONObject().toString(), jsonObject.toString());
    assertEquals(testDisk, new TestDisk(testDisk.toJSONObject(), clusterMapConfig));
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 38 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class HardwareLayoutTest method basics.

@Test
public void basics() throws JSONException {
    JSONObject jsonObject = TestUtils.getJsonHardwareLayout("Alpha", getDatacenters());
    HardwareLayout hardwareLayout = new HardwareLayout(jsonObject, new ClusterMapConfig(new VerifiableProperties(props)));
    assertEquals(hardwareLayout.getVersion(), TestUtils.defaultHardwareLayoutVersion);
    assertEquals(hardwareLayout.getClusterName(), "Alpha");
    assertEquals(hardwareLayout.getDatacenters().size(), datacenterCount);
    assertEquals(hardwareLayout.getRawCapacityInBytes(), datacenterCount * dataNodeCount * diskCount * diskCapacityInBytes);
    assertEquals(hardwareLayout.toJSONObject().toString(), jsonObject.toString());
    assertEquals(hardwareLayout.getDataNodeInHardStateCount(HardwareState.AVAILABLE), datacenterCount * dataNodeCount);
    assertEquals(hardwareLayout.getDataNodeInHardStateCount(HardwareState.UNAVAILABLE), 0);
    assertEquals(hardwareLayout.calculateUnavailableDataNodeCount(), 0);
    assertEquals(hardwareLayout.getDiskInHardStateCount(HardwareState.AVAILABLE), datacenterCount * dataNodeCount * diskCount);
    assertEquals(hardwareLayout.getDiskInHardStateCount(HardwareState.UNAVAILABLE), 0);
    assertEquals(hardwareLayout.calculateUnavailableDiskCount(), 0);
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 39 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class HelixClusterManagerTest method badInstantiationTest.

/**
 * Test bad instantiation.
 * @throws Exception
 */
@Test
public void badInstantiationTest() throws Exception {
    // Good test happened in the constructor
    assertEquals(0L, metricRegistry.getGauges().get(HelixClusterManager.class.getName() + ".instantiationFailed").getValue());
    // Bad test
    Set<com.github.ambry.utils.TestUtils.ZkInfo> zkInfos = new HashSet<>(dcsToZkInfo.values());
    zkInfos.iterator().next().setPort(0);
    JSONObject invalidZkJson = constructZkLayoutJSON(zkInfos);
    Properties props = new Properties();
    props.setProperty("clustermap.host.name", hostname);
    props.setProperty("clustermap.cluster.name", clusterNamePrefixInHelix + clusterNameStatic);
    props.setProperty("clustermap.datacenter.name", dcs[0]);
    props.setProperty("clustermap.dcs.zk.connect.strings", invalidZkJson.toString(2));
    ClusterMapConfig invalidClusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    metricRegistry = new MetricRegistry();
    try {
        new HelixClusterManager(invalidClusterMapConfig, hostname, new MockHelixManagerFactory(helixCluster, null), metricRegistry);
        fail("Instantiation should have failed with invalid zk addresses");
    } catch (IOException e) {
        assertEquals(1L, metricRegistry.getGauges().get(HelixClusterManager.class.getName() + ".instantiationFailed").getValue());
    }
    metricRegistry = new MetricRegistry();
    try {
        new HelixClusterManager(clusterMapConfig, hostname, new MockHelixManagerFactory(helixCluster, new Exception("beBad")), metricRegistry);
        fail("Instantiation should fail with a HelixManager factory that throws exception on listener registrations");
    } catch (Exception e) {
        assertEquals(1L, metricRegistry.getGauges().get(HelixClusterManager.class.getName() + ".instantiationFailed").getValue());
        assertEquals("beBad", e.getCause().getMessage());
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) IOException(java.io.IOException) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) IOException(java.io.IOException) JSONObject(org.json.JSONObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class HelixParticipantTest method testSetReplicaSealedState.

/**
 * Tests setReplicaSealedState method for {@link HelixParticipant}
 * @throws IOException
 */
@Test
public void testSetReplicaSealedState() throws IOException {
    // setup HelixParticipant and dependencies
    String partitionIdStr = "somePartitionId";
    String partitionIdStr2 = "someOtherPartitionId";
    ReplicaId replicaId = createMockAmbryReplica(partitionIdStr);
    ReplicaId replicaId2 = createMockAmbryReplica(partitionIdStr2);
    String hostname = "localhost";
    int port = 2200;
    String instanceName = ClusterMapUtils.getInstanceName(hostname, port);
    HelixParticipant helixParticipant = new HelixParticipant(new ClusterMapConfig(new VerifiableProperties(props)), helixManagerFactory);
    helixParticipant.initialize(hostname, port, Collections.EMPTY_LIST);
    HelixManager helixManager = helixManagerFactory.getZKHelixManager(null, null, null, null);
    HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
    InstanceConfig instanceConfig = new InstanceConfig("someInstanceId");
    helixAdmin.setInstanceConfig(clusterName, instanceName, instanceConfig);
    // Make sure the current sealedReplicas list is null
    List<String> sealedReplicas = ClusterMapUtils.getSealedReplicas(instanceConfig);
    assertNull("sealedReplicas is not null", sealedReplicas);
    String listName = "sealedReplicas";
    // Check that invoking setReplicaSealedState with a non-AmbryReplica ReplicaId throws an IllegalArgumentException
    ReplicaId notAmbryReplica = createMockNotAmbryReplica(partitionIdStr);
    try {
        helixParticipant.setReplicaSealedState(notAmbryReplica, true);
        fail("Expected an IllegalArgumentException here");
    } catch (IllegalArgumentException e) {
    // Expected exception
    }
    // Check that invoking setReplicaSealedState adds the partition to the list of sealed replicas
    helixParticipant.setReplicaSealedState(replicaId, true);
    sealedReplicas = ClusterMapUtils.getSealedReplicas(helixAdmin.getInstanceConfig(clusterName, instanceName));
    listIsExpectedSize(sealedReplicas, 1, listName);
    assertTrue(sealedReplicas.contains(partitionIdStr));
    // Seal another replicaId
    helixParticipant.setReplicaSealedState(replicaId2, true);
    sealedReplicas = ClusterMapUtils.getSealedReplicas(helixAdmin.getInstanceConfig(clusterName, instanceName));
    listIsExpectedSize(sealedReplicas, 2, listName);
    assertTrue(sealedReplicas.contains(partitionIdStr2));
    assertTrue(sealedReplicas.contains(partitionIdStr));
    // Check that sealed replica list doesn't take duplicates (and that dups are detected by partitionId comparison, not
    // replicaId object comparison
    ReplicaId dup = createMockAmbryReplica(partitionIdStr);
    helixParticipant.setReplicaSealedState(dup, true);
    helixParticipant.setReplicaSealedState(replicaId2, true);
    sealedReplicas = ClusterMapUtils.getSealedReplicas(helixAdmin.getInstanceConfig(clusterName, instanceName));
    listIsExpectedSize(sealedReplicas, 2, listName);
    assertTrue(sealedReplicas.contains(partitionIdStr2));
    assertTrue(sealedReplicas.contains(partitionIdStr));
    // Check that invoking setReplicaSealedState with isSealed == false removes partition from list of sealed replicas
    helixParticipant.setReplicaSealedState(replicaId, false);
    sealedReplicas = ClusterMapUtils.getSealedReplicas(helixAdmin.getInstanceConfig(clusterName, instanceName));
    listIsExpectedSize(sealedReplicas, 1, listName);
    assertTrue(sealedReplicas.contains(partitionIdStr2));
    assertFalse(sealedReplicas.contains(partitionIdStr));
    // Removing a replicaId that's already been removed doesn't hurt anything
    helixParticipant.setReplicaSealedState(replicaId, false);
    sealedReplicas = ClusterMapUtils.getSealedReplicas(helixAdmin.getInstanceConfig(clusterName, instanceName));
    listIsExpectedSize(sealedReplicas, 1, listName);
    // Removing all replicas yields expected behavior (and removal works by partitionId, not replicaId itself)
    dup = createMockAmbryReplica(partitionIdStr2);
    helixParticipant.setReplicaSealedState(dup, false);
    sealedReplicas = ClusterMapUtils.getSealedReplicas(helixAdmin.getInstanceConfig(clusterName, instanceName));
    listIsExpectedSize(sealedReplicas, 0, listName);
}
Also used : HelixManager(org.apache.helix.HelixManager) InstanceConfig(org.apache.helix.model.InstanceConfig) VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixAdmin(org.apache.helix.HelixAdmin) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Aggregations

VerifiableProperties (com.github.ambry.config.VerifiableProperties)137 Properties (java.util.Properties)88 Test (org.junit.Test)71 MetricRegistry (com.codahale.metrics.MetricRegistry)42 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)40 BlobProperties (com.github.ambry.messageformat.BlobProperties)35 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)25 StoreConfig (com.github.ambry.config.StoreConfig)25 ArrayList (java.util.ArrayList)25 ClusterMap (com.github.ambry.clustermap.ClusterMap)24 IOException (java.io.IOException)21 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)20 RouterConfig (com.github.ambry.config.RouterConfig)18 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClusterAgentsFactory (com.github.ambry.clustermap.ClusterAgentsFactory)15 MockTime (com.github.ambry.utils.MockTime)14 BlobId (com.github.ambry.commons.BlobId)13 HashMap (java.util.HashMap)12 File (java.io.File)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11