public void tearDown() throws Exception {
memcachedClient.shutdown();
}
public void testCounter() throws Exception {
Counter counter = memcachedClient.getCounter("a");
Assert.assertEquals(0, counter.get());
Assert.assertEquals(0, counter.get());
Assert.assertEquals(1, counter.incrementAndGet());
Assert.assertEquals(2, counter.incrementAndGet());
Assert.assertEquals(3, counter.incrementAndGet());
Assert.assertEquals(2, counter.decrementAndGet());
Assert.assertEquals(1, counter.decrementAndGet());
Assert.assertEquals(0, counter.decrementAndGet());
Assert.assertEquals(0, counter.decrementAndGet());
Assert.assertEquals(4, counter.addAndGet(4));
Assert.assertEquals(7, counter.addAndGet(3));
Assert.assertEquals(0, counter.addAndGet(-7));
counter.set(1000);
Assert.assertEquals(1000, counter.get());
Assert.assertEquals(1001, counter.incrementAndGet());
counter = memcachedClient.getCounter("b", 100);
Assert.assertEquals(101, counter.incrementAndGet());
Assert.assertEquals(102, counter.incrementAndGet());
Assert.assertEquals(101, counter.decrementAndGet());
// test issue 74
counter = memcachedClient.getCounter("issue74", 0);
for (int i = 0; i < 100; i++) {
Assert.assertEquals(i + 1, counter.incrementAndGet());
}
for (int i = 0; i < 100; i++) {
counter.decrementAndGet();
}
Assert.assertEquals(0, counter.get());
}