@Test
  public void testGetVersionedCacheEntry() {

    VersionedValue value = remoteCache.getVersioned("aKey");
    assertNull("expected null but received: " + value, remoteCache.getVersioned("aKey"));

    remoteCache.put("aKey", "aValue");
    assertEquals("aValue", remoteCache.get("aKey"));
    VersionedValue valueBinary = remoteCache.getVersioned("aKey");
    assertNotNull(valueBinary);
    assertEquals(valueBinary.getValue(), "aValue");

    // now put the same value
    remoteCache.put("aKey", "aValue");
    VersionedValue entry2 = remoteCache.getVersioned("aKey");
    assertEquals(entry2.getValue(), "aValue");

    assertNotEquals(entry2.getVersion(), valueBinary.getVersion());
    assertNotEquals(valueBinary, entry2);

    // now put a different value
    remoteCache.put("aKey", "anotherValue");
    VersionedValue entry3 = remoteCache.getVersioned("aKey");
    assertEquals(entry3.getValue(), "anotherValue");
    assertNotEquals(entry3.getVersion(), entry2.getVersion());
    assertNotEquals(entry3, entry2);
  }
 public static void testPutGetVersioned(RemoteCache<String, String> remoteCache) {
   remoteCache.clear();
   remoteCache.put(KEY1, VALUE1);
   VersionedValue<String> v = remoteCache.getVersioned(KEY1);
   assertEquals(VALUE1, v.getValue());
   assertTrue(v.getVersion() != 0);
 }
 public static void testRemoveWithVersion(RemoteCache<String, String> remoteCache) {
   remoteCache.clear();
   remoteCache.put(KEY1, VALUE1);
   VersionedValue<String> v = remoteCache.getVersioned(KEY1);
   assertEquals(VALUE1, v.getValue());
   long ver = v.getVersion();
   remoteCache.removeWithVersion(KEY1, ver);
   v = remoteCache.getVersioned(KEY1);
   if (v != null) assertTrue(ver != v.getVersion());
 }
 public static void testRemoveWithVersionAsync(RemoteCache<String, String> remoteCache)
     throws Exception {
   remoteCache.clear();
   remoteCache.put(KEY1, VALUE1);
   VersionedValue<String> v = remoteCache.getVersioned(KEY1);
   assertEquals(VALUE1, v.getValue());
   long ver = v.getVersion();
   NotifyingFuture<Boolean> f = remoteCache.removeWithVersionAsync(KEY1, ver);
   f.get(ASYNC_TIMEOUT, TimeUnit.SECONDS);
   v = remoteCache.getVersioned(KEY1);
   if (v != null) assertTrue(ver != v.getVersion());
 }
  @Test
  public void testRemoveWithVersion() {

    assertTrue(!remoteCache.removeWithVersion("aKey", 12321212l));

    remoteCache.put("aKey", "aValue");
    VersionedValue valueBinary = remoteCache.getVersioned("aKey");
    assertTrue(remoteCache.removeWithVersion("aKey", valueBinary.getVersion()));

    remoteCache.put("aKey", "aNewValue");

    VersionedValue entry2 = remoteCache.getVersioned("aKey");
    assertNotEquals(entry2.getVersion(), valueBinary.getVersion());
    assertEquals(entry2.getValue(), "aNewValue");

    assertTrue(!remoteCache.removeWithVersion("aKey", valueBinary.getVersion()));
  }
  @Test
  public void testReplaceWithVersion() {
    assertNull(remoteCache.replace("aKey", "aValue"));

    remoteCache.put("aKey", "aValue");
    VersionedValue valueBinary = remoteCache.getVersioned("aKey");
    // replacement should take place (and so return true)
    assertTrue(remoteCache.replaceWithVersion("aKey", "aNewValue", valueBinary.getVersion()));

    // version should have changed; value should have changed
    VersionedValue entry2 = remoteCache.getVersioned("aKey");
    assertNotEquals(entry2.getVersion(), valueBinary.getVersion());
    assertEquals(entry2.getValue(), "aNewValue");

    // replacement should not take place because we have changed the value
    assertTrue(!remoteCache.replaceWithVersion("aKey", "aNewValue", valueBinary.getVersion()));
  }
  @Test
  public void testRemoveWithVersionAsync() throws Exception {
    NotifyingFuture<Boolean> future = null;
    future = remoteCache.removeWithVersionAsync("aKey", 12321212l);
    assertTrue(!future.get());

    remoteCache.put("aKey", "aValue");
    VersionedValue valueBinary = remoteCache.getVersioned("aKey");
    future = remoteCache.removeWithVersionAsync("aKey", valueBinary.getVersion());
    assertTrue(future.get());

    remoteCache.put("aKey", "aNewValue");
    VersionedValue entry2 = remoteCache.getVersioned("aKey");
    assertNotEquals(entry2.getVersion(), valueBinary.getVersion());
    assertEquals(entry2.getValue(), "aNewValue");

    future = remoteCache.removeWithVersionAsync("aKey", valueBinary.getVersion());
    assertTrue(!future.get());
  }
  @Test
  public void testReplaceWithVersionAsync() throws Exception {
    assertNull(remoteCache.replace("aKey", "aValue"));

    remoteCache.put("aKey", "aValue");
    VersionedValue valueBinary = remoteCache.getVersioned("aKey");
    // replacement should take place (and so return true)
    NotifyingFuture<Boolean> future =
        remoteCache.replaceWithVersionAsync("aKey", "aNewValue", valueBinary.getVersion());
    assertTrue(future.get());

    // version should have changed; value should have changed
    VersionedValue entry2 = remoteCache.getVersioned("aKey");
    assertNotEquals(entry2.getVersion(), valueBinary.getVersion());
    assertEquals("aNewValue", entry2.getValue());

    // replacement should not take place because we have changed the value
    future = remoteCache.replaceWithVersionAsync("aKey", "aNewValue", valueBinary.getVersion());
    assertFalse(future.get());
  }
  @Test
  public void testReplaceWithVersionWithLifespan() throws Exception {
    int lifespanInSecs = 1;
    assertNull(remoteCache.replace("aKey", "aValue"));
    remoteCache.put("aKey", "aValue");
    VersionedValue valueBinary = remoteCache.getVersioned("aKey");
    assertTrue(
        remoteCache.replaceWithVersion(
            "aKey", "aNewValue", valueBinary.getVersion(), lifespanInSecs));

    // version should have changed; value should have changed
    VersionedValue entry2 = remoteCache.getVersioned("aKey");
    assertNotEquals(entry2.getVersion(), valueBinary.getVersion());
    assertEquals("aNewValue", entry2.getValue());

    sleepForSecs(lifespanInSecs + 1);
    assertNull(remoteCache.getVersioned("aKey"));
  }
Ejemplo n.º 10
0
 public void testGetWithVersion() throws Exception {
   Object key = generateKeyAndShutdownServer();
   resetStats();
   VersionedValue value = remoteCache.getVersioned(key);
   assertEquals("v", value.getValue());
 }