Java Code Examples for net.spy.memcached.MemcachedClient#add()

The following examples show how to use net.spy.memcached.MemcachedClient#add() . 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: IntegrationJUnitTest.java    From gemfirexd-oss with Apache License 2.0 7 votes vote down vote up
public void testGemFireProperty() throws Exception {
  Properties props = new Properties();
  final int port = AvailablePortHelper.getRandomAvailableTCPPort();
  props.setProperty("memcached-port", port+"");
  CacheFactory cf = new CacheFactory(props);
  Cache cache = cf.create();
  
  MemcachedClient client = new MemcachedClient(
      new InetSocketAddress(SocketCreator.getLocalHost(), port));
  Future<Boolean> f = client.add("key", 10, "myStringValue");
  assertTrue(f.get());
  Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
  assertTrue(f1.get());
  
  assertEquals("myStringValue", client.get("key"));
  assertEquals("myStringValue1", client.get("key1"));
  assertNull(client.get("nonExistentkey"));
  cache.close();
}
 
Example 2
Source File: IntegrationJUnitTest.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public void testGemFireProperty() throws Exception {
  Properties props = new Properties();
  final int port = AvailablePortHelper.getRandomAvailableTCPPort();
  props.setProperty("memcached-port", port+"");
  CacheFactory cf = new CacheFactory(props);
  Cache cache = cf.create();
  
  MemcachedClient client = new MemcachedClient(
      new InetSocketAddress(SocketCreator.getLocalHost(), port));
  Future<Boolean> f = client.add("key", 10, "myStringValue");
  assertTrue(f.get());
  Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
  assertTrue(f1.get());
  
  assertEquals("myStringValue", client.get("key"));
  assertEquals("myStringValue1", client.get("key1"));
  assertNull(client.get("nonExistentkey"));
  cache.close();
}
 
Example 3
Source File: DomainObjectsAsValuesJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testGetPutDomainObject() throws Exception {
  MemcachedClient client = new MemcachedClient(
      new InetSocketAddress(SocketCreator.getLocalHost(), PORT));
  Customer c = new Customer("name0", "addr0");
  Customer c1 = new Customer("name1", "addr1");
  Future<Boolean> f = client.add("keyObj", 10, c);
  assertTrue(f.get());
  Future<Boolean> f1 = client.add("key1", 10, c1);
  assertTrue(f1.get());
  assertEquals(c, client.get("keyObj"));
  assertEquals(c1, client.get("key1"));
  assertNull(client.get("nonExistentkey"));
}
 
Example 4
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testPutGet() throws Exception {
  MemcachedClient client = createMemcachedClient();
  Future<Boolean> f = client.add("key", 10, "myStringValue");
  assertTrue(f.get());
  Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
  assertTrue(f1.get());
  assertEquals("myStringValue", client.get("key"));
  assertEquals("myStringValue1", client.get("key1"));
  assertNull(client.get("nonExistentkey"));
  // zero exp
  f = client.add("Hello", 0, "World");
  Thread.sleep(1100);
  assertEquals("World", client.get("Hello"));
}
 
Example 5
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testMultiGet() throws Exception {
  MemcachedClient client = bootstrapClient();
  Map<String, Object> val = client.getBulk("key", "key1");
  assertEquals(2, val.size());
  assertEquals("myStringValue", val.get("key"));
  assertEquals("myStringValue1", val.get("key1"));
  client.add("Hello", 0, "World");
  Thread.sleep(1100);
  assertEquals("World", client.get("Hello"));
}
 
Example 6
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private MemcachedClient bootstrapClient() throws IOException,
    UnknownHostException, InterruptedException, ExecutionException {
  MemcachedClient client = createMemcachedClient();
  Future<Boolean> f = client.add("key", 10, "myStringValue");
  f.get();
  Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
  f1.get();
  return client;
}
 
Example 7
Source File: DomainObjectsAsValuesJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testGetPutDomainObject() throws Exception {
  MemcachedClient client = new MemcachedClient(
      new InetSocketAddress(SocketCreator.getLocalHost(), PORT));
  Customer c = new Customer("name0", "addr0");
  Customer c1 = new Customer("name1", "addr1");
  Future<Boolean> f = client.add("keyObj", 10, c);
  assertTrue(f.get());
  Future<Boolean> f1 = client.add("key1", 10, c1);
  assertTrue(f1.get());
  assertEquals(c, client.get("keyObj"));
  assertEquals(c1, client.get("key1"));
  assertNull(client.get("nonExistentkey"));
}
 
Example 8
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testPutGet() throws Exception {
  MemcachedClient client = createMemcachedClient();
  Future<Boolean> f = client.add("key", 10, "myStringValue");
  assertTrue(f.get());
  Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
  assertTrue(f1.get());
  assertEquals("myStringValue", client.get("key"));
  assertEquals("myStringValue1", client.get("key1"));
  assertNull(client.get("nonExistentkey"));
  // zero exp
  f = client.add("Hello", 0, "World");
  Thread.sleep(1100);
  assertEquals("World", client.get("Hello"));
}
 
Example 9
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void testMultiGet() throws Exception {
  MemcachedClient client = bootstrapClient();
  Map<String, Object> val = client.getBulk("key", "key1");
  assertEquals(2, val.size());
  assertEquals("myStringValue", val.get("key"));
  assertEquals("myStringValue1", val.get("key1"));
  client.add("Hello", 0, "World");
  Thread.sleep(1100);
  assertEquals("World", client.get("Hello"));
}
 
Example 10
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private MemcachedClient bootstrapClient() throws IOException,
    UnknownHostException, InterruptedException, ExecutionException {
  MemcachedClient client = createMemcachedClient();
  Future<Boolean> f = client.add("key", 10, "myStringValue");
  f.get();
  Future<Boolean> f1 = client.add("key1", 10, "myStringValue1");
  f1.get();
  return client;
}
 
Example 11
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testAdd() throws Exception {
  MemcachedClient client = bootstrapClient();
  Future<Boolean> f = client.add("key", 10, "newVal");
  assertFalse(f.get());
}
 
Example 12
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testLongExpiration() throws Exception {
  MemcachedClient client = bootstrapClient();
  client.add("newKey", (int)System.currentTimeMillis() - 60 *1000, "newValue");
  Thread.sleep(15 *1000);
  assertEquals("newValue", client.get("newKey"));
}
 
Example 13
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testAdd() throws Exception {
  MemcachedClient client = bootstrapClient();
  Future<Boolean> f = client.add("key", 10, "newVal");
  assertFalse(f.get());
}
 
Example 14
Source File: GemcachedDevelopmentJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testLongExpiration() throws Exception {
  MemcachedClient client = bootstrapClient();
  client.add("newKey", (int)System.currentTimeMillis() - 60 *1000, "newValue");
  Thread.sleep(15 *1000);
  assertEquals("newValue", client.get("newKey"));
}