memcachedClient.set("name", 0, "dennis");
assertEquals("dennis", memcachedClient.get("name"));
long writeMessageCount = memcachedClient.getConnector().getStatistics()
.getWriteMessageCount();
CountDownLatch latch = new CountDownLatch(1);
Command errorCommand = null;
if (memcachedClient.getProtocol() == Protocol.Text) {
errorCommand = new MockEncodeTimeoutTextGetOneCommand("name",
"name".getBytes(), CommandType.GET_ONE, latch, 1000);
} else {
errorCommand = new MockEncodeTimeoutBinaryGetCommand("name", "name"
.getBytes(), CommandType.GET_ONE, latch, OpCode.GET, false,
1000);
}
memcachedClient.getConnector().send(errorCommand);
// Force write thread to encode command
errorCommand.setIoBuffer(null);
// wait 100 milliseconds,the operation will be timeout
if (!latch.await(100, TimeUnit.MILLISECONDS)) {
errorCommand.cancel();
}
Thread.sleep(1000);
// It is not written to channel,because it is canceled.
assertEquals(writeMessageCount, memcachedClient.getConnector()
.getStatistics().getWriteMessageCount());