Package voldemort.utils

Examples of voldemort.utils.ByteArray


                                                                                     .asSlopStore();

        // 5 slops for 3 stores => ( key1 [put(value1), delete, put(value2)] AND
        // key2 [put(value2), delete] )
        long keyInt1 = (long) (Math.random() * 1000000000L), keyInt2 = (long) (Math.random() * 10000000L);
        ByteArray key1 = new ByteArray(ByteUtils.getBytes("" + keyInt1, "UTF-8")), key2 = new ByteArray(ByteUtils.getBytes(""
                                                                                                                                   + keyInt2,
                                                                                                                           "UTF-8"));
        byte[] value1 = ByteUtils.getBytes("value-" + new String(key1.get()), "UTF-8"), value2 = ByteUtils.getBytes("value-"
                                                                                                                            + new String(key2.get()),
                                                                                                                    "UTF-8");

        VectorClock vectorClock1 = new VectorClock(), vectorClock2 = new VectorClock();

        List<Versioned<Slop>> entrySet = Lists.newArrayList();
View Full Code Here


        return store;
    }

    @Test
    public void testPersistence() throws Exception {
        this.store.put(new ByteArray("abc".getBytes()),
                       new Versioned<byte[]>("cdef".getBytes()),
                       null);
        this.store.close();
        this.environment.close();
        this.environment = new Environment(this.tempDir, envConfig);
        this.database = environment.openDatabase(null, "test", databaseConfig);
        this.store = makeBdbStorageEngine("test",
                                          this.environment,
                                          this.database,
                                          runtimeConfig,
                                          this.prefixPartitionId);
        List<Versioned<byte[]>> vals = store.get(new ByteArray("abc".getBytes()), null);
        assertEquals(1, vals.size());
        TestUtils.bytesEqual("cdef".getBytes(), vals.get(0).getValue());
    }
View Full Code Here

        ExecutorService executor = Executors.newFixedThreadPool(10);
        final CountDownLatch latch = new CountDownLatch(10);
        final AtomicBoolean returnedEmpty = new AtomicBoolean(false);
        final byte[] keyBytes = "foo".getBytes();
        final byte[] valueBytes = "bar".getBytes();
        store.put(new ByteArray(keyBytes), new Versioned<byte[]>(valueBytes), null);

        for(int i = 0; i < 10; i++) {
            executor.submit(new Runnable() {

                public void run() {
                    try {
                        for(int j = 0; j < 1000 && !returnedEmpty.get(); j++) {
                            List<Versioned<byte[]>> vals = store.get(new ByteArray(keyBytes), null);
                            if(vals.size() == 0 && j > 1)
                                returnedEmpty.set(true);
                            else {
                                VectorClock v = (VectorClock) vals.get(0).getVersion();
                                v.incrementVersion(0, System.currentTimeMillis());
                                try {
                                    store.put(new ByteArray(keyBytes),
                                              new Versioned<byte[]>(valueBytes, v),
                                              null);
                                } catch(ObsoleteVersionException e) {
                                    // Ignore these
                                }
View Full Code Here

        assertFalse("Should not have seen any empty results", returnedEmpty.get());
    }

    @Test(timeout = 30000)
    public void testGetAndLock() throws Exception {
        final ByteArray key = new ByteArray("getAndLock".getBytes());
        final byte[] valueBytes = "bar".getBytes();

        store.put(key, new Versioned<byte[]>(valueBytes), null);
        KeyLockHandle<byte[]> handle = store.getAndLock(key);

        // get will block and timeout
        try {
            store.get(key, null);
            fail("get(..) should have blocked and timedout");
        } catch(PersistenceFailureException pfe) {
            // expected
            assertTrue("Should have had a LockTimeoutException",
                       pfe.getCause() instanceof LockTimeoutException);
        }

        // let go of the key lock
        store.releaseLock(handle);

        // get should not block, since the lock has been released
        List<Versioned<byte[]>> vals = store.get(key, null);
        assertEquals("Should read back the version previously written", 1, vals.size());
        assertEquals("Should read back the version previously written",
                     new ByteArray(valueBytes),
                     new ByteArray(vals.get(0).getValue()));
    }
View Full Code Here

                     new ByteArray(vals.get(0).getValue()));
    }

    @Test(timeout = 30000)
    public void testPutAndLock() throws Exception {
        final ByteArray key = new ByteArray("putAndLock".getBytes());
        final byte[] valueBytes = "Lion".getBytes();

        store.put(key, new Versioned<byte[]>(valueBytes), null);
        // begin the read-modify-write cycle
        KeyLockHandle<byte[]> handle = store.getAndLock(key);
View Full Code Here

        executor.execute(new Runnable() {

            public void run() {
                while(keepRunning.get()) {
                    byte[] bytes = Integer.toString(count.getAndIncrement()).getBytes();
                    store.put(new ByteArray(bytes), Versioned.value(bytes), null);
                    count.incrementAndGet();
                }
            }
        });
        executor.execute(new Runnable() {

            public void run() {
                while(keepRunning.get()) {
                    byte[] bytes = Integer.toString(rand.nextInt(count.get())).getBytes();
                    store.delete(new ByteArray(bytes), new VectorClock());
                    count.incrementAndGet();
                }
            }
        });
View Full Code Here

                                                                  StoreDefinitionUtils.getStoreDefinitionWithName(storeDefs,
                                                                                                                  "test"));

            // Confirm the valid ones made it
            for(Versioned<Slop> slop: validStoreSlops) {
                ByteArray key = slop.getValue().getKey();

                if(rPlan.getReplicationNodeList(key.get()).contains(1)) {
                    List<Versioned<byte[]>> slopEntry = adminClient.storeOps.getNodeKey("test",
                                                                                        1,
                                                                                        key);
                    if(slop.getValue().getOperation() == Operation.DELETE) {
                        assertTrue("Delete Slop should have not reached destination",
View Full Code Here

    @Test
    public void testVeryLargeValues() throws Exception {
        final Store<ByteArray, byte[], byte[]> store = getStore();
        byte[] biggie = new byte[1 * 1024 * 1024];
        ByteArray key = new ByteArray(biggie);
        Random rand = new Random();
        for(int i = 0; i < 10; i++) {
            rand.nextBytes(biggie);
            Versioned<byte[]> versioned = new Versioned<byte[]>(biggie);
            store.put(key, versioned, null);
View Full Code Here

    }

    public ByteArray getValidKey() {
        int i = (int) (Math.random() * TEST_KEYS.size());
        String key = TEST_KEYS.get(i);
        return new ByteArray(ByteUtils.getBytes(key, "UTF-8"));
    }
View Full Code Here

    }

    @Test
    public void testSimpleGetAndPut() {
        for(int i = 0; i <= TEST_RUNS; i++) {
            ByteArray key = getValidKey();
            VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
            Versioned<byte[]> value = new Versioned<byte[]>(getValidValue(key),
                                                            clock.incremented(0, 1));

            metadataStore.put(key, value, null);
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.