}
@Test
public void testMemcacheSimple() throws IOException, ExecutionException, InterruptedException {
final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
MemcachedClient client = getMemcacheClient(instance);
try {
for (int i = 0; i < 100; i++) {
final OperationFuture<Boolean> future = client.set(String.valueOf(i), 0, i);
assertEquals(Boolean.TRUE, future.get());
}
for (int i = 0; i < 100; i++) {
assertEquals(i, client.get(String.valueOf(i)));
}
for (int i = 0; i < 100; i++) {
final OperationFuture<Boolean> future = client.add(String.valueOf(i), 0, i * 100);
assertEquals(Boolean.FALSE, future.get());
}
for (int i = 0; i < 100; i++) {
assertEquals(i, client.get(String.valueOf(i)));
}
for (int i = 100; i < 200; i++) {
final OperationFuture<Boolean> future = client.add(String.valueOf(i), 0, i);
assertEquals(Boolean.TRUE, future.get());
}
for (int i = 0; i < 200; i++) {
assertEquals(i, client.get(String.valueOf(i)));
}
for (int i = 0; i < 200; i++) {
final OperationFuture<Boolean> future = client.replace(String.valueOf(i), 0, i * 10);
assertEquals(Boolean.TRUE, future.get());
}
for (int i = 0; i < 200; i++) {
assertEquals(i * 10, client.get(String.valueOf(i)));
}
for (int i = 200; i < 400; i++) {
final OperationFuture<Boolean> future = client.replace(String.valueOf(i), 0, i);
assertEquals(Boolean.FALSE, future.get());
}
for (int i = 200; i < 400; i++) {
assertEquals(null, client.get(String.valueOf(i)));
}
for (int i = 100; i < 200; i++) {
final OperationFuture<Boolean> future = client.delete(String.valueOf(i));
assertEquals(Boolean.TRUE, future.get());
}
for (int i = 100; i < 200; i++) {
assertEquals(null, client.get(String.valueOf(100)));
}
for (int i = 100; i < 200; i++) {
final OperationFuture<Boolean> future = client.delete(String.valueOf(i));
assertEquals(Boolean.FALSE, future.get());
}
final LinkedList<String> keys = new LinkedList<String>();
for (int i = 0; i < 100; i++) {
keys.add(String.valueOf(i));
}
final Map<String, Object> bulk = client.getBulk(keys);
for (int i = 0; i < 100; i++) {
assertEquals(i * 10, bulk.get(String.valueOf(i)));
}
// STATS
final Map<String, String> stats = client.getStats().get(instance.getCluster().getLocalMember().getInetSocketAddress());
assertEquals("700", stats.get("cmd_set"));
assertEquals("1000", stats.get("cmd_get"));
assertEquals("700", stats.get("get_hits"));
assertEquals("300", stats.get("get_misses"));
assertEquals("100", stats.get("delete_hits"));
assertEquals("100", stats.get("delete_misses"));
} finally {
client.shutdown();
}
}