Java Code Examples for com.google.appengine.api.memcache.MemcacheService#IdentifiableValue

The following examples show how to use com.google.appengine.api.memcache.MemcacheService#IdentifiableValue . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutIfUntouchedExpire() {
    final String TS_KEY = createTimeStampKey("testPutIfUntouched");

    memcache.put(TS_KEY, STR_VALUE);
    MemcacheService.IdentifiableValue oldOriginalIdValue = memcache.getIdentifiable(TS_KEY);
    final String NEW_VALUE = "new-" + STR_VALUE;

    // Store NEW_VALUE if no other value stored since oldOriginalIdValue was retrieved.
    // memcache.get() has not been called, so this put should succeed.
    Boolean valueWasStored = memcache.putIfUntouched(TS_KEY, oldOriginalIdValue, NEW_VALUE, Expiration.byDeltaSeconds(1));
    assertEquals(true, valueWasStored);
    assertEquals(NEW_VALUE, memcache.get(TS_KEY));

    // Value should not be stored after expiration period.
    sync(3000);
    assertNull(memcache.get(TS_KEY));
}
 
Example 2
Source File: MemcacheAsyncTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetIdentifiables() {
    unwrap(service.put("key1", "value1"));
    unwrap(service.put("key2", "value2"));
    Map<String, MemcacheService.IdentifiableValue> identifiables = unwrap(service.getIdentifiables(Arrays.asList("key1", "key2")));

    assertEquals(2, identifiables.size());

    assertNotNull(identifiables.get("key1"));
    assertEquals("value1", identifiables.get("key1").getValue());

    assertNotNull(identifiables.get("key2"));
    assertEquals("value2", identifiables.get("key2").getValue());
}
 
Example 3
Source File: MemcacheAsyncTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutIfUntouched() {
    unwrap(service.put("key", "value"));

    MemcacheService.IdentifiableValue identifiable = unwrap(service.getIdentifiable("key"));

    boolean valueWasStored = unwrap(service.putIfUntouched("key", identifiable, "newValue"));
    assertTrue(valueWasStored);
    assertEquals("newValue", unwrap(service.get("key")));

    boolean valueWasStored2 = unwrap(service.putIfUntouched("key", identifiable, "newestValue"));
    assertFalse(valueWasStored2);
    assertEquals("newValue", unwrap(service.get("key")));
}
 
Example 4
Source File: MemcacheAsyncTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutIfUntouchedMulti() {
    unwrap(service.put("key1", "value1"));
    unwrap(service.put("key2", "value2"));

    MemcacheService.IdentifiableValue identifiable1 = unwrap(service.getIdentifiable("key1"));
    MemcacheService.IdentifiableValue identifiable2 = unwrap(service.getIdentifiable("key2"));


    HashMap<Object, MemcacheService.CasValues> map = new HashMap<Object, MemcacheService.CasValues>();
    map.put("key1", new MemcacheService.CasValues(identifiable1, "newValue1"));
    map.put("key2", new MemcacheService.CasValues(identifiable2, "newValue2"));

    Set<Object> storedKeys = unwrap(service.putIfUntouched(map));
    assertEquals(2, storedKeys.size());
    assertTrue(storedKeys.contains("key1"));
    assertTrue(storedKeys.contains("key2"));
    assertEquals("newValue1", unwrap(service.get("key1")));
    assertEquals("newValue2", unwrap(service.get("key2")));


    map = new HashMap<Object, MemcacheService.CasValues>();
    map.put("key1", new MemcacheService.CasValues(identifiable1, "newestValue1"));
    map.put("key2", new MemcacheService.CasValues(identifiable1, "newestValue2"));

    storedKeys = unwrap(service.putIfUntouched(map));
    assertTrue(storedKeys.isEmpty());
    assertEquals("newValue1", unwrap(service.get("key1")));
    assertEquals("newValue2", unwrap(service.get("key2")));
}
 
Example 5
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetIdentifiables() {
    memcache.put("key1", "value1");
    memcache.put("key2", "value2");
    Map<String, MemcacheService.IdentifiableValue> identifiables = memcache.getIdentifiables(Arrays.asList("key1", "key2"));

    assertEquals(2, identifiables.size());

    assertNotNull(identifiables.get("key1"));
    assertEquals("value1", identifiables.get("key1").getValue());

    assertNotNull(identifiables.get("key2"));
    assertEquals("value2", identifiables.get("key2").getValue());
}
 
Example 6
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSomeIdentifiables() {
    memcache.put("key1", "value1");
    Map<String, MemcacheService.IdentifiableValue> identifiables = memcache.getIdentifiables(Arrays.asList("key1", "no_such_key2"));

    assertEquals(1, identifiables.size());

    assertNotNull(identifiables.get("key1"));
    assertEquals("value1", identifiables.get("key1").getValue());
}
 
Example 7
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutIfUntouched() {
    memcache.put("key", "value");

    MemcacheService.IdentifiableValue identifiable = memcache.getIdentifiable("key");

    boolean valueWasStored = memcache.putIfUntouched("key", identifiable, "newValue");
    assertTrue(valueWasStored);
    assertEquals("newValue", memcache.get("key"));

    boolean valueWasStored2 = memcache.putIfUntouched("key", identifiable, "newestValue");
    assertFalse(valueWasStored2);
    assertEquals("newValue", memcache.get("key"));
}
 
Example 8
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutIfUntouchedMulti() {
    memcache.put("key1", "value1");
    memcache.put("key2", "value2");

    MemcacheService.IdentifiableValue identifiable1 = memcache.getIdentifiable("key1");
    MemcacheService.IdentifiableValue identifiable2 = memcache.getIdentifiable("key2");


    HashMap<Object, MemcacheService.CasValues> map = new HashMap<Object, MemcacheService.CasValues>();
    map.put("key1", new MemcacheService.CasValues(identifiable1, "newValue1"));
    map.put("key2", new MemcacheService.CasValues(identifiable2, "newValue2"));

    Set<Object> storedKeys = memcache.putIfUntouched(map);
    assertEquals(2, storedKeys.size());
    assertTrue(storedKeys.contains("key1"));
    assertTrue(storedKeys.contains("key2"));
    assertEquals("newValue1", memcache.get("key1"));
    assertEquals("newValue2", memcache.get("key2"));


    map = new HashMap<Object, MemcacheService.CasValues>();
    map.put("key1", new MemcacheService.CasValues(identifiable1, "newestValue1"));
    map.put("key2", new MemcacheService.CasValues(identifiable1, "newestValue2"));

    storedKeys = memcache.putIfUntouched(map);
    assertTrue(storedKeys.isEmpty());
    assertEquals("newValue1", memcache.get("key1"));
    assertEquals("newValue2", memcache.get("key2"));
}
 
Example 9
Source File: AppEngineMemcachedClient.java    From memcached-spring-boot with Apache License 2.0 4 votes vote down vote up
@Override
public void touch(String key, int exp) {
    final MemcacheService.IdentifiableValue identifiable = this.service.getIdentifiable(key);
    this.service.putIfUntouched(key, identifiable, identifiable.getValue(), Expiration.byDeltaSeconds(exp));
}
 
Example 10
Source File: MemcacheAsyncTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetIdentifiable() {
    unwrap(service.put("key", "value"));
    MemcacheService.IdentifiableValue identifiable = unwrap(service.getIdentifiable("key"));
    assertEquals("value", identifiable.getValue());
}
 
Example 11
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetIdentifiable() {
    memcache.put("key", "value");
    MemcacheService.IdentifiableValue identifiable = memcache.getIdentifiable("key");
    assertEquals("value", identifiable.getValue());
}
 
Example 12
Source File: MemcacheTest.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetNoIdentifiable() {
    MemcacheService.IdentifiableValue identifiable = memcache.getIdentifiable("no_such_key1");
    assertNull(identifiable);
}