Package voldemort.utils

Examples of voldemort.utils.ByteArray


        defaultStoreClient.put(KEY, conflict2);
        defaultStoreClient.put(KEY, conflict3);
        defaultStoreClient.put(KEY, conflict4);
        defaultStoreClient.put(KEY, conflict5);
        defaultStoreClient.put(KEY, conflict6);
        List<Versioned<byte[]>> resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
        assertEquals(6, resList.size());
        Versioned<String> res = defaultStoreClient.get(KEY);
        defaultStoreClient.put(KEY, res);
        resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
        assertEquals(1, resList.size());
    }
View Full Code Here


                                                                routingStrategy,
                                                                1,
                                                                dir,
                                                                2);
        // should not have exceptions
        engine.get(new ByteArray("ab".getBytes()), null);
    }
View Full Code Here

        HashMap<ByteArray, byte[]> entrySet = null;
        Iterator<ByteArray> keys = null;
        RoutingStrategy strategy = servers[0].getMetadataStore().getRoutingStrategy(testStoreName);
        while(true) {
            ByteArray key;
            byte[] value;
            if(keys == null || !keys.hasNext()) {
                entrySet = ServerTestUtils.createRandomKeyValuePairs(100);
                keys = entrySet.keySet().iterator();
            }
            key = keys.next();
            value = entrySet.get(key);
            List<Node> routedNodes = strategy.routeRequest(key.get());
            boolean keyShouldBeInNode0 = false;
            boolean keyShouldBeInNode1 = false;
            for(Node node: routedNodes) {
                keyShouldBeInNode0 = keyShouldBeInNode0 || (node.getId() == 0);
                keyShouldBeInNode1 = keyShouldBeInNode1 || (node.getId() == 1);
View Full Code Here

        // Insert some data for the keys
        Store<ByteArray, byte[], byte[]> nodeStore = getStore(0, storeName);

        for(int i = 0; i < keys.size(); i++) {
            ByteArray key = keys.get(i);
            byte[] val = entries.get(key);
            long ts = 0;
            if(i == 0) {
                // have multiple conflicting versions.. one lower ts and one
                // higher ts, than the streaming version
                Versioned<byte[]> v1 = new Versioned<byte[]>(val,
                                                             TestUtils.getClockWithTs(baseTimeMs - 1,
                                                                                      1));
                nodeStore.put(key, v1, null);
                Versioned<byte[]> v2 = new Versioned<byte[]>(val,
                                                             TestUtils.getClockWithTs(baseTimeMs + 1,
                                                                                      2));
                nodeStore.put(key, v2, null);
            } else {
                if(i % 2 == 0) {
                    // even keys : streaming write wins
                    ts = baseTimeMs + i;
                } else {
                    // odd keys : storage version wins
                    ts = baseTimeMs - i;
                }
                nodeStore.put(key, new Versioned<byte[]>(val, new VectorClock(ts)), null);
            }
        }

        Iterator<Pair<ByteArray, Versioned<byte[]>>> iterator = new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {

            final Iterator<ByteArray> keysItr = keys.iterator();
            int keyCount = 0;

            @Override
            protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
                while(keysItr.hasNext()) {
                    ByteArray key = keysItr.next();
                    byte[] val = entries.get(key);
                    long ts = 0;
                    if(keyCount == 0) {
                        // streaming put will be in the middle of two version on
                        // storage
                        keyCount++;
                        return new Pair<ByteArray, Versioned<byte[]>>(key,
                                                                      new Versioned<byte[]>(val,
                                                                                            new VectorClock(baseTimeMs)));
                    } else {
                        if(keyCount % 2 == 0) {
                            // even keys : streaming write wins
                            ts = baseTimeMs - keyCount;
                        } else {
                            // odd keys : storage version wins
                            ts = baseTimeMs + keyCount;
                        }
                        keyCount++;
                        return new Pair<ByteArray, Versioned<byte[]>>(key,
                                                                      new Versioned<byte[]>(val,
                                                                                            new VectorClock(ts)));
                    }
                }
                return endOfData();
            }
        };

        getAdminClient().streamingOps.updateEntriesTimeBased(0, storeName, iterator, null);

        // check updated values
        for(int i = 0; i < keys.size(); i++) {
            ByteArray key = keys.get(i);
            List<Versioned<byte[]>> vals = nodeStore.get(key, null);

            if(i == 0) {
                assertEquals("Must contain exactly two versions", 2, vals.size());
                Set<Long> storageTimeSet = new HashSet<Long>();
View Full Code Here

        adminClient.restoreOps.restoreDataFromReplications(1, 2);

        // assert server 1 has all entries for its partitions
        store = getStore(1, testStoreName);
        for(Entry<ByteArray, byte[]> entry: entrySet.entrySet()) {
            ByteArray key = entry.getKey();
            assertSame("entry should be present for key " + key, 1, store.get(entry.getKey(), null)
                                                                         .size());
            assertEquals("entry value should match",
                         new String(entry.getValue()),
                         new String(store.get(entry.getKey(), null).get(0).getValue()));
View Full Code Here

        // 1. Make sure the vector clocks make sense.. Read through Node 2 and
        // proxy getting from Node 0 and issue a write based off that,
        // incrementing the clock for Node 2 and make sure there is no
        // ObsoleteVersionException at both Node 0 and
        // Node 2.
        ByteArray secondaryKey = testSecondaryKeys.get(0);
        VectorClock clock1 = ((VectorClock)
                redirectingStoreNode2.getVersions(secondaryKey).get(0)).incremented(2,
                                                                                    System.currentTimeMillis());
        try {
            redirectingStoreNode2.put(secondaryKey,
                                      Versioned.value("write-through".getBytes("UTF-8"), clock1),
                                      null);
        } catch(Exception e) {
            fail("Unexpected error in testing write through proxy put");
            e.printStackTrace();
        }
        waitForProxyPutsToDrain(redirectingStoreNode2);

        assertTrue("Unexpected failures in proxy put",
                   redirectingStoreNode2.getProxyPutStats().getNumProxyPutFailures() == 0);
        assertEquals("Unexpected value in Node 2",
                     "write-through",
                     new String(socketStoreNode2.get(secondaryKey, null).get(0).getValue()));
        assertTrue("Proxy write not seen on proxy node 0",
                   "write-through".equals(new String(socketStoreNode0.get(secondaryKey, null)
                                                                     .get(0)
                                                                     .getValue())));

        // Also test that if put fails locally, proxy put is not attempted.
        try {
            redirectingStoreNode2.put(secondaryKey,
                                      Versioned.value("write-through-updated".getBytes("UTF-8"),
                                                      clock1),
                                      null);
            fail("Should have thrown OVE");
        } catch(ObsoleteVersionException ove) {
            // Expected
        } catch(Exception e) {
            fail("Unexpected error in testing write through proxy put");
            e.printStackTrace();
        }
        waitForProxyPutsToDrain(redirectingStoreNode2);
        assertFalse("Proxy write not seen on proxy node 0",
                    "write-through-updated".equals(new String(socketStoreNode0.get(secondaryKey,
                                                                                   null)
                                                                              .get(0)
                                                                              .getValue())));

        // 2. Make sure if the proxy node is still a replica, we don't issue
        // proxy puts. Node 2 -> Node 0 on partition 0, for which Node 0 is
        // still a replica
        ByteArray primaryKey = testPrimaryKeys.get(0);
        VectorClock clock2 = ((VectorClock)
                redirectingStoreNode2.getVersions(primaryKey).get(0)).incremented(2,
                                                                                  System.currentTimeMillis());
        try {
            redirectingStoreNode2.put(primaryKey,
View Full Code Here

                redirectingStoreNode0.getRedirectingSocketStore("test",
                                                                0);

        long time = System.currentTimeMillis();
        // 1. Test that once a key is fetched over, get() can serve it locally..
        ByteArray primaryKey1 = testPrimaryKeys.get(1);
        assertTrue("Originally key should not exist on Node 2",
                   socketStoreNode2.get(primaryKey1, null).size() == 0);

        assertTrue("get on Node 2 should return a valid value by proxy fetching from Node 0",
                   redirectingStoreNode2.get(primaryKey1, null).size() > 0);

        socketStoreNode0.delete(primaryKey1, makeSuperClock(time++));
        assertTrue("Still should be able to serve it locally from Node 2",
                   redirectingStoreNode2.get(primaryKey1, null).size() > 0);

        // 2. Test that put is still issued on top of version on remote version.
        // But once moved over, can be issued just on local version.
        ByteArray secondaryKey1 = testSecondaryKeys.get(1);
        VectorClock writeClock = makeSuperClock(time++);
        socketStoreNode0.put(secondaryKey1, new
                             Versioned<byte[]>("value-win".getBytes(),
                                               writeClock), null);
        try {
            redirectingStoreNode2.put(secondaryKey1, new
                                      Versioned<byte[]>("value-ove".getBytes(),
                                                        writeClock), null);
            fail("Missing OVE.. put should be based on remote version");
        } catch(ObsoleteVersionException ove) {
            // should have OVE if based on remote version due to equal clock
        }
        // But would have still move over value from Node 0
        assertEquals("Value not moved over from Node 0",
                     "value-win",
                     new String(socketStoreNode2.get(secondaryKey1, null).get(0).getValue()));
        socketStoreNode0.delete(secondaryKey1, makeSuperClock(time++));
        redirectingStoreNode2.put(secondaryKey1,
                                  new Versioned<byte[]>("value-final".getBytes(),
                                                        makeSuperClock(time++)),
                                  null);
        assertEquals("Final value not found on node 2",
                     "value-final",
                     new String(socketStoreNode2.get(secondaryKey1, null).get(0).getValue()));
        assertEquals("Final value not found on node 0",
                     "value-final",
                     new String(socketStoreNode0.get(secondaryKey1, null).get(0).getValue()));

        // delete all the primary and secondary keys from Node 2 and Node 0, to
        // begin getAll() tests
        for(ByteArray key: testPrimaryKeys) {
            socketStoreNode0.delete(key, makeSuperClock(time++));
            socketStoreNode2.delete(key, makeSuperClock(time++));
            socketStoreNode0.put(key, new Versioned<byte[]>("normal".getBytes(),
                                                            makeSuperClock(time++)), null);
        }
        for(ByteArray key: testSecondaryKeys) {
            socketStoreNode0.delete(key, makeSuperClock(time++));
            socketStoreNode2.delete(key, makeSuperClock(time++));
            socketStoreNode0.put(key, new Versioned<byte[]>("normal".getBytes(),
                                                            makeSuperClock(time++)), null);
        }

        // 3. Test case where some keys are moved over and some are n't for
        // getAlls.
        List<ByteArray> keyList = new ArrayList<ByteArray>();
        keyList.addAll(testPrimaryKeys);
        keyList.addAll(testSecondaryKeys);
        keyList.add(new ByteArray("non-existent-key".getBytes()));

        // add the first primary & secondary key with bigger vector clock on
        // Node 2 and lower clock on Node 0..
        VectorClock smallerClock = makeSuperClock(time++);
        VectorClock biggerClock = makeSuperClock(time++);
        socketStoreNode0.put(testPrimaryKeys.get(0), new
                             Versioned<byte[]>("loser".getBytes(),
                                               smallerClock), null);
        socketStoreNode2.put(testPrimaryKeys.get(0), new
                             Versioned<byte[]>("winner".getBytes(),
                                               biggerClock), null);
        socketStoreNode0.put(testSecondaryKeys.get(0), new
                             Versioned<byte[]>("loser".getBytes(),
                                               smallerClock), null);
        socketStoreNode2.put(testSecondaryKeys.get(0), new
                             Versioned<byte[]>("winner".getBytes(),
                                               biggerClock), null);

        Map<ByteArray, List<Versioned<byte[]>>> vals =
                redirectingStoreNode2.getAll(keyList, null);
        assertEquals("Should contain exactly as many keys as the primary + secondary keys",
                     testPrimaryKeys.size() + testSecondaryKeys.size(),
                     vals.size());
        assertFalse("Should not contain non existent key",
                    vals.containsKey(new ByteArray("non-existent-key".getBytes())));

        for(Entry<ByteArray, List<Versioned<byte[]>>> entry: vals.entrySet()) {
            String valueStr = new String(entry.getValue().get(0).getValue());
            if(entry.getKey().equals(testPrimaryKeys.get(0))
               || entry.getKey().equals(testSecondaryKeys.get(0))) {
                assertEquals("Value should be 'winner'", "winner", valueStr);
            } else {
                assertEquals("Value should be 'normal'", "normal", valueStr);
            }
        }

        // Now delete all keys on Node 0 and make sure it is still served out of
        // Node 2
        for(ByteArray key: testPrimaryKeys) {
            socketStoreNode0.delete(key, makeSuperClock(time++));
        }
        for(ByteArray key: testSecondaryKeys) {
            socketStoreNode0.delete(key, makeSuperClock(time++));
        }

        vals = redirectingStoreNode2.getAll(keyList, null);
        assertEquals("Should contain exactly as many keys as the primary + secondary keys",
                     testPrimaryKeys.size() + testSecondaryKeys.size(),
                     vals.size());
        assertFalse("Should not contain non existent key",
                    vals.containsKey(new ByteArray("non-existent-key".getBytes())));

        for(Entry<ByteArray, List<Versioned<byte[]>>> entry: vals.entrySet()) {
            String valueStr = new String(entry.getValue().get(0).getValue());
            if(entry.getKey().equals(testPrimaryKeys.get(0))
               || entry.getKey().equals(testSecondaryKeys.get(0))) {
View Full Code Here

        PerformanceTest socketWriteTest = new PerformanceTest() {

            @Override
            public void doOperation(int i) {
                byte[] bytes = String.valueOf(i).getBytes();
                ByteArray key = new ByteArray(bytes);
                socketStore.put(key, new Versioned<byte[]>(bytes), null);
            }
        };
        System.out.println("###########################################");
        System.out.println("Performing socket write test.");
        socketWriteTest.run(numRequests, numThreads);
        socketWriteTest.printStats();
        System.out.println();

        PerformanceTest socketReadTest = new PerformanceTest() {

            @Override
            public void doOperation(int i) {
                try {
                    socketStore.get(TestUtils.toByteArray(String.valueOf(i)), null);
                } catch(Exception e) {
                    System.out.println("Failure on i = " + i);
                    e.printStackTrace();
                }
            }
        };
        System.out.println("Performing socket read test.");
        socketReadTest.run(numRequests, 1);
        socketReadTest.printStats();
        System.out.println();
        System.out.println();

        socketStore.close();
        storeFactory.close();
        socketService.stop();

        /** * Do HTTP tests ** */
        repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
        HttpService httpService = new HttpService(null,
                                                  null,
                                                  repository,
                                                  RequestFormatType.VOLDEMORT_V0,
                                                  numThreads,
                                                  8080);
        httpService.start();

        ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
                                                                                        10000,
                                                                                        TimeUnit.MILLISECONDS);

        DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);

        HttpParams clientParams = httpClient.getParams();
        httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
        HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
        HttpProtocolParams.setUserAgent(clientParams, "test-agent");
        HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);

        HttpConnectionParams.setConnectionTimeout(clientParams, 10000);

        connectionManager.setMaxTotal(numThreads);
        connectionManager.setDefaultMaxPerRoute(numThreads);
        HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);

        final HttpStore httpStore = new HttpStore("test",
                                                  "localhost",
                                                  8080,
                                                  httpClient,
                                                  new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V0),
                                                  false);
        Thread.sleep(400);

        PerformanceTest httpWriteTest = new PerformanceTest() {

            @Override
            public void doOperation(int i) {
                byte[] key = String.valueOf(i).getBytes();
                httpStore.put(new ByteArray(key), new Versioned<byte[]>(key), null);
            }
        };
        System.out.println("###########################################");
        System.out.println("Performing HTTP write test.");
        httpWriteTest.run(numRequests, numThreads);
        httpWriteTest.printStats();
        System.out.println();

        PerformanceTest httpReadTest = new PerformanceTest() {

            @Override
            public void doOperation(int i) {
                httpStore.get(new ByteArray(String.valueOf(i).getBytes()), null);
            }
        };
        System.out.println("Performing HTTP read test.");
        httpReadTest.run(numRequests, numThreads);
        httpReadTest.printStats();
View Full Code Here

            version1.incrementVersion(0, System.currentTimeMillis());
            VectorClock version2 = version1.incremented(0, System.currentTimeMillis());

            if(node.getZoneId() == clientZoneId) {
                // local zone
                store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
                store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
            } else {
                // remote zone
                store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v2_bytes, version2), null);
                store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
                store.put(new ByteArray(k3_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
            }
        }

        client = socketStoreClientFactory.getRawStore(storeDef.getName(), null);
    }
View Full Code Here

        }
        return version;
    }

    public static NodeValue<ByteArray, byte[]> createNodeValue(int nodeId, Version version) {
        ByteArray key = new ByteArray(new byte[]{54, 52, 49, 57, 52, 54, 51, 51});
        byte[] value = new byte[]{69,119,105,119,83,71,80,113,108,108,119,86,67,120,103,111};
        Versioned<byte[]> versioned = new Versioned<byte[]>(value, version);
        return new NodeValue<ByteArray, byte[]>(nodeId, key, versioned);
    }
View Full Code Here

TOP

Related Classes of voldemort.utils.ByteArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.