@Test 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); Assert.assertEquals(et, we.getType()); Assert.assertEquals(ks, we.getState()); Assert.assertEquals("blah", we.getPath()); } } }
@Test public void testIntConversion() { // Ensure that we can convert all valid integers to EventTypes EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class); for(EventType et : allTypes) { Assert.assertEquals(et, EventType.fromInt( et.getIntValue() ) ); } }
@Override public void callBack(String target, EventType etype) throws Exception { System.out.println(target + " got event " + etype.name() + ", num=" + etype.getIntValue()); if (etype.getIntValue() == ZkConnect.DATACHANGED) System.out.println(zk.getObject(target)); zk.addWatch(target, this); }
@Override public void callBackR(String target, EventType etype) throws Exception { System.out.println(target + " got event " + etype.name() + ", num=" + etype.getIntValue()); // System.out.println(zk.getObject(target)); if (etype.getIntValue() == ZkConnect.NODECREATED) { zk.addRecursiveWatch(target, this, true); // if it's not deleted, // then anything under // here is added } else { if (etype.getIntValue() == ZkConnect.NODEDELETED) System.out.println("GOT THE DELETION"); } }
/** * Convert WatchedEvent to type that can be sent over network */ public WatcherEvent getWrapper() { return new WatcherEvent(eventType.getIntValue(), keeperState.getIntValue(), path); } }
/** * Convert WatchedEvent to type that can be sent over network */ public WatcherEvent getWrapper() { return new WatcherEvent(eventType.getIntValue(), keeperState.getIntValue(), path); } }
@Test public void testConvertingToEventWrapper() { WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah"); WatcherEvent wew = we.getWrapper(); Assert.assertEquals(EventType.NodeCreated.getIntValue(), wew.getType()); Assert.assertEquals(KeeperState.Expired.getIntValue(), wew.getState()); Assert.assertEquals("blah", wew.getPath()); } }
/** * Convert WatchedEvent to type that can be sent over network */ public WatcherEvent getWrapper() { return new WatcherEvent(eventType.getIntValue(), keeperState.getIntValue(), path); } }