Java Code Examples for net.spy.memcached.memcachedclient#shutdown()

The following examples show how to use net.spy.memcached.memcachedclient#shutdown() . 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: SpymemcachedITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  System.err.println("[NOTE] `memcached` must be running for this test. For Mac OS: `brew install memcached && memcached`");
  final MemcachedClient client = new MemcachedClient(new InetSocketAddress("localhost", 11211));
  final boolean op = client.set("key", 120, "value").get(15, TimeUnit.SECONDS);
  if (!op)
    throw new AssertionError("Failed to set value");

  if (!"value".equals(client.get("key")))
    throw new AssertionError("Failed to get value");

  client.shutdown();
  TestUtil.checkSpan(new ComponentSpanCount("java-memcached", 2));
}
 
Example 2
Source File: SpymemcachedFactoryTest.java    From pippo with Apache License 2.0 5 votes vote down vote up
/**
 * Test of create method, of class SpymemcachedUtil.
 */
@Test
public void testCreate_PippoSettings() {
    System.out.println("create");
    MemcachedClient result = SpymemcachedFactory.create(application.getPippoSettings());
    assertNotNull(result);
    result.shutdown();
}
 
Example 3
Source File: SpymemcachedFactoryTest.java    From pippo with Apache License 2.0 5 votes vote down vote up
/**
 * Test of create method, of class SpymemcachedUtil.
 */
@Test
public void testCreate_5args() {
    System.out.println("create");
    ConnectionFactoryBuilder.Protocol protocol = ConnectionFactoryBuilder.Protocol.BINARY;
    String user = "";
    String pass = "";
    String[] authMechanisms = new String[]{"PLAIN"};
    MemcachedClient result = SpymemcachedFactory.create(HOST, protocol, user, pass, authMechanisms);
    assertNotNull(result);
    result.shutdown();
}
 
Example 4
Source File: MemcacheRestExample.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param args Command line arguments.
 * @throws Exception In case of error.
 */
public static void main(String[] args) throws Exception {
    MemcachedClient client = null;

    try (Ignite ignite = Ignition.start(MemcacheRestExampleNodeStartup.configuration())) {
        System.out.println();
        System.out.println(">>> Memcache REST example started.");

        IgniteCache<String, Object> cache = ignite.cache("default");

        client = startMemcachedClient(host, port);

        // Put string value to cache using Memcache binary protocol.
        if (client.add("strKey", 0, "strVal").get())
            System.out.println(">>> Successfully put string value using Memcache client.");

        // Check that string value is actually in cache using traditional
        // Ignite API and Memcache binary protocol.
        System.out.println(">>> Getting value for 'strKey' using Ignite cache API: " + cache.get("strKey"));
        System.out.println(">>> Getting value for 'strKey' using Memcache client: " + client.get("strKey"));

        // Remove string value from cache using Memcache binary protocol.
        if (client.delete("strKey").get())
            System.out.println(">>> Successfully removed string value using Memcache client.");

        // Check that cache is empty.
        System.out.println(">>> Current cache size: " + cache.size() + " (expected: 0).");

        // Put integer value to cache using Memcache binary protocol.
        if (client.add("intKey", 0, 100).get())
            System.out.println(">>> Successfully put integer value using Memcache client.");

        // Check that integer value is actually in cache using traditional
        // Ignite API and Memcache binary protocol.
        System.out.println(">>> Getting value for 'intKey' using Ignite cache API: " + cache.get("intKey"));
        System.out.println(">>> Getting value for 'intKey' using Memcache client: " + client.get("intKey"));

        // Remove string value from cache using Memcache binary protocol.
        if (client.delete("intKey").get())
            System.out.println(">>> Successfully removed integer value using Memcache client.");

        // Check that cache is empty.
        System.out.println(">>> Current cache size: " + cache.size() + " (expected: 0).");

        // Create atomic long and close it after test is done.
        try (IgniteAtomicLong l = ignite.atomicLong("atomicLong", 10, true)) {
            // Increment atomic long by 5 using Memcache client.
            if (client.incr("atomicLong", 5, 0) == 15)
                System.out.println(">>> Successfully incremented atomic long by 5.");

            // Increment atomic long using Ignite API and check that value is correct.
            System.out.println(">>> New atomic long value: " + l.incrementAndGet() + " (expected: 16).");

            // Decrement atomic long by 3 using Memcache client.
            if (client.decr("atomicLong", 3, 0) == 13)
                System.out.println(">>> Successfully decremented atomic long by 3.");

            // Decrement atomic long using Ignite API and check that value is correct.
            System.out.println(">>> New atomic long value: " + l.decrementAndGet() + " (expected: 12).");
        }
    }
    finally {
        if (client != null)
            client.shutdown();
    }
}
 
Example 5
Source File: CacheGrantManual.java    From oxAuth with MIT License 4 votes vote down vote up
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);
                }

                OperationStatus status = set.getStatus(); // block

                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();

}
 
Example 6
Source File: MemcachedCacheFactory.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@Override
protected void destroyConnectionClient(MemcachedClient connectionClient) {
	connectionClient.shutdown(10, TimeUnit.SECONDS);
}