use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class ClusterChangeHandlerTest method initializationFailureTest.
/**
* Test failure case when initializing {@link HelixClusterManager} with dynamic cluster change handler
*/
@Test
public void initializationFailureTest() {
// save current local dc for restore purpose
int savedport = dcsToZkInfo.get(localDc).getPort();
// mock local dc connectivity issue
dcsToZkInfo.get(localDc).setPort(0);
JSONObject invalidZkJson = constructZkLayoutJSON(dcsToZkInfo.values());
Properties properties = new Properties();
properties.putAll(props);
properties.setProperty("clustermap.dcs.zk.connect.strings", invalidZkJson.toString(2));
properties.setProperty("clustermap.cluster.change.handler.type", "DynamicClusterChangeHandler");
ClusterMapConfig invalidClusterMapConfig = new ClusterMapConfig(new VerifiableProperties(properties));
MetricRegistry metricRegistry = new MetricRegistry();
try {
new HelixClusterManager(invalidClusterMapConfig, selfInstanceName, helixManagerFactory, metricRegistry);
fail("Instantiation with dynamic cluster change handler should fail due to connection issue to zk");
} catch (IOException e) {
assertEquals(1L, metricRegistry.getGauges().get(HelixClusterManager.class.getName() + ".instantiationFailed").getValue());
assertEquals(1L, metricRegistry.getGauges().get(HelixClusterManager.class.getName() + ".instantiationExceptionCount").getValue());
}
// restore original setup
dcsToZkInfo.get(localDc).setPort(savedport);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class DataNodeTest method testSoftState.
@Test
public void testSoftState() throws JSONException, InterruptedException {
JSONObject jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 7666, 8666, HardwareState.AVAILABLE, getDisks());
Properties props = new Properties();
props.setProperty("clustermap.fixedtimeout.datanode.retry.backoff.ms", Integer.toString(2000));
props.setProperty("clustermap.cluster.name", "test");
props.setProperty("clustermap.datacenter.name", "dc1");
props.setProperty("clustermap.host.name", "localhost");
ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
int threshold = clusterMapConfig.clusterMapFixedTimeoutDatanodeErrorThreshold;
long retryBackoffMs = clusterMapConfig.clusterMapFixedTimeoutDataNodeRetryBackoffMs;
DataNode dataNode = new TestDataNode("datacenter", jsonObject, clusterMapConfig);
for (int i = 0; i < threshold; i++) {
ensure(dataNode, HardwareState.AVAILABLE);
dataNode.onNodeTimeout();
}
// After threshold number of continuous errors, the resource should be unavailable
ensure(dataNode, HardwareState.UNAVAILABLE);
Thread.sleep(retryBackoffMs + 1);
// If retryBackoffMs has passed, the resource should be available.
ensure(dataNode, HardwareState.AVAILABLE);
// A single timeout should make the node unavailable now
dataNode.onNodeTimeout();
ensure(dataNode, HardwareState.UNAVAILABLE);
// A single response should make the node available now
dataNode.onNodeResponse();
ensure(dataNode, HardwareState.AVAILABLE);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class DataNodeTest method validateGetPort.
/**
* Validate {@link DataNodeId#getPortToConnectTo()} returns port type corresponding to the
* SSL enabled datacenter list specified in {@link ClusterMapConfig}.
* @throws Exception
*/
@Test
public void validateGetPort() throws Exception {
ClusterMapConfig clusterMapConfig;
Properties props = new Properties();
props.setProperty("clustermap.ssl.enabled.datacenters", "datacenter1,datacenter2,datacenter3");
props.setProperty("clustermap.cluster.name", "test");
props.setProperty("clustermap.datacenter.name", "dc1");
props.setProperty("clustermap.host.name", "localhost");
clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
System.out.println(clusterMapConfig.clusterMapSslEnabledDatacenters);
JSONObject jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 7666, 8666, HardwareState.AVAILABLE, getDisks());
DataNode dataNode = new TestDataNode("datacenter2", jsonObject, clusterMapConfig);
assertEquals("The datacenter of the data node is in the ssl enabled datacenter list. SSL port should be returned", PortType.SSL, dataNode.getPortToConnectTo().getPortType());
dataNode = new TestDataNode("datacenter5", jsonObject, clusterMapConfig);
assertEquals("The datacenter of the data node is not in the ssl enabled datacenter list. Plaintext port should be returned", PortType.PLAINTEXT, dataNode.getPortToConnectTo().getPortType());
jsonObject.remove("sslport");
dataNode = new TestDataNode("datacenter1", jsonObject, clusterMapConfig);
try {
dataNode.getPortToConnectTo();
fail("Should have thrown Exception because there is no sslPort.");
} catch (IllegalStateException e) {
// The datacenter of the data node is in the ssl enabled datacenter list, but the data node does not have an ssl
// port to connect. Exception should be thrown.
}
}
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 TestUtils method getDummyConfig.
/**
* For use when the the actual values in {@link ClusterMapConfig} are unimportant.
* @return a {@link ClusterMapConfig} with some default values.
*/
static ClusterMapConfig getDummyConfig() {
Properties props = new Properties();
props.setProperty("clustermap.host.name", "localhost");
props.setProperty("clustermap.cluster.name", "cluster");
props.setProperty("clustermap.datacenter.name", "");
props.setProperty("clustermap.resolve.hostnames", "false");
return new ClusterMapConfig(new VerifiableProperties(props));
}
Aggregations