Search in sources :

Example 6 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project geode by apache.

the class GemcachedBinaryClientJUnitTest method testCacheLoaderException.

@SuppressWarnings("unchecked")
public void testCacheLoaderException() throws Exception {
    MemcachedClient client = createMemcachedClient();
    assertTrue(client.set("key", 0, "value").get());
    GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
    Region region = cache.getRegion(GemFireMemcachedServer.REGION_NAME);
    region.getAttributesMutator().setCacheLoader(new CacheLoader() {

        @Override
        public void close() {
        }

        @Override
        public Object load(LoaderHelper helper) throws CacheLoaderException {
            if (helper.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
                throw new RuntimeException("ExpectedStrings: Cache loader exception");
            }
            return null;
        }
    });
    long start = System.nanoTime();
    try {
        client.get("exceptionkey");
        throw new RuntimeException("expected exception not thrown");
    } catch (Exception e) {
    // expected
    }
    assertEquals("value", client.get("key"));
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) MemcachedClient(net.spy.memcached.MemcachedClient) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 7 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project geode by apache.

the class GemcachedDevelopmentJUnitTest method testFlushDelay.

@Test
public void testFlushDelay() throws Exception {
    MemcachedClient client = bootstrapClient();
    Future<Boolean> b = client.flush(5);
    assertTrue(b.get());
    assertNotNull(client.get("key"));
    assertNotNull(client.get("key1"));
    Thread.sleep(8 * 1000);
    assertNull(client.get("key"));
    assertNull(client.get("key1"));
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project geode by apache.

the class GemcachedDevelopmentJUnitTest method testPutGet.

@Test
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"));
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project geode by apache.

the class GemcachedDevelopmentJUnitTest method testReplace.

@Test
public void testReplace() throws Exception {
    MemcachedClient client = bootstrapClient();
    Future<Boolean> b = client.replace("key", 10, "newVal");
    assertTrue(b.get());
    b = client.replace("nonExistentkey", 10, "val");
    assertFalse(b.get());
    b = client.replace("key", 10, "myStringValue");
    assertTrue(b.get());
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project geode by apache.

the class GemcachedDevelopmentJUnitTest method testFlush.

@Test
public void testFlush() throws Exception {
    MemcachedClient client = bootstrapClient();
    Future<Boolean> b = client.flush();
    assertTrue(b.get());
    assertNull(client.get("key"));
    assertNull(client.get("key1"));
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

MemcachedClient (net.spy.memcached.MemcachedClient)52 Test (org.junit.Test)22 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)17 InetSocketAddress (java.net.InetSocketAddress)11 ExecutionException (java.util.concurrent.ExecutionException)9 ConnectionFactoryBuilder (net.spy.memcached.ConnectionFactoryBuilder)8 ConnectionFactory (net.spy.memcached.ConnectionFactory)7 IOException (java.io.IOException)6 TimeoutException (java.util.concurrent.TimeoutException)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 BinaryConnectionFactory (net.spy.memcached.BinaryConnectionFactory)3 Predicate (com.google.common.base.Predicate)2 Supplier (com.google.common.base.Supplier)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Config (com.hazelcast.config.Config)2