Search in sources :

Example 1 with ZoneAffinity

use of voldemort.client.ZoneAffinity in project voldemort by voldemort.

the class ZoneShrinkageClientTest method testZoneAffinityClient.

@Test
public void testZoneAffinityClient() {
    ZoneAffinity zoneAffinity = new ZoneAffinity(true, true, true);
    ClientConfig clientConfig = new ClientConfig().setBootstrapUrls(sourceCluster.getNodeById(0).getSocketUrl().toString()).setClientZoneId(DROP_ZONE_ID).setZoneAffinity(zoneAffinity);
    SocketStoreClientFactory factory = new SocketStoreClientFactory(clientConfig);
    StoreClient<String, String> client = factory.getStoreClient(sourceStoreDefs.get(sourceStoreDefs.size() - 1).getName());
    // do some operations against the stores from zone 0.
    for (int i = 0; i < 10; i++) {
        try {
            client.put("key" + i, "val" + i);
            assertEquals("Must read value back", "val" + i, client.get("key" + i).getValue());
        } catch (Exception e) {
            fail("Should be not see any failures");
        }
    }
    // shrink the cluster, by dropping zone 0
    String clusterXmlString = new ClusterMapper().writeCluster(targetCluster);
    String storesXmlString = new StoreDefinitionsMapper().writeStoreList(targetStoreDefs);
    int[] remoteNodeList = new int[sourceCluster.getNumberOfNodes()];
    int ni = 0;
    for (Integer nodeId : sourceCluster.getNodeIds()) {
        remoteNodeList[ni++] = nodeId;
    }
    adminClient.metadataMgmtOps.updateRemoteMetadataPair(new ArrayList<Integer>(sourceCluster.getNodeIds()), "cluster.xml", new Versioned<String>(clusterXmlString, TestUtils.getClock(remoteNodeList)), "stores.xml", new Versioned<String>(storesXmlString, TestUtils.getClock(remoteNodeList)));
    try {
        Thread.sleep(clientConfig.getAsyncMetadataRefreshInMs() * 2);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // do more operations, the client should fail.
    for (int i = 0; i < 10; i++) {
        long startMs = System.currentTimeMillis();
        try {
            client.put("key" + i, "val" + i);
            assertEquals("Must read value back", "val" + i, client.get("key" + i).getValue());
            fail("Should be not see any successes");
        } catch (Exception e) {
            e.printStackTrace();
            long elapsedMs = System.currentTimeMillis() - startMs;
            assertTrue("Operation took longer than timeout to fail :" + elapsedMs + " ms.", elapsedMs < clientConfig.getRoutingTimeout(TimeUnit.MILLISECONDS));
        }
    }
}
Also used : StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ZoneAffinity(voldemort.client.ZoneAffinity) ClusterMapper(voldemort.xml.ClusterMapper) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) AdminClientConfig(voldemort.client.protocol.admin.AdminClientConfig) ClientConfig(voldemort.client.ClientConfig) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 Test (org.junit.Test)1 ClientConfig (voldemort.client.ClientConfig)1 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)1 ZoneAffinity (voldemort.client.ZoneAffinity)1 AdminClientConfig (voldemort.client.protocol.admin.AdminClientConfig)1 ClusterMapper (voldemort.xml.ClusterMapper)1 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)1