Examples of WatchedEvent


Examples of org.apache.zookeeper.WatchedEvent

             * when the initial (or previously failed) connection cannot be re-established. This needs to be run through the retry policy
             * and callbacks need to get invoked, etc.
             */
            if ( e instanceof CuratorConnectionLossException )
            {
                WatchedEvent watchedEvent = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState.Disconnected, null);
                CuratorEvent event = new CuratorEventImpl(this, CuratorEventType.WATCHED, KeeperException.Code.CONNECTIONLOSS.intValue(), null, null, operationAndData.getContext(), null, null, null, watchedEvent, null);
                if ( checkBackgroundRetry(operationAndData, event) )
                {
                    queueOperation(operationAndData);
                }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

                zk.delete(name, stat.getVersion(), vcb, null);
            }

            for (int i = 0; i < names.length; i++) {
                String name = names[i];
                WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS);
                assertEquals(name, event.getPath());
                assertEquals(Event.EventType.NodeDataChanged, event.getType());
                assertEquals(Event.KeeperState.SyncConnected, event.getState());
                event = watcher.events.poll(10, TimeUnit.SECONDS);
                assertEquals(name, event.getPath());
                assertEquals(Event.EventType.NodeDeleted, event.getType());
                assertEquals(Event.KeeperState.SyncConnected, event.getState());
            }
        } finally {
            if (zk != null) {
                zk.close();
            }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

        assertTrue(localWatcher.events.isEmpty());
        zk.setData("/watchtest/child", new byte[1], -1);
        zk.create("/watchtest/child2", new byte[0], Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);

        WatchedEvent e = localWatcher.events.poll(10, TimeUnit.SECONDS);
        if (!ClientCnxn.disableAutoWatchReset) {
            assertEquals(e.getPath(), EventType.NodeDataChanged, e.getType());
            assertEquals("/watchtest/child", e.getPath());
        } else {
            assertNull("unexpected event", e);
        }

        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
        if (!ClientCnxn.disableAutoWatchReset) {
            // The create will trigger the get children and the exist
            // watches
            assertEquals(EventType.NodeCreated, e.getType());
            assertEquals("/watchtest/child2", e.getPath());
        } else {
            assertNull("unexpected event", e);
        }

        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
        if (!ClientCnxn.disableAutoWatchReset) {
            assertEquals(EventType.NodeChildrenChanged, e.getType());
            assertEquals("/watchtest", e.getPath());
        } else {
            assertNull("unexpected event", e);
        }

        // Make sure PINGs don't screw us up!
        Thread.sleep(4000);

        assertTrue(localWatcher.events.isEmpty()); // ensure no late arrivals
        stopServer();
        globalWatcher.waitForDisconnected(3000);
        try {
        try {
            localWatcher.waitForDisconnected(500);
            if (!isGlobal && !ClientCnxn.disableAutoWatchReset) {
                fail("Got an event when I shouldn't have");
            }
        } catch(TimeoutException toe) {
            if (ClientCnxn.disableAutoWatchReset) {
                fail("Didn't get an event when I should have");
            }
            // Else what we are expecting since there are no outstanding watches
        }
        } catch (Exception e1) {
            LOG.error("bad", e1);
            throw new RuntimeException(e1);
        }
        startServer();
        globalWatcher.waitForConnected(3000);

        if (isGlobal) {
            zk.getChildren("/watchtest", true);
            zk.getData("/watchtest/child", true, new Stat());
            zk.exists("/watchtest/child2", true);
        } else {
            zk.getChildren("/watchtest", localWatcher);
            zk.getData("/watchtest/child", localWatcher, new Stat());
            zk.exists("/watchtest/child2", localWatcher);
        }

        // Do trigger an event to make sure that we do not get
        // it later
        zk.delete("/watchtest/child2", -1);

        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
        assertEquals(EventType.NodeDeleted, e.getType());
        assertEquals("/watchtest/child2", e.getPath());

        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
        assertEquals(EventType.NodeChildrenChanged, e.getType());
        assertEquals("/watchtest", e.getPath());

        assertTrue(localWatcher.events.isEmpty());

        stopServer();
        globalWatcher.waitForDisconnected(3000);
        localWatcher.waitForDisconnected(500);
        startServer();
        globalWatcher.waitForConnected(3000);
        if (!isGlobal && !ClientCnxn.disableAutoWatchReset) {
            localWatcher.waitForConnected(500);
        }

        zk.delete("/watchtest/child", -1);
        zk.delete("/watchtest", -1);

        e = localWatcher.events.poll(10, TimeUnit.SECONDS);
        if (!ClientCnxn.disableAutoWatchReset) {
            assertEquals(EventType.NodeDeleted, e.getType());
            assertEquals("/watchtest/child", e.getPath());
        } else {
            assertNull("unexpected event", e);
        }

        // Make sure nothing is straggling!
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

            for (int i = 0; i < watchers.length; i++) {
                zk.setData("/foo-" + i, ("foodata2-" + i).getBytes(), -1);
                zk.setData("/foo-" + i, ("foodata3-" + i).getBytes(), -1);
            }
            for (int i = 0; i < watchers.length; i++) {
                WatchedEvent event =
                    watchers[i].events.poll(10, TimeUnit.SECONDS);
                assertEquals("/foo-" + i, event.getPath());
                assertEquals(EventType.NodeDataChanged, event.getType());
                assertEquals(KeeperState.SyncConnected, event.getState());
               
                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                assertEquals(0, watchers[i].events.size());
            }
           
            //
            // test get/exists with single set of watchers
            //  get/exists together
            //
            for (int i = 0; i < watchers.length; i++) {
                assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
                assertNotNull(zk.exists("/foo-" + i, watchers[i]));
            }
            // trigger the watches
            for (int i = 0; i < watchers.length; i++) {
                zk.setData("/foo-" + i, ("foodata4-" + i).getBytes(), -1);
                zk.setData("/foo-" + i, ("foodata5-" + i).getBytes(), -1);
            }
            for (int i = 0; i < watchers.length; i++) {
                WatchedEvent event =
                    watchers[i].events.poll(10, TimeUnit.SECONDS);
                assertEquals("/foo-" + i, event.getPath());
                assertEquals(EventType.NodeDataChanged, event.getType());
                assertEquals(KeeperState.SyncConnected, event.getState());
               
                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                assertEquals(0, watchers[i].events.size());
            }
           
            //
            // test get/exists with two sets of watchers
            //
            for (int i = 0; i < watchers.length; i++) {
                assertNotNull(zk.getData("/foo-" + i, watchers[i], stat));
                assertNotNull(zk.exists("/foo-" + i, watchers2[i]));
            }
            // trigger the watches
            for (int i = 0; i < watchers.length; i++) {
                zk.setData("/foo-" + i, ("foodata6-" + i).getBytes(), -1);
                zk.setData("/foo-" + i, ("foodata7-" + i).getBytes(), -1);
            }
            for (int i = 0; i < watchers.length; i++) {
                WatchedEvent event =
                    watchers[i].events.poll(10, TimeUnit.SECONDS);
                assertEquals("/foo-" + i, event.getPath());
                assertEquals(EventType.NodeDataChanged, event.getType());
                assertEquals(KeeperState.SyncConnected, event.getState());
               
                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                assertEquals(0, watchers[i].events.size());

                // watchers2
                WatchedEvent event2 =
                    watchers2[i].events.poll(10, TimeUnit.SECONDS);
                assertEquals("/foo-" + i, event2.getPath());
                assertEquals(EventType.NodeDataChanged, event2.getType());
                assertEquals(KeeperState.SyncConnected, event2.getState());
               
                // small chance that an unexpected message was delivered
                //  after this check, but we would catch that next time
                //  we check events
                assertEquals(0, watchers2[i].events.size());
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

            zk.create("/frog", "hi".getBytes(), Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
            // the first poll is just a session delivery
            LOG.info("Comment: checking for events length "
                     + watcher.events.size());
            WatchedEvent event = watcher.events.poll(10, TimeUnit.SECONDS);
            assertEquals("/frog", event.getPath());
            assertEquals(EventType.NodeCreated, event.getType());
            assertEquals(KeeperState.SyncConnected, event.getState());
            // Test child watch and create with sequence
            zk.getChildren("/ben", true);
            for (int i = 0; i < 10; i++) {
                zk.create("/ben/" + i + "-", Integer.toString(i).getBytes(),
                        Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
            }
            children = zk.getChildren("/ben", false);
            Collections.sort(children);
            assertEquals(10, children.size());
            for (int i = 0; i < 10; i++) {
                final String name = children.get(i);
                assertTrue("starts with -", name.startsWith(i + "-"));
                byte b[];
                if (withWatcherObj) {
                    b = zk.getData("/ben/" + name, watcher, stat);
                } else {
                    b = zk.getData("/ben/" + name, true, stat);
                }
                assertEquals(Integer.toString(i), new String(b));
                zk.setData("/ben/" + name, "new".getBytes(), stat.getVersion());
                if (withWatcherObj) {
                    stat = zk.exists("/ben/" + name, watcher);
                } else {
                stat = zk.exists("/ben/" + name, true);
                }
                zk.delete("/ben/" + name, stat.getVersion());
            }
            event = watcher.events.poll(10, TimeUnit.SECONDS);
            assertEquals("/ben", event.getPath());
            assertEquals(EventType.NodeChildrenChanged, event.getType());
            assertEquals(KeeperState.SyncConnected, event.getState());
            for (int i = 0; i < 10; i++) {
                event = watcher.events.poll(10, TimeUnit.SECONDS);
                final String name = children.get(i);
                assertEquals("/ben/" + name, event.getPath());
                assertEquals(EventType.NodeDataChanged, event.getType());
                assertEquals(KeeperState.SyncConnected, event.getState());
                event = watcher.events.poll(10, TimeUnit.SECONDS);
                assertEquals("/ben/" + name, event.getPath());
                assertEquals(EventType.NodeDeleted, event.getType());
                assertEquals(KeeperState.SyncConnected, event.getState());
            }
            zk.create("/good\u0001path", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            //try {
            //    zk.create("/bad\u0000path", "".getBytes(), null, CreateMode.PERSISTENT);
            //    fail("created an invalid path");
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

            } catch (InterruptedException e) {
                assertTrue("interruption unexpected", false);
            }
        }
        public void verify(List<EventType> expected) throws InterruptedException{
            WatchedEvent event;
            int count = 0;
            while (count < expected.size()
                    && (event = events.poll(30, TimeUnit.SECONDS)) != null)
            {
                assertEquals(expected.get(count), event.getType());
                count++;
            }
            assertEquals(expected.size(), count);
            events.clear();
        }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

        // EventWatch is a simple, immutable type, so all we need to do
       // is make sure we can create all possible combinations of values.

        EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
       EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
       WatchedEvent we;

        for(EventType et : allTypes) {
           for(KeeperState ks : allStates) {
               we = new WatchedEvent(et, ks, "blah");
               assertEquals(et, we.getType());
               assertEquals(ks, we.getState());
               assertEquals("blah", we.getPath());
           }
           
        }
    }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

    public void testCreatingWatchedEventFromWrapper() {
        // Make sure we can handle any type of correct wrapper

        EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
       EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
       WatchedEvent we;
       WatcherEvent wep;

        for(EventType et : allTypes) {
           for(KeeperState ks : allStates) {
               wep = new WatcherEvent(et.getIntValue(), ks.getIntValue(), "blah");
               we = new WatchedEvent(wep);
               assertEquals(et, we.getType());
               assertEquals(ks, we.getState());
               assertEquals("blah", we.getPath());
           }
        }
    }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

    public void testCreatingWatchedEventFromInvalidWrapper() {
        // Make sure we can't convert from an invalid wrapper

       try {
           WatcherEvent wep = new WatcherEvent(-2342, -252352, "foo");
           WatchedEvent we = new WatchedEvent(wep);
           fail("Was able to create WatchedEvent from bad wrapper");
       } catch (RuntimeException re) {
           // we're good
       }
    }
View Full Code Here

Examples of org.apache.zookeeper.WatchedEvent

       }
    }

   @Test
   public void testConvertingToEventWrapper() {
       WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
       WatcherEvent wew = we.getWrapper();
      
       assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
       assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
       assertEquals("blah", wew.getPath());
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.