/**
   * Verifies the deletion of cache objects.
   *
   * @throws Exception
   */
  @Test
  public void testEvict() throws Exception {
    CouchbaseCache cache = new CouchbaseCache(cacheName, client);

    String key = "couchbase-cache-test";
    String value = "Hello World!";

    Boolean success = client.set(key, 0, value).get();
    assertTrue(success);

    cache.evict(key);
    Object result = client.get(key);
    assertNull(result);
  }
  /** Verifies set() with TTL value. */
  @Test
  public void testSetWithTtl() throws InterruptedException {
    CouchbaseCache cache = new CouchbaseCache(cacheName, client, 1); // cache for 1 second

    String key = "couchbase-cache-test";
    String value = "Hello World!";
    cache.put(key, value);

    // wait for TTL to expire (double time of TTL)
    Thread.sleep(2000);

    String stored = (String) client.get(key);
    assertNull(stored);
  }
  /** Verifies set() and get() of cache objects. */
  @Test
  public void testGetSet() {
    CouchbaseCache cache = new CouchbaseCache(cacheName, client);

    String key = "couchbase-cache-test";
    String value = "Hello World!";
    cache.put(key, value);

    String stored = (String) client.get(key);
    assertNotNull(stored);
    assertEquals(value, stored);

    ValueWrapper loaded = cache.get(key);
    assertEquals(value, loaded.get());
  }
  public static void main(String[] args) {

    System.out.println(
        "--------------------------------------------------------------------------");
    System.out.println("\tCouchbase Atomic Operations");
    System.out.println(
        "--------------------------------------------------------------------------");

    List<URI> uris = new LinkedList<URI>();

    uris.add(URI.create("http://127.0.0.1:8091/pools"));

    CouchbaseClient cb = null;
    try {
      cb = new CouchbaseClient(uris, "default", "");

      cb.delete("counter");

      System.out.println("Set Counter to 0");
      cb.incr("counter", 1, 0);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      System.out.println("Increment by 1");
      cb.incr("counter", 1);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      System.out.println("Increment by 10");
      cb.incr("counter", 10);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      cb.delete("counter");
      System.out.println("-- counter deleted --");

      System.out.println(
          "--------------------------------------------------------------------------");
      System.out.println("Using incr + initial values for counters ");
      cb.incr("counter", 1, 1);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      System.out.println("Decrease below 0");
      cb.decr("counter", 1000);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      System.out.println("set counter to -1, decr, then incr sets to max value");
      cb.incr("counter", -1, -1);
      cb.incr("counter", 1);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      System.out.println("incr on max value returns it to 0");
      cb.incr("counter", 1);
      System.out.println("Counter : " + cb.get("counter"));
      System.out.println("");

      cb.delete("counter");

      System.out.println("\n\n");

      cb.shutdown(10, TimeUnit.SECONDS);

    } catch (Exception e) {
      System.err.println("Error connecting to Couchbase: " + e.getMessage());
    }
  }
 public void close(@Disposes CouchbaseClient couchbaseClient) {
   couchbaseClient.shutdown();
 }