Search in sources :

Example 76 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class BdbStorageEngineTest method testPutAndLock.

@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);
    // put will block and timeout
    try {
        store.put(key, new Versioned<byte[]>("Mountain Lion".getBytes()), null);
        fail("put(..) should have blocked and timedout");
    } catch (PersistenceFailureException pfe) {
        // expected
        assertTrue("Should have had a LockTimeoutException", pfe.getCause() instanceof LockTimeoutException);
    }
    // end the read-modify-write cycle
    handle.setValues(Lists.newArrayList(new Versioned<byte[]>("Mavericks".getBytes())));
    store.putAndUnlock(key, handle);
    // get should not block, and read out Mavericks
    List<Versioned<byte[]>> vals = store.get(key, null);
    assertEquals("Exactly one version", 1, vals.size());
    assertEquals("Should read back the version written by putAndUnlock", "Mavericks", new String(vals.get(0).getValue()));
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) PersistenceFailureException(voldemort.store.PersistenceFailureException) LockTimeoutException(com.sleepycat.je.LockTimeoutException) AbstractStorageEngineTest(voldemort.store.AbstractStorageEngineTest) Test(org.junit.Test)

Example 77 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class BdbStorageEngineTest method testConcurrentReadAndPut.

@Test
public void testConcurrentReadAndPut() throws Exception {
    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
                            }
                        }
                    }
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    latch.await();
    assertFalse("Should not have seen any empty results", returnedEmpty.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ExecutorService(java.util.concurrent.ExecutorService) ByteArray(voldemort.utils.ByteArray) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractStorageEngineTest(voldemort.store.AbstractStorageEngineTest) Test(org.junit.Test)

Example 78 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class MetadataStoreTest method testSimpleGetAndPut.

@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);
        checkValues(value, metadataStore.get(key, null), key);
    }
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) AvroAddStoreTest(voldemort.tools.admin.AvroAddStoreTest) Test(org.junit.Test)

Example 79 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class MetadataStoreTest method testObsoletePut.

@Test
public void testObsoletePut() {
    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));
        try {
            metadataStore.put(key, value, null);
            assertTrue(true);
            metadataStore.put(key, value, null);
            fail();
        } catch (ObsoleteVersionException e) {
        // expected ObsoleteVersionException
        }
    }
}
Also used : ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) AvroAddStoreTest(voldemort.tools.admin.AvroAddStoreTest) Test(org.junit.Test)

Example 80 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class MetadataStoreTest method testSynchronousPut.

@Test
public void testSynchronousPut() {
    for (int i = 0; i <= TEST_RUNS; i++) {
        ByteArray key = getValidKey();
        VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
        Versioned<byte[]> value1 = new Versioned<byte[]>(getValidValue(key), clock.incremented(1, 1));
        Versioned<byte[]> value2 = new Versioned<byte[]>(getValidValue(key), clock.incremented(2, 1));
        metadataStore.put(key, value1, null);
        metadataStore.put(key, value2, null);
        assertEquals("Only one metadata value should return", 1, metadataStore.get(key, null).size());
        checkValues(value2, metadataStore.get(key, null), key);
    }
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) AvroAddStoreTest(voldemort.tools.admin.AvroAddStoreTest) Test(org.junit.Test)

Aggregations

Versioned (voldemort.versioning.Versioned)214 ByteArray (voldemort.utils.ByteArray)130 Test (org.junit.Test)88 VectorClock (voldemort.versioning.VectorClock)73 ArrayList (java.util.ArrayList)56 VoldemortException (voldemort.VoldemortException)48 List (java.util.List)36 StoreDefinition (voldemort.store.StoreDefinition)29 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 Node (voldemort.cluster.Node)27 Pair (voldemort.utils.Pair)25 Slop (voldemort.store.slop.Slop)22 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)22 Map (java.util.Map)21 Cluster (voldemort.cluster.Cluster)17 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)15 InvalidMetadataException (voldemort.store.InvalidMetadataException)13 PersistenceFailureException (voldemort.store.PersistenceFailureException)13 Version (voldemort.versioning.Version)13