예제 #1
0
 public void testSetLoggingLevelVerbosity() throws Exception {
   if (memcachedClient.getProtocol() == Protocol.Text
       || memcachedClient.getProtocol() == Protocol.Binary) {
     memcachedClient.setLoggingLevelVerbosity(
         AddrUtil.getAddresses(properties.getProperty("test.memcached.servers")).get(0), 2);
     memcachedClient.setLoggingLevelVerbosityWithNoReply(
         AddrUtil.getAddresses(properties.getProperty("test.memcached.servers")).get(0), 3);
     memcachedClient.setLoggingLevelVerbosityWithNoReply(
         AddrUtil.getAddresses(properties.getProperty("test.memcached.servers")).get(0), 0);
   } else {
     // do nothing,binary protocol doesn't have verbosity protocol.
   }
 }
예제 #2
0
  public void _testOperationEncodeTimeout() throws Exception {
    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());
    // It works
    assertEquals("dennis", memcachedClient.get("name"));
  }
예제 #3
0
  public void testTouch() throws Exception {
    this.memcachedClient.set("x", 1, 0);
    assertEquals(0, this.memcachedClient.get("x"));
    assertTrue(this.memcachedClient.touch("x", 1));
    assertEquals(0, this.memcachedClient.get("x"));
    assertTrue(this.memcachedClient.touch("x", 1));
    Thread.sleep(1100);
    assertNull(this.memcachedClient.get("x"));
    if (memcachedClient.getProtocol() == Protocol.Binary) {
      this.memcachedClient.set("x", 1, 0);
      assertEquals(0, this.memcachedClient.getAndTouch("x", 1));
    }

    // touch not exists
    assertFalse(memcachedClient.touch("not_exists", 0));
  }
예제 #4
0
 public void testOperationDecodeTimeOut() throws Exception {
   memcachedClient.set("name", 0, "dennis");
   assertEquals("dennis", memcachedClient.get("name"));
   CountDownLatch latch = new CountDownLatch(1);
   Command errorCommand = null;
   if (memcachedClient.getProtocol() == Protocol.Text) {
     errorCommand =
         new MockDecodeTimeoutTextGetOneCommand(
             "name", "name".getBytes(), CommandType.GET_ONE, latch, 1000);
   } else {
     errorCommand =
         new MockDecodeTimeoutBinaryGetOneCommand(
             "name", "name".getBytes(), CommandType.GET_ONE, latch, OpCode.GET, false, 1000);
   }
   memcachedClient.getConnector().send(errorCommand);
   // wait 100 milliseconds,the operation will be timeout
   latch.await(100, TimeUnit.MILLISECONDS);
   assertNull(errorCommand.getResult());
   Thread.sleep(1000);
   // It works.
   assertNotNull(errorCommand.getResult());
   assertEquals("dennis", memcachedClient.get("name"));
 }
예제 #5
0
 public void testAutoReconnect() throws Exception {
   final String key = "name";
   memcachedClient.set(key, 0, "dennis");
   assertEquals("dennis", memcachedClient.get(key));
   CountDownLatch latch = new CountDownLatch(1);
   int currentServerCount = memcachedClient.getAvaliableServers().size();
   MockErrorCommand errorCommand = null;
   if (memcachedClient.getProtocol() == Protocol.Text) {
     errorCommand =
         new MockErrorTextGetOneCommand(key, key.getBytes(), CommandType.GET_ONE, latch);
   } else {
     errorCommand =
         new MockErrorBinaryGetOneCommand(
             key, key.getBytes(), CommandType.GET_ONE, latch, OpCode.GET, false);
   }
   memcachedClient.getConnector().send((Command) errorCommand);
   latch.await(MemcachedClient.DEFAULT_OP_TIMEOUT, TimeUnit.MILLISECONDS);
   assertTrue(errorCommand.isDecoded());
   // wait for reconnecting
   Thread.sleep(2000 * 3);
   assertEquals(currentServerCount, memcachedClient.getAvaliableServers().size());
   // It works
   assertEquals("dennis", memcachedClient.get(key));
 }