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