Search in sources :

Example 1 with PutResult

use of com.ibm.etcd.client.utils.RangeCache.PutResult in project etcd-java by IBM.

the class RangeCacheTest method testBasics.

@Test
public void testBasics() throws Exception {
    KvClient kvc = client.getKvClient();
    kvc.delete(bs("tmp/")).asPrefix().sync();
    try (RangeCache rc = new RangeCache(client, bs("tmp/"), false)) {
        PutResult pr = rc.put(bs("tmp/a"), bs("val1"), 0L);
        assertTrue(pr.succ());
        assertEquals(bs("val1"), pr.kv().getValue());
        rc.start().get(1L, TimeUnit.SECONDS);
        assertTrue(rc.delete(bs("tmp/a")));
        assertFalse(rc.delete(bs("tmp/c")));
        assertTrue(rc.put(bs("tmp/a"), bs("val1"), 0L).succ());
        assertEquals(bs("val1"), rc.get(bs("tmp/a")).getValue());
        assertEquals(bs("val1"), rc.getRemote(bs("tmp/a")).getValue());
        assertEquals(1, Iterators.size(rc.iterator()));
        Iterator<KeyValue> it = rc.iterator(), sit = rc.strongIterator();
        assertTrue(Iterators.elementsEqual(it, sit));
        KvClient directKv = directClient.getKvClient();
        directKv.put(bs("tmp/d"), bs("val2")).sync();
        Thread.sleep(80L);
        assertEquals(bs("val2"), rc.get(bs("tmp/d")).getValue());
        directKv.put(bs("tmp/d"), bs("valX")).sync();
        Thread.sleep(80L);
        assertEquals(bs("valX"), rc.get(bs("tmp/d")).getValue());
        directKv.delete(bs("tmp/d")).sync();
        Thread.sleep(80L);
        assertNull(rc.get(bs("tmp/d")));
    }
}
Also used : KeyValue(com.ibm.etcd.api.KeyValue) KvClient(com.ibm.etcd.client.kv.KvClient) PutResult(com.ibm.etcd.client.utils.RangeCache.PutResult) Test(org.junit.Test)

Aggregations

KeyValue (com.ibm.etcd.api.KeyValue)1 KvClient (com.ibm.etcd.client.kv.KvClient)1 PutResult (com.ibm.etcd.client.utils.RangeCache.PutResult)1 Test (org.junit.Test)1