Package voldemort.utils

Examples of voldemort.utils.ByteArray


    private Set<String> getEntries(ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> itr) {
        HashSet<String> keySet = new HashSet<String>();
        while(itr.hasNext()) {
            Pair<ByteArray, Versioned<byte[]>> entry = itr.next();
            ByteArray key = entry.getFirst();
            byte[] value = entry.getSecond().getValue();

            String skey = new String(key.get());
            int keyId = Integer.parseInt(skey.replaceAll("key", ""));
            assertEquals(0, ByteUtils.compare(value, ("value" + keyId).getBytes()));

            keySet.add(skey);
        }
View Full Code Here


                int partition = strategy.getPartitionList(bkey).get(0);
                if(!partitionToKeysMap.containsKey(partition))
                    partitionToKeysMap.put(partition, new HashSet<String>());
                partitionToKeysMap.get(partition).add(key);

                prefixedBdbStore.put(new ByteArray(bkey),
                                     new Versioned<byte[]>(("value" + i).getBytes()),
                                     null);
            }

            // check if they are properly retrieved by that partition id
View Full Code Here

        // generate the keys
        for(int i = 0; i < 5; i++) {
            Set<Integer> nodesCovered = Sets.newHashSet();
            while(nodesCovered.size() < NUM_NODES_TOTAL) {
                ByteArray randomKey = new ByteArray(TestUtils.randomBytes(KEY_LENGTH));
                byte[] randomValue = TestUtils.randomBytes(VALUE_LENGTH);

                if(randomKey.length() > 0 && randomValue.length > 0) {
                    if(!keyList.contains(randomKey)) {
                        for(Node node: strategy.routeRequest(randomKey.get())) {
                            keysToNodes.put(randomKey, node.getId());
                            nodesCovered.add(node.getId());
                        }
                        logger.info("Inserting key [" + randomKey + "] to key list as id:"
                                    + keyList.size());
                        keyList.add(randomKey);
                        keyValues.put(randomKey, new ByteArray(randomValue));
                    }
                }
            }
        }
    }
View Full Code Here

        }

        int errorCount = 0;
        for(Map.Entry<Integer, ByteArray> failedKey: nodeToFailedKeysMap.entries()) {
            Integer nodeId = failedKey.getKey();
            ByteArray key = failedKey.getValue();
            byte[] expected = keyValues.get(key).get();

            Integer id = keyList.indexOf(key);

            // check if map exist
View Full Code Here

            byte[] opCode = new byte[] { operation.getOpCode() };
            byte[] spacer = new byte[] { (byte) 0 };
            byte[] storeName = ByteUtils.getBytes(STORE_NAME, "UTF-8");
            byte[] nodeIdBytes = new byte[ByteUtils.SIZE_OF_INT];
            ByteUtils.writeInt(nodeIdBytes, entry.getKey(), 0);
            ByteArray slopKey = new ByteArray(ByteUtils.cat(opCode,
                                                            spacer,
                                                            storeName,
                                                            spacer,
                                                            nodeIdBytes,
                                                            spacer,
View Full Code Here

        RetentionEnforcingStore store = new RetentionEnforcingStore(engine,
                                                                    retentionStoreDef,
                                                                    onlineDeletes,
                                                                    time);
        // do a bunch of puts
        store.put(new ByteArray("k1".getBytes()), new Versioned<byte[]>("v1".getBytes()), null);
        store.put(new ByteArray("k2".getBytes()), new Versioned<byte[]>("v2".getBytes()), null);
        long writeMs = System.currentTimeMillis();

        // wait for a bit and then do more puts
        Thread.sleep(2000);

        store.put(new ByteArray("k3".getBytes()), new Versioned<byte[]>("v3".getBytes()), null);
        store.put(new ByteArray("k4".getBytes()), new Versioned<byte[]>("v4".getBytes()), null);

        // move time forward just enough such that some keys will have expired.
        time.setTime(writeMs + retentionStoreDef.getRetentionDays() * Time.MS_PER_DAY + 1);
        assertEquals("k1 should have expired", 0, store.get(new ByteArray("k1".getBytes()), null)
                                                       .size());
        assertEquals("k2 should have expired", 0, store.get(new ByteArray("k2".getBytes()), null)
                                                       .size());

        assertTrue("k3 should not have expired", store.get(new ByteArray("k3".getBytes()), null)
                                                      .size() > 0);
        assertTrue("k4 should not have expired", store.get(new ByteArray("k4".getBytes()), null)
                                                      .size() > 0);
        // get all with k1, k4 should return a map with k4 alone
        Map<ByteArray, List<Versioned<byte[]>>> getAllResult = store.getAll(Arrays.asList(new ByteArray("k1".getBytes()),
                                                                                          new ByteArray("k4".getBytes())),
                                                                            null);
        assertEquals("map should contain one element only", 1, getAllResult.size());
        assertEquals("k1 should not be present",
                     false,
                     getAllResult.containsKey(new ByteArray("k1".getBytes())));
        assertEquals("k4 should be present",
                     true,
                     getAllResult.containsKey(new ByteArray("k4".getBytes())));

        // if online deletes are not configured, we should see the deleted keys
        // in the base bdb store, so the datacleanup job can go and delete them
        assertEquals("k1 should be present",
                     !onlineDeletes,
                     engine.get(new ByteArray("k1".getBytes()), null).size() > 0);
        assertEquals("k2 should be present",
                     !onlineDeletes,
                     engine.get(new ByteArray("k2".getBytes()), null).size() > 0);

        // delete everything for next run
        engine.truncate();
    }
View Full Code Here

    }

    private void put(String... items) {
        for(String item: items) {
            VectorClock clock = null;
            List<Versioned<byte[]>> found = engine.get(new ByteArray(item.getBytes()), null);
            if(found.size() == 0) {
                clock = new VectorClock(time.getMilliseconds());
            } else if(found.size() == 1) {
                VectorClock oldClock = (VectorClock) found.get(0).getVersion();
                clock = oldClock.incremented(0, time.getMilliseconds());
            } else {
                fail("Found multiple versions.");
            }
            engine.put(new ByteArray(item.getBytes()),
                       new Versioned<byte[]>(item.getBytes(), clock),
                       null);
        }
    }
View Full Code Here

    public void testVersionedPut() {
        defaultStoreClient.put(KEY, v1);
        defaultStoreClient.put(KEY, v2);
        Versioned<String> res = defaultStoreClient.get(KEY);
        defaultStoreClient.put(KEY, res);
        List<Versioned<byte[]>> resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
        assertEquals(1, resList.size());
    }
View Full Code Here

        }
    }

    private void assertContains(String... keys) {
        for(String key: keys) {
            List<Versioned<byte[]>> found = engine.get(new ByteArray(key.getBytes()), null);
            assertTrue("Did not find key '" + key + "' in store!", found.size() > 0);
        }
    }
View Full Code Here

    @Test
    public void testNormalPut() {
        defaultStoreClient.put(KEY, v1);
        defaultStoreClient.put(KEY, v2);
        defaultStoreClient.put(KEY, "my-value2");
        List<Versioned<byte[]>> resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
        assertEquals(1, resList.size());
    }
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.