public void testCAS() throws Exception { final String key = "castestkey"; // First, make sure it doesn't work for a non-existing value. assertSame( "Expected error CASing with no existing value.", CASResponse.NOT_FOUND, client.cas(key, 0x7fffffffffL, "bad value")); // OK, stick a value in here. assertTrue(client.add(key, 5, "original value").get()); CASValue<?> getsVal = client.gets(key); assertEquals("original value", getsVal.getValue()); // Now try it with an existing value, but wrong CAS id assertSame( "Expected error CASing with invalid id", CASResponse.EXISTS, client.cas(key, getsVal.getCas() + 1, "broken value")); // Validate the original value is still in tact. assertEquals("original value", getsVal.getValue()); // OK, now do a valid update assertSame( "Expected successful CAS with correct id (" + getsVal.getCas() + ")", CASResponse.OK, client.cas(key, getsVal.getCas(), "new value")); assertEquals("new value", client.get(key)); // Test a CAS replay assertSame( "Expected unsuccessful CAS with replayed id", CASResponse.EXISTS, client.cas(key, getsVal.getCas(), "crap value")); assertEquals("new value", client.get(key)); }
@Test public void testCASValueToString() { CASValue<String> c = new CASValue<String>(717L, "hi"); assertEquals("{CasValue 717/hi}", c.toString()); }