Пример #1
0
 public void testIssue150() throws Exception {
   memcachedClient.set("a", 0, 1);
   try {
     memcachedClient.incr("a", 1);
     fail();
   } catch (MemcachedException e) {
     // assertEquals("cannot increment or decrement non-numeric value",e.getMessage());
   }
   memcachedClient.set("a", 0, "1");
   assertEquals(3, memcachedClient.incr("a", 2));
 }
Пример #2
0
 public long incr(String key, long delta, long initValue, int exp) {
   try {
     return memcachedClient.incr(key, delta, initValue, memcachedClient.getOpTimeout(), exp);
   } catch (Exception e) {
     throw new IllegalStateException(e.getMessage(), e);
   }
 }
Пример #3
0
 public long incr(String key, long delta) {
   try {
     return memcachedClient.incr(key, delta);
   } catch (Exception e) {
     throw new IllegalStateException(e.getMessage(), e);
   }
 }
Пример #4
0
 @Test
 public void incr() throws TimeoutException, InterruptedException, MemcachedException {
   Counter counter = memcachedClient.getCounter(key);
   System.out.println(counter.get());
   Assert.assertEquals(1L, memcachedClient.incr(key, 1L, 1L, 1000L, 60));
   System.out.println(memcachedClient.getCounter(key).get());
   Thread.sleep(20000);
   System.out.println(memcachedClient.getCounter(key).get());
   Thread.sleep(20000);
   System.out.println(memcachedClient.getCounter(key).get());
   Thread.sleep(10000);
   System.out.println(memcachedClient.getCounter(key).get());
   Thread.sleep(15000);
   System.out.println(memcachedClient.getCounter(key).get());
 }
Пример #5
0
  public void testIncr() throws Exception {
    assertEquals(0, memcachedClient.incr("a", 5));
    assertTrue(memcachedClient.set("a", 0, "1"));
    assertEquals(6, memcachedClient.incr("a", 5));
    assertEquals(10, memcachedClient.incr("a", 4));

    // test incr with initValue
    memcachedClient.delete("a");
    assertEquals(1, memcachedClient.incr("a", 5, 1));
    assertEquals(6, memcachedClient.incr("a", 5));
    assertEquals(10, memcachedClient.incr("a", 4));

    // test incr with initValue and expire time
    memcachedClient.delete("a");
    assertEquals(1, memcachedClient.incr("a", 5, 1, 1000, 1));
    Thread.sleep(2000);
    assertNull(memcachedClient.get("a"));

    // key is chinese
    assertEquals(1, memcachedClient.incr("娴��", 5, 1, 1000, 0));
    assertEquals(6, memcachedClient.incr("娴��", 5));
    assertEquals(10, memcachedClient.incr("娴��", 4));

    // blank key
    new BlankKeyChecker() {
      @Override
      public void call() throws Exception {
        memcachedClient.incr("", 0, 1);
      }
    }.check();
    // null key
    new BlankKeyChecker() {
      @Override
      public void call() throws Exception {
        memcachedClient.incr((String) null, 0, 1);
      }
    }.check();

    // invalid key
    new InValidKeyChecker() {
      @Override
      public void call() throws Exception {
        memcachedClient.incr("test\r\n", 0, 1);
      }
    }.check();
    new InValidKeyChecker() {
      @Override
      public void call() throws Exception {
        memcachedClient.incr("test test2", 0, 1);
      }
    }.check();

    // key is too long
    new TooLongKeyChecker(memcachedClient) {
      @Override
      public void call() throws Exception {
        int keyLength = memcachedClient.getProtocol() == Protocol.Text ? 256 : 65536;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < keyLength; i++) {
          sb.append(i);
        }
        memcachedClient.incr(sb.toString(), 0, 1);
      }
    }.check();
  }