Search in sources :

Example 1 with WatchCreateException

use of com.ibm.etcd.client.watch.WatchCreateException in project etcd-java by IBM.

the class WatchTest method testCreateFail.

@Test
public void testCreateFail() throws Exception {
    KvStoreClient client = EtcdClient.forEndpoint("localhost", 2379).withPlainText().build();
    try {
        KvClient kvc = client.getKvClient();
        // range end before start => should fail
        Watch watch2 = kvc.watch(ByteString.copyFromUtf8("/watchtest2")).rangeEnd(ByteString.copyFromUtf8("/watchtest1")).startRevision(-5000L).start((ListenerObserver<WatchUpdate>) (c, v, t) -> {
        });
        try {
            watch2.get(1000, TimeUnit.SECONDS);
            fail("watch future should fail");
        } catch (ExecutionException e) {
            System.out.println("watch creation failed with exception: " + e);
            assertTrue(e.getCause() instanceof WatchCreateException);
        }
    } finally {
        client.close();
    }
}
Also used : AfterClass(org.junit.AfterClass) WatchUpdate(com.ibm.etcd.client.kv.WatchUpdate) BeforeClass(org.junit.BeforeClass) Watch(com.ibm.etcd.client.kv.KvClient.Watch) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) KvClient(com.ibm.etcd.client.kv.KvClient) BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) WatchIterator(com.ibm.etcd.client.kv.KvClient.WatchIterator) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) AtomicReference(java.util.concurrent.atomic.AtomicReference) WatchCreateException(com.ibm.etcd.client.watch.WatchCreateException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) ByteString(com.google.protobuf.ByteString) StreamObserver(io.grpc.stub.StreamObserver) Map(java.util.Map) Phaser(java.util.concurrent.Phaser) EventType(com.ibm.etcd.api.Event.EventType) KvTest.bs(com.ibm.etcd.client.KvTest.bs) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) PutResponse(com.ibm.etcd.api.PutResponse) KvTest.t(com.ibm.etcd.client.KvTest.t) Watch(com.ibm.etcd.client.kv.KvClient.Watch) WatchUpdate(com.ibm.etcd.client.kv.WatchUpdate) KvClient(com.ibm.etcd.client.kv.KvClient) ExecutionException(java.util.concurrent.ExecutionException) WatchCreateException(com.ibm.etcd.client.watch.WatchCreateException) Test(org.junit.Test)

Aggregations

ByteString (com.google.protobuf.ByteString)1 EventType (com.ibm.etcd.api.Event.EventType)1 PutResponse (com.ibm.etcd.api.PutResponse)1 KvTest.bs (com.ibm.etcd.client.KvTest.bs)1 KvTest.t (com.ibm.etcd.client.KvTest.t)1 KvClient (com.ibm.etcd.client.kv.KvClient)1 Watch (com.ibm.etcd.client.kv.KvClient.Watch)1 WatchIterator (com.ibm.etcd.client.kv.KvClient.WatchIterator)1 WatchUpdate (com.ibm.etcd.client.kv.WatchUpdate)1 WatchCreateException (com.ibm.etcd.client.watch.WatchCreateException)1 StreamObserver (io.grpc.stub.StreamObserver)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Phaser (java.util.concurrent.Phaser)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1