Search in sources :

Example 26 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project hazelcast by hazelcast.

the class AdvancedNetworkingCommunicationIntegrationTest method testMemcacheConnectionToEndpoints.

@Test
public void testMemcacheConnectionToEndpoints() throws Exception {
    Config config = createCompleteMultiSocketConfig();
    JoinConfig join = config.getAdvancedNetworkConfig().getJoin();
    join.getMulticastConfig().setEnabled(false);
    join.getTcpIpConfig().setEnabled(false);
    HazelcastInstance hz = newHazelcastInstance(config);
    MemcachedClient client = null;
    try {
        client = getMemcachedClient(hz, MEMCACHE_PORT);
        client.get("whatever");
    } finally {
        shutdownQuietly(client);
    }
    testMemcacheCallFailsOnPort(hz, MEMBER_PORT);
    testMemcacheCallFailsOnPort(hz, CLIENT_PORT);
    testMemcacheCallFailsOnPort(hz, WAN1_PORT);
    testMemcacheCallFailsOnPort(hz, REST_PORT);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) JoinConfig(com.hazelcast.config.JoinConfig) MemcachedClient(net.spy.memcached.MemcachedClient) JoinConfig(com.hazelcast.config.JoinConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 27 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project hazelcast by hazelcast.

the class AdvancedNetworkingCommunicationIntegrationTest method getMemcachedClient.

private MemcachedClient getMemcachedClient(HazelcastInstance instance, int port) throws Exception {
    String hostName = instance.getCluster().getLocalMember().getSocketAddress().getHostName();
    InetSocketAddress address = new InetSocketAddress(hostName, port);
    ConnectionFactory factory = new ConnectionFactoryBuilder().setOpTimeout(3000).setDaemon(true).setFailureMode(FailureMode.Retry).build();
    return new MemcachedClient(factory, Collections.singletonList(address));
}
Also used : ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) ConnectionFactory(net.spy.memcached.ConnectionFactory) InetSocketAddress(java.net.InetSocketAddress) MemcachedClient(net.spy.memcached.MemcachedClient)

Example 28 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project hazelcast by hazelcast.

the class AdvancedNetworkingCommunicationIntegrationTest method testMemcacheCallFailsOnPort.

private void testMemcacheCallFailsOnPort(HazelcastInstance hz, int port) throws Exception {
    MemcachedClient client = null;
    try {
        client = getMemcachedClient(hz, port);
        try {
            client.get("whatever");
            fail("Memcache call should throw SocketException for port " + port);
        } catch (Exception ex) {
        // expected
        }
    } finally {
        shutdownQuietly(client);
    }
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) IOException(java.io.IOException) SocketException(java.net.SocketException)

Example 29 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 MB
    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.<ResourceHolder<MemcachedClientIF>>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) ResourceHolder(io.druid.collections.ResourceHolder) StupidResourceHolder(io.druid.collections.StupidResourceHolder)

Example 30 with MemcachedClient

use of net.spy.memcached.MemcachedClient in project hazelcast by hazelcast.

the class MemcacheTest method getMemcacheClient.

private MemcachedClient getMemcacheClient(HazelcastInstance instance) throws Exception {
    InetSocketAddress address = instance.getCluster().getLocalMember().getSocketAddress();
    ConnectionFactory factory = new ConnectionFactoryBuilder().setOpTimeout(60 * 60 * 60).setDaemon(true).setFailureMode(FailureMode.Retry).build();
    return new MemcachedClient(factory, Collections.singletonList(address));
}
Also used : ConnectionFactoryBuilder(net.spy.memcached.ConnectionFactoryBuilder) ConnectionFactory(net.spy.memcached.ConnectionFactory) InetSocketAddress(java.net.InetSocketAddress) 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