public void testPrependWithoutCAS() throws Exception { final String key = "prepend.key"; assertTrue(client.set(key, 5, "test").get()); OperationFuture<Boolean> op = client.prepend(key, "es"); assertTrue(op.get()); assert op.getStatus().isSuccess(); assertEquals("estest", client.get(key)); }
/** * Set a value and Observe. * * @param key the key to set * @param exp the Expiry value * @param value the Key value * @param req the Persistence to Master value * @param rep the Persistence to Replicas * @return whether or not the operation was performed */ public OperationFuture<Boolean> set( String key, int exp, String value, PersistTo req, ReplicateTo rep) { OperationFuture<Boolean> setOp = set(key, exp, value); try { if (setOp.get()) { observePoll(key, setOp.getCas(), req, rep); } } catch (InterruptedException e) { setOp.set(false, setOp.getStatus()); } catch (ExecutionException e) { setOp.set(false, setOp.getStatus()); } catch (TimeoutException e) { setOp.set(false, setOp.getStatus()); } catch (IllegalArgumentException e) { setOp.set(false, setOp.getStatus()); } catch (RuntimeException e) { setOp.set(false, setOp.getStatus()); } return (setOp); }
public void testABunchOfCancelledOperations() throws Exception { final String k = "bunchOCancel"; Collection<Future<?>> futures = new ArrayList<Future<?>>(); for (int i = 0; i < 1000; i++) { futures.add(client.set(k, 5, "xval")); futures.add(client.asyncGet(k)); } OperationFuture<Boolean> sf = client.set(k, 5, "myxval"); GetFuture<Object> gf = client.asyncGet(k); for (Future<?> f : futures) { f.cancel(true); } assertTrue(sf.get()); assert sf.getStatus().isSuccess(); assertEquals("myxval", gf.get()); assert gf.getStatus().isSuccess(); }
/** * Delete a value and Observe. * * @param key the key to set * @param req the Persistence to Master value * @param rep the Persistence to Replicas * @return whether or not the operation was performed */ public OperationFuture<Boolean> delete(String key, PersistTo req, ReplicateTo rep) { OperationFuture<Boolean> deleteOp = delete(key); try { deleteOp.get(); deleteOp.set(true, deleteOp.getStatus()); observePoll(key, 0L, req, rep); } catch (InterruptedException e) { deleteOp.set(false, deleteOp.getStatus()); } catch (ExecutionException e) { deleteOp.set(false, deleteOp.getStatus()); } catch (TimeoutException e) { deleteOp.set(false, deleteOp.getStatus()); } catch (IllegalArgumentException e) { deleteOp.set(false, deleteOp.getStatus()); } catch (RuntimeException e) { deleteOp.set(false, deleteOp.getStatus()); } return (deleteOp); }