Search in sources :

Example 1 with LockTimeoutException

use of com.sleepycat.je.LockTimeoutException 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 2 with LockTimeoutException

use of com.sleepycat.je.LockTimeoutException in project voldemort by voldemort.

the class BdbStorageEngineTest method testGetAndLock.

@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()));
}
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)

Aggregations

LockTimeoutException (com.sleepycat.je.LockTimeoutException)2 Test (org.junit.Test)2 AbstractStorageEngineTest (voldemort.store.AbstractStorageEngineTest)2 PersistenceFailureException (voldemort.store.PersistenceFailureException)2 ByteArray (voldemort.utils.ByteArray)2 Versioned (voldemort.versioning.Versioned)2