Exemplo n.º 1
0
 @Test
 public void getPutStaticValue() {
   String bucket = "bucket";
   String key = "key";
   String value = "foobar";
   HashMapCacheClient cache = new HashMapCacheClient();
   cache.addBucket(bucket);
   cache.put(bucket, key, value.getBytes());
   assertEquals("get value from cache", value, new String(cache.get(bucket, key)));
   List<Double> ratios = Arrays.asList(0.0d, 1.0d);
   CacheWorker worker =
       new CacheWorker(
           cache, "gpsvrun", "getPutStaticValue", bucket, 200, new String[] {key}, null, ratios);
   worker.run();
   CacheStats stats = worker.getStats();
   assertEquals("puts", 0, stats.getNumPuts());
   assertEquals("gets", 200, stats.getNumGets());
   assertEquals("hits", 200, stats.getNumHits());
 }
Exemplo n.º 2
0
  @Test
  public void getPutCount() {
    String bucket = "bucket";
    HashMapCacheClient cache = new HashMapCacheClient();
    cache.addBucket(bucket);
    KeyValueHelper keyValueHelper = new KeyValueHelper();
    keyValueHelper.setKeyGenerator(new DefaultKeyGenerator());
    String[] keys = keyValueHelper.makeKeys(10, 64);
    List<byte[]> values = keyValueHelper.makeValues(keys, 1024);

    List<Double> ratios = Arrays.asList(1.0d, 5.0d);
    CacheWorker worker =
        new CacheWorker(cache, "gpc1", "getPutCount", bucket, 600, keys, values, ratios);
    worker.run();
    CacheStats stats = worker.getStats();

    assertTrue("puts", ChooserTest.withinPercent(stats.getNumPuts(), 100, 0.10));
    assertTrue("gets", ChooserTest.withinPercent(stats.getNumGets(), 500, .10));
    assertEquals("sum", 600, stats.getNumPuts() + stats.getNumGets());
  }