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);
}
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));
}
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);
}
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());
}
}
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);
}
Aggregations