Search in sources :

Example 41 with MemcachedClient

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

the class IntegrationJUnitTest method testMemcachedBindAddress.

@Test
public void testMemcachedBindAddress() throws Exception {
    Properties props = new Properties();
    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
    props.setProperty(MEMCACHED_PORT, port + "");
    props.setProperty(MEMCACHED_BIND_ADDRESS, "127.0.0.1");
    props.put(MCAST_PORT, "0");
    CacheFactory cf = new CacheFactory(props);
    Cache cache = cf.create();
    MemcachedClient client = new MemcachedClient(new InetSocketAddress("127.0.0.1", 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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MemcachedClient(net.spy.memcached.MemcachedClient) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 42 with MemcachedClient

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

the class IntegrationJUnitTest method testGemFireProperty.

@Test
public void testGemFireProperty() throws Exception {
    Properties props = new Properties();
    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
    props.setProperty(MEMCACHED_PORT, port + "");
    props.setProperty(MCAST_PORT, "0");
    CacheFactory cf = new CacheFactory(props);
    Cache cache = cf.create();
    MemcachedClient client = new MemcachedClient(new InetSocketAddress(InetAddress.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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MemcachedClient(net.spy.memcached.MemcachedClient) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 43 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project oxCore by GluuFederation.

the class MemcachedProvider method create.

public void create() {
    log.debug("Starting MemcachedProvider ...");
    try {
        final ConnectionFactory connectionFactory;
        if (memcachedConfiguration.getConnectionFactoryType() == MemcachedConnectionFactoryType.BINARY) {
            connectionFactory = new BinaryConnectionFactory(memcachedConfiguration.getMaxOperationQueueLength(), memcachedConfiguration.getBufferSize());
        } else {
            connectionFactory = new DefaultConnectionFactory(memcachedConfiguration.getMaxOperationQueueLength(), memcachedConfiguration.getBufferSize());
        }
        client = new MemcachedClient(connectionFactory, AddrUtil.getAddresses(memcachedConfiguration.getServers()));
        testConnection();
        log.debug("MemcachedProvider started.");
    } catch (Exception e) {
        throw new IllegalStateException("Error starting MemcachedProvider", e);
    }
}
Also used : DefaultConnectionFactory(net.spy.memcached.DefaultConnectionFactory) BinaryConnectionFactory(net.spy.memcached.BinaryConnectionFactory) ConnectionFactory(net.spy.memcached.ConnectionFactory) DefaultConnectionFactory(net.spy.memcached.DefaultConnectionFactory) MemcachedClient(net.spy.memcached.MemcachedClient) BinaryConnectionFactory(net.spy.memcached.BinaryConnectionFactory)

Example 44 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project oxAuth by GluuFederation.

the class CacheGrantManual method main.

public static void main(String[] args) throws IOException {
    final MemcachedClient client = createClients();
    final ExecutorService executorService = Executors.newFixedThreadPool(1000, daemonThreadFactory());
    int count = 10000;
    final long start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        final int key = i;
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                // MemcachedClient client = clients.get(random);
                Object toPut = testGrant();
                // Object toPut = UUID.randomUUID().toString();
                OperationFuture<Boolean> set = null;
                for (int j = 0; j < 3; j++) {
                    set = client.set(Integer.toString(key), 60, toPut);
                }
                // block
                OperationStatus status = set.getStatus();
                System.out.println(" key: " + key + ", time: " + (new Date().getTime() - start) + "ms, set: " + status);
                executorService.execute(new Runnable() {

                    @Override
                    public void run() {
                        int random = random();
                        if (random % 3 == 0) {
                            try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        Object get = client.get(Integer.toString(key));
                        System.out.println("GET key: " + key + " result: " + get);
                    }
                });
            }
        });
    }
    sleep(40);
    // System.out.println(client.get("myKey"));
    // 
    // client.set("myKey", 30, testState());
    // 
    // sleep(12);
    // System.out.println(client.get("myKey"));
    // 
    // sleep(12);
    // System.out.println(client.get("myKey"));
    client.shutdown();
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) OperationStatus(net.spy.memcached.ops.OperationStatus) ExecutorService(java.util.concurrent.ExecutorService) OperationFuture(net.spy.memcached.internal.OperationFuture) Date(java.util.Date)

Example 45 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project druid by druid-io.

the class MemcachedCacheBenchmark method setUp.

@Override
protected void setUp() throws Exception {
    SerializingTranscoder transcoder = new SerializingTranscoder(// 50 MiB
    50 * 1024 * 1024);
    // disable compression
    transcoder.setCompressionThreshold(Integer.MAX_VALUE);
    client = new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH).setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true).setFailureMode(FailureMode.Retry).setTranscoder(transcoder).setShouldOptimize(true).build(), AddrUtil.getAddresses(hosts));
    cache = new MemcachedCache(Suppliers.ofInstance(StupidResourceHolder.create(client)), new MemcachedCacheConfig() {

        @Override
        public String getMemcachedPrefix() {
            return "druid-memcached-benchmark";
        }

        @Override
        public int getTimeout() {
            return 30000;
        }

        @Override
        public int getExpiration() {
            return 3600;
        }
    }, MemcachedCacheTest.NOOP_MONITOR);
    randBytes = new byte[objectSize * 1024];
    new Random(0).nextBytes(randBytes);
}
Also used : SerializingTranscoder(net.spy.memcached.transcoders.SerializingTranscoder) ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) Random(java.util.Random) MemcachedClient(net.spy.memcached.MemcachedClient)

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