Exemplo n.º 1
0
 public void flushAll() {
   try {
     memcachedClient.flushAll();
   } catch (Exception e) {
     throw new IllegalStateException(e.getMessage(), e);
   }
 }
Exemplo n.º 2
0
  public void testWeightedServers() throws Exception {
    // shutdown current client
    memcachedClient.shutdown();

    MemcachedClientBuilder builder = createWeightedBuilder();
    builder.getConfiguration().setStatisticsServer(true);
    memcachedClient = builder.build();
    memcachedClient.flushAll(5000);

    Map<InetSocketAddress, Map<String, String>> oldStats = memcachedClient.getStats();

    for (int i = 0; i < 100; i++) {
      assertTrue(memcachedClient.set(String.valueOf(i), 0, i));
    }
    for (int i = 0; i < 100; i++) {
      assertEquals(i, memcachedClient.get(String.valueOf(i)));
    }

    List<InetSocketAddress> addressList =
        AddrUtil.getAddresses(properties.getProperty("test.memcached.servers"));
    Map<InetSocketAddress, Map<String, String>> newStats = memcachedClient.getStats();
    for (InetSocketAddress address : addressList) {
      int oldSets = Integer.parseInt(oldStats.get(address).get("cmd_set"));
      int newSets = Integer.parseInt(newStats.get(address).get("cmd_set"));
      System.out.println("sets:" + (newSets - oldSets));
      int oldGets = Integer.parseInt(oldStats.get(address).get("cmd_get"));
      int newGets = Integer.parseInt(newStats.get(address).get("cmd_get"));
      System.out.println("gets:" + (newGets - oldGets));
    }
  }
Exemplo n.º 3
0
  protected void createClients()
      throws IOException, Exception, TimeoutException, InterruptedException, MemcachedException {
    properties = ResourcesUtils.getResourceAsProperties("test.properties");

    MemcachedClientBuilder builder = createBuilder();
    builder.getConfiguration().setStatisticsServer(true);
    memcachedClient = builder.build();
    memcachedClient.flushAll();
  }
Exemplo n.º 4
0
 public void testFlushAll() throws Exception {
   for (int i = 0; i < 50; i++) {
     assertTrue(memcachedClient.add(String.valueOf(i), 0, i));
   }
   List<String> keys = new ArrayList<String>();
   for (int i = 0; i < 100; i++) {
     keys.add(String.valueOf(i));
   }
   Map<String, Integer> result = memcachedClient.get(keys);
   assertEquals(50, result.size());
   for (int i = 0; i < 50; i++) {
     assertEquals((Integer) i, result.get(String.valueOf(i)));
   }
   memcachedClient.flushAll();
   result = memcachedClient.get(keys);
   assertTrue(result.isEmpty());
 }