Search in sources :

Example 6 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class VerifyOrAddStoreTest method verifyCreateWithNodeFailure.

@Test
public void verifyCreateWithNodeFailure() throws Exception {
    ServerTestUtils.stopVoldemortServer(servers[FAILED_NODE_ID]);
    // Set CreateStore to false, node down should have thrown an error
    try {
        adminClient.storeMgmtOps.verifyOrAddStore(newStoreDef, PROCESS_NAME, false, service);
        Assert.fail("Node failure should have raised an error");
    } catch (VoldemortException ex) {
    // Pass
    }
    // Verify that.
    for (Integer nodeId : cluster.getNodeIds()) {
        if (nodeId == FAILED_NODE_ID) {
        // this is a dead server, continue;
        } else {
            StoreDefinition retrieved = retrieveStoreOnNode(newStoreName, nodeId);
            assertNull("store should not exist", retrieved);
        }
    }
    // nodes that are up and thrown an exception at the end.
    try {
        adminClient.storeMgmtOps.verifyOrAddStore(newStoreDef, PROCESS_NAME, service);
        Assert.fail("Node failure should have raised an error");
    } catch (VoldemortException ex) {
    // Pass
    }
    // Verify that.
    for (Integer nodeId : cluster.getNodeIds()) {
        if (nodeId == FAILED_NODE_ID) {
        // this is a dead server, continue;
        } else {
            StoreDefinition retrieved = retrieveStoreOnNode(newStoreName, nodeId);
            assertEquals("store successfully created on online nodes", newStoreDef, retrieved);
        }
    }
    // Verify set quota on the stores as well.
    for (QuotaType quotaType : new QuotaType[] { QuotaType.STORAGE_SPACE, QuotaType.GET_THROUGHPUT }) {
        long newQuota = 100000 + new Random().nextInt(10000);
        try {
            adminClient.quotaMgmtOps.setQuota(newStoreName, quotaType, newQuota, service);
            Assert.fail("Node failure should have raised an error");
        } catch (VoldemortException ex) {
        // expected.
        }
        for (Integer nodeId : cluster.getNodeIds()) {
            if (nodeId == FAILED_NODE_ID) {
            // this is dead server, continue.
            } else {
                Long retrievedQuota = getQuotaForNode(newStoreName, quotaType, nodeId);
                assertEquals("Set and retrieved different quota", newQuota, retrievedQuota.longValue());
            }
        }
    }
}
Also used : Random(java.util.Random) StoreDefinition(voldemort.store.StoreDefinition) QuotaType(voldemort.store.quota.QuotaType) VoldemortException(voldemort.VoldemortException) Test(org.junit.Test)

Example 7 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class VerifyOrAddStoreTest method verifyAdminClientAcrossNodeRestart.

@Test
public void verifyAdminClientAcrossNodeRestart() throws Exception {
    long newQuota = 500000 + new Random().nextInt(10000);
    // Do a query create the connections.
    adminClient.storeMgmtOps.verifyOrAddStore(newStoreDef, PROCESS_NAME, service);
    // Create client pool as well.
    for (QuotaType quotaType : new QuotaType[] { QuotaType.STORAGE_SPACE, QuotaType.GET_THROUGHPUT }) {
        adminClient.quotaMgmtOps.setQuota(newStoreName, quotaType, newQuota, service);
    }
    ServerTestUtils.stopVoldemortServer(servers[FAILED_NODE_ID]);
    try {
        retrieveStoreOnNode(newStoreName, FAILED_NODE_ID);
        Assert.fail("Downed node retrieval should have thrown an error");
    } catch (VoldemortException ex) {
    // Expected
    }
    try {
        adminClient.storeMgmtOps.verifyOrAddStore(newStoreDef, PROCESS_NAME, service);
        Assert.fail("Downed node should have thrown an error");
    } catch (VoldemortException ex) {
    // Expected
    }
    // setQuota should throw as well.
    for (QuotaType quotaType : new QuotaType[] { QuotaType.STORAGE_SPACE, QuotaType.GET_THROUGHPUT }) {
        try {
            adminClient.quotaMgmtOps.setQuota(newStoreName, quotaType, newQuota, service);
            Assert.fail("Node failure should have raised an error");
        } catch (VoldemortException ex) {
        // expected.
        }
    }
    servers[FAILED_NODE_ID] = ServerTestUtils.restartServer(servers[FAILED_NODE_ID], FAILED_NODE_ID, cluster, serverProps);
    StoreDefinition retrieved = retrieveStoreOnNode(newStoreName, FAILED_NODE_ID);
    assertEquals("After restart, should retrieve the store", newStoreDef, retrieved);
    adminClient.storeMgmtOps.verifyOrAddStore(newStoreDef, PROCESS_NAME, service);
    long updatedQuota = newQuota + 100;
    for (QuotaType quotaType : new QuotaType[] { QuotaType.STORAGE_SPACE, QuotaType.GET_THROUGHPUT }) {
        adminClient.quotaMgmtOps.setQuota(newStoreName, quotaType, updatedQuota, service);
        for (Integer nodeId : cluster.getNodeIds()) {
            Long retrievedQuota = getQuotaForNode(newStoreName, quotaType, nodeId);
            assertEquals("Set and retrieved different quota", updatedQuota, retrievedQuota.longValue());
        }
    }
}
Also used : Random(java.util.Random) QuotaType(voldemort.store.quota.QuotaType) StoreDefinition(voldemort.store.StoreDefinition) VoldemortException(voldemort.VoldemortException) Test(org.junit.Test)

Example 8 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class QuotaTest method testBasicOperation.

@Test
public void testBasicOperation() {
    String storeName = stores.get(0).getName();
    for (QuotaType quotaType : QuotaType.values()) {
        verifyNoQuota(storeName, quotaType);
        // Create
        int newQuota = new Random().nextInt(Integer.MAX_VALUE);
        adminClient.quotaMgmtOps.setQuota(storeName, quotaType, newQuota);
        verifyValidQuota(storeName, quotaType, newQuota);
        // Update
        newQuota = new Random().nextInt(Integer.MAX_VALUE);
        adminClient.quotaMgmtOps.setQuota(storeName, quotaType, newQuota);
        verifyValidQuota(storeName, quotaType, newQuota);
        // Delete
        adminClient.quotaMgmtOps.unsetQuota(storeName, quotaType);
        verifyNoQuota(storeName, quotaType);
    }
}
Also used : Random(java.util.Random) QuotaType(voldemort.store.quota.QuotaType) Test(org.junit.Test)

Example 9 with QuotaType

use of voldemort.store.quota.QuotaType in project voldemort by voldemort.

the class QuotaTest method testGetAllQuota.

@Test
public void testGetAllQuota() {
    for (QuotaType quotaType : QuotaType.values()) {
        List<String> existingStoreNames = new ArrayList<String>();
        Map<String, Integer> storeQuotas = new HashMap<String, Integer>();
        for (StoreDefinition store : stores) {
            String storeName = store.getName();
            existingStoreNames.add(storeName);
            int quota = new Random().nextInt();
            storeQuotas.put(storeName, quota);
            adminClient.quotaMgmtOps.setQuota(storeName, quotaType, quota);
        }
        // All stores in some order
        Collections.shuffle(existingStoreNames);
        verifyGetAll(existingStoreNames, storeQuotas, quotaType);
        // Pick subset of stores.
        final int REQUIRED_ELEMENTS = 3;
        int numElements = REQUIRED_ELEMENTS + new Random().nextInt(existingStoreNames.size() - REQUIRED_ELEMENTS);
        List<String> fewStores = existingStoreNames.subList(0, numElements);
        verifyGetAll(fewStores, storeQuotas, quotaType);
        // Pick few existing stores and few non-existent stores
        List<String> mixedStores = new ArrayList<String>();
        mixedStores.addAll(fewStores);
        for (int i = 0; i < 10; i++) {
            mixedStores.add("NON_EXISTENT_STORE" + i);
        }
        verifyGetAll(mixedStores, storeQuotas, quotaType);
    }
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) QuotaType(voldemort.store.quota.QuotaType) StoreDefinition(voldemort.store.StoreDefinition) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

QuotaType (voldemort.store.quota.QuotaType)9 Test (org.junit.Test)7 Random (java.util.Random)5 VoldemortException (voldemort.VoldemortException)4 StoreDefinition (voldemort.store.StoreDefinition)3 HashMap (java.util.HashMap)2 AdminClient (voldemort.client.protocol.admin.AdminClient)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 AdminClientConfig (voldemort.client.protocol.admin.AdminClientConfig)1 NodeValue (voldemort.store.routed.NodeValue)1 ByteArray (voldemort.utils.ByteArray)1 Pair (voldemort.utils.Pair)1 VectorClock (voldemort.versioning.VectorClock)1