Search in sources :

Example 76 with ClusterMapConfig

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

the class DataNodeTest method basics.

@Test
public void basics() throws JSONException {
    JSONObject jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 7666, 8666, HardwareState.AVAILABLE, getDisks());
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    DataNode dataNode = new TestDataNode("datacenter", jsonObject, clusterMapConfig);
    assertEquals(dataNode.getHostname(), TestUtils.getLocalHost());
    assertEquals(dataNode.getPort(), 6666);
    assertEquals(dataNode.getState(), HardwareState.AVAILABLE);
    assertEquals(dataNode.getDisks().size(), diskCount);
    assertEquals(dataNode.getRawCapacityInBytes(), diskCount * diskCapacityInBytes);
    assertNull(dataNode.getRackId());
    assertEquals(TestUtils.DEFAULT_XID, dataNode.getXid());
    assertEquals(dataNode.toJSONObject().toString(), jsonObject.toString());
    assertEquals(dataNode, new TestDataNode("datacenter", dataNode.toJSONObject(), clusterMapConfig));
    // Test with defined rackId
    jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 7666, 8666, 42, TestUtils.DEFAULT_XID, getDisks(), HardwareState.AVAILABLE);
    dataNode = new TestDataNode("datacenter", jsonObject, clusterMapConfig);
    assertEquals("42", dataNode.getRackId());
    assertEquals(TestUtils.DEFAULT_XID, dataNode.getXid());
    assertEquals(dataNode.toJSONObject().toString(), jsonObject.toString());
    assertEquals(dataNode, new TestDataNode("datacenter", dataNode.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 77 with ClusterMapConfig

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

the class DataNodeTest method validation.

@Test
public void validation() throws JSONException {
    JSONObject jsonObject;
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
        // Null DataNode
        jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 7666, 8666, HardwareState.AVAILABLE, getDisks());
        new DataNode(null, jsonObject, clusterMapConfig);
        fail("Should have failed validation.");
    } catch (IllegalStateException e) {
    // Expected.
    }
    // Bad hostname
    jsonObject = TestUtils.getJsonDataNode("", 6666, 7666, 8666, HardwareState.AVAILABLE, getDisks());
    failValidation(jsonObject, clusterMapConfig);
    // Bad hostname (http://tools.ietf.org/html/rfc6761 defines 'invalid' top level domain)
    jsonObject = TestUtils.getJsonDataNode("hostname.invalid", 6666, 7666, 8666, HardwareState.AVAILABLE, getDisks());
    failValidation(jsonObject, clusterMapConfig);
    // Port should between 1025 and 65535
    int[][] portsToTest = { { -1, 7666, 8666 }, { 100 * 1000, 7666, 8666 }, { 6666, -1, 8666 }, { 6666, 100 * 1000, 8666 }, { 6666, 7777, -1 }, { 6666, 7777, 100 * 1000 } };
    for (int[] ports : portsToTest) {
        jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), ports[0], ports[1], ports[2], HardwareState.AVAILABLE, getDisks());
        failValidation(jsonObject, clusterMapConfig);
    }
    // same port number for plain text and ssl port
    jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 6666, 8666, HardwareState.AVAILABLE, getDisks());
    failValidation(jsonObject, clusterMapConfig);
    // same port number for plain text and HTTP2 port
    jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 7666, 6666, HardwareState.AVAILABLE, getDisks());
    failValidation(jsonObject, clusterMapConfig);
    // same port number for http2 port and ssl port
    jsonObject = TestUtils.getJsonDataNode(TestUtils.getLocalHost(), 6666, 8666, 8666, HardwareState.AVAILABLE, getDisks());
    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 78 with ClusterMapConfig

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

the class DiskTest method testDiskSoftState.

@Test
public void testDiskSoftState() throws JSONException, InterruptedException {
    JSONObject jsonObject = TestUtils.getJsonDisk("/mnt1", HardwareState.AVAILABLE, 100 * 1024 * 1024 * 1024L);
    Properties props = new Properties();
    props.setProperty("clustermap.fixedtimeout.disk.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.clusterMapFixedTimeoutDiskErrorThreshold;
    long retryBackoffMs = clusterMapConfig.clusterMapFixedTimeoutDiskRetryBackoffMs;
    Disk testDisk = new TestDisk(jsonObject, clusterMapConfig);
    for (int i = 0; i < threshold; i++) {
        assertEquals(testDisk.getState(), HardwareState.AVAILABLE);
        testDisk.onDiskError();
    }
    assertEquals(testDisk.getState(), HardwareState.UNAVAILABLE);
    Thread.sleep(retryBackoffMs + 1);
    assertEquals(testDisk.getState(), HardwareState.AVAILABLE);
    // A single error should make it unavailable
    testDisk.onDiskError();
    assertEquals(testDisk.getState(), HardwareState.UNAVAILABLE);
    testDisk.onDiskOk();
    assertEquals(testDisk.getState(), HardwareState.AVAILABLE);
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 79 with ClusterMapConfig

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

the class DiskTest method validation.

@Test
public void validation() throws JSONException {
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
        // Null DataNode
        new Disk(null, TestUtils.getJsonDisk("/mnt1", HardwareState.AVAILABLE, 100 * 1024 * 1024 * 1024L), clusterMapConfig);
        fail("Construction of Disk should have failed validation.");
    } catch (IllegalStateException e) {
    // Expected.
    }
    // Bad mount path (empty)
    failValidation(TestUtils.getJsonDisk("", HardwareState.AVAILABLE, 100 * 1024 * 1024 * 1024L), clusterMapConfig);
    // Bad mount path (relative path)
    failValidation(TestUtils.getJsonDisk("mnt1", HardwareState.AVAILABLE, 100 * 1024 * 1024 * 1024L), clusterMapConfig);
    // Bad capacity (too small)
    failValidation(TestUtils.getJsonDisk("/mnt1", HardwareState.UNAVAILABLE, 0), clusterMapConfig);
    // Bad capacity (too big)
    failValidation(TestUtils.getJsonDisk("/mnt1", HardwareState.UNAVAILABLE, 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024L), clusterMapConfig);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 80 with ClusterMapConfig

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

the class DatacenterTest method basics.

@Test
public void basics() throws JSONException {
    JSONObject jsonObject = TestUtils.getJsonDatacenter("XYZ1", (byte) 1, getDataNodes());
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    Datacenter datacenter = new TestDatacenter(jsonObject, clusterMapConfig);
    assertEquals(datacenter.getName(), "XYZ1");
    assertEquals(datacenter.getId(), 1);
    assertEquals(datacenter.getDataNodes().size(), dataNodeCount);
    assertEquals(datacenter.getRawCapacityInBytes(), dataNodeCount * diskCount * diskCapacityInBytes);
    assertFalse(datacenter.isRackAware());
    assertEquals(datacenter.toJSONObject().toString(), jsonObject.toString());
    assertEquals(datacenter, new TestDatacenter(datacenter.toJSONObject(), clusterMapConfig));
    jsonObject = TestUtils.getJsonDatacenter("XYZ1", (byte) 1, getDataNodesRackAware());
    datacenter = new TestDatacenter(jsonObject, clusterMapConfig);
    assertTrue(datacenter.isRackAware());
    assertEquals(datacenter.toJSONObject().toString(), jsonObject.toString());
    assertEquals(datacenter, new TestDatacenter(datacenter.toJSONObject(), clusterMapConfig));
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Aggregations

ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)100 VerifiableProperties (com.github.ambry.config.VerifiableProperties)81 Test (org.junit.Test)56 Properties (java.util.Properties)52 MetricRegistry (com.codahale.metrics.MetricRegistry)47 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)26 HashSet (java.util.HashSet)25 JSONObject (org.json.JSONObject)25 File (java.io.File)24 ClusterMap (com.github.ambry.clustermap.ClusterMap)23 HashMap (java.util.HashMap)21 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)19 ClusterAgentsFactory (com.github.ambry.clustermap.ClusterAgentsFactory)18 DataNodeId (com.github.ambry.clustermap.DataNodeId)18 StoreConfig (com.github.ambry.config.StoreConfig)18 ReplicaId (com.github.ambry.clustermap.ReplicaId)16 List (java.util.List)16 Map (java.util.Map)16 CountDownLatch (java.util.concurrent.CountDownLatch)16