Repository: zookeeper Updated Branches: refs/heads/master b1fd480b2 -> a5ffb4c8d
ZOOKEEPER-3207: Removing the unexpected WatchManager.java introduced by mistake during maven migration Author: Fangmin Lyu <[email protected]> Reviewers: [email protected] Closes #729 from lvfangmin/ZOOKEEPER-3207 Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/a5ffb4c8 Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/a5ffb4c8 Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/a5ffb4c8 Branch: refs/heads/master Commit: a5ffb4c8dd49d1d6b03904d457eea62a3009c91a Parents: b1fd480 Author: Fangmin Lyu <[email protected]> Authored: Tue Dec 11 14:03:37 2018 +0100 Committer: Andor Molnar <[email protected]> Committed: Tue Dec 11 14:03:37 2018 +0100 ---------------------------------------------------------------------- .../apache/zookeeper/server/WatchManager.java | 266 ------------------- .../zookeeper/server/WatchesPathReport.java | 83 ------ .../apache/zookeeper/server/WatchesReport.java | 83 ------ .../apache/zookeeper/server/WatchesSummary.java | 98 ------- .../zookeeper/server/WatchesPathReportTest.java | 60 ----- .../zookeeper/server/WatchesReportTest.java | 60 ----- .../zookeeper/server/WatchesSummaryTest.java | 42 --- 7 files changed, 692 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchManager.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchManager.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchManager.java deleted file mode 100644 index 076f645..0000000 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchManager.java +++ /dev/null @@ -1,266 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server; - -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.Watcher.Event.EventType; -import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class manages watches. It allows watches to be associated with a string - * and removes watchers and their watches in addition to managing triggers. - */ -class WatchManager { - private static final Logger LOG = LoggerFactory.getLogger(WatchManager.class); - - private final Map<String, Set<Watcher>> watchTable = - new HashMap<String, Set<Watcher>>(); - - private final Map<Watcher, Set<String>> watch2Paths = - new HashMap<Watcher, Set<String>>(); - - synchronized int size(){ - int result = 0; - for(Set<Watcher> watches : watchTable.values()) { - result += watches.size(); - } - return result; - } - - synchronized void addWatch(String path, Watcher watcher) { - Set<Watcher> list = watchTable.get(path); - if (list == null) { - // don't waste memory if there are few watches on a node - // rehash when the 4th entry is added, doubling size thereafter - // seems like a good compromise - list = new HashSet<Watcher>(4); - watchTable.put(path, list); - } - list.add(watcher); - - Set<String> paths = watch2Paths.get(watcher); - if (paths == null) { - // cnxns typically have many watches, so use default cap here - paths = new HashSet<String>(); - watch2Paths.put(watcher, paths); - } - paths.add(path); - } - - synchronized void removeWatcher(Watcher watcher) { - Set<String> paths = watch2Paths.remove(watcher); - if (paths == null) { - return; - } - for (String p : paths) { - Set<Watcher> list = watchTable.get(p); - if (list != null) { - list.remove(watcher); - if (list.size() == 0) { - watchTable.remove(p); - } - } - } - } - - Set<Watcher> triggerWatch(String path, EventType type) { - return triggerWatch(path, type, null); - } - - Set<Watcher> triggerWatch(String path, EventType type, Set<Watcher> supress) { - WatchedEvent e = new WatchedEvent(type, - KeeperState.SyncConnected, path); - Set<Watcher> watchers; - synchronized (this) { - watchers = watchTable.remove(path); - if (watchers == null || watchers.isEmpty()) { - if (LOG.isTraceEnabled()) { - ZooTrace.logTraceMessage(LOG, - ZooTrace.EVENT_DELIVERY_TRACE_MASK, - "No watchers for " + path); - } - return null; - } - for (Watcher w : watchers) { - Set<String> paths = watch2Paths.get(w); - if (paths != null) { - paths.remove(path); - } - } - } - for (Watcher w : watchers) { - if (supress != null && supress.contains(w)) { - continue; - } - w.process(e); - } - return watchers; - } - - /** - * Brief description of this object. - */ - @Override - public synchronized String toString() { - StringBuilder sb = new StringBuilder(); - - sb.append(watch2Paths.size()).append(" connections watching ") - .append(watchTable.size()).append(" paths\n"); - - int total = 0; - for (Set<String> paths : watch2Paths.values()) { - total += paths.size(); - } - sb.append("Total watches:").append(total); - - return sb.toString(); - } - - /** - * String representation of watches. Warning, may be large! - * @param byPath iff true output watches by paths, otw output - * watches by connection - * @return string representation of watches - */ - synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) { - if (byPath) { - for (Entry<String, Set<Watcher>> e : watchTable.entrySet()) { - pwriter.println(e.getKey()); - for (Watcher w : e.getValue()) { - pwriter.print("\t0x"); - pwriter.print(Long.toHexString(((ServerCnxn)w).getSessionId())); - pwriter.print("\n"); - } - } - } else { - for (Entry<Watcher, Set<String>> e : watch2Paths.entrySet()) { - pwriter.print("0x"); - pwriter.println(Long.toHexString(((ServerCnxn)e.getKey()).getSessionId())); - for (String path : e.getValue()) { - pwriter.print("\t"); - pwriter.println(path); - } - } - } - } - - /** - * Checks the specified watcher exists for the given path - * - * @param path - * znode path - * @param watcher - * watcher object reference - * @return true if the watcher exists, false otherwise - */ - synchronized boolean containsWatcher(String path, Watcher watcher) { - Set<String> paths = watch2Paths.get(watcher); - if (paths == null || !paths.contains(path)) { - return false; - } - return true; - } - - /** - * Removes the specified watcher for the given path - * - * @param path - * znode path - * @param watcher - * watcher object reference - * @return true if the watcher successfully removed, false otherwise - */ - synchronized boolean removeWatcher(String path, Watcher watcher) { - Set<String> paths = watch2Paths.get(watcher); - if (paths == null || !paths.remove(path)) { - return false; - } - - Set<Watcher> list = watchTable.get(path); - if (list == null || !list.remove(watcher)) { - return false; - } - - if (list.size() == 0) { - watchTable.remove(path); - } - - return true; - } - - /** - * Returns a watch report. - * - * @return watch report - * @see WatchesReport - */ - synchronized WatchesReport getWatches() { - Map<Long, Set<String>> id2paths = new HashMap<Long, Set<String>>(); - for (Entry<Watcher, Set<String>> e: watch2Paths.entrySet()) { - Long id = ((ServerCnxn) e.getKey()).getSessionId(); - Set<String> paths = new HashSet<String>(e.getValue()); - id2paths.put(id, paths); - } - return new WatchesReport(id2paths); - } - - /** - * Returns a watch report by path. - * - * @return watch report - * @see WatchesPathReport - */ - synchronized WatchesPathReport getWatchesByPath() { - Map<String, Set<Long>> path2ids = new HashMap<String, Set<Long>>(); - for (Entry<String, Set<Watcher>> e : watchTable.entrySet()) { - Set<Long> ids = new HashSet<Long>(e.getValue().size()); - path2ids.put(e.getKey(), ids); - for (Watcher watcher : e.getValue()) { - ids.add(((ServerCnxn) watcher).getSessionId()); - } - } - return new WatchesPathReport(path2ids); - } - - /** - * Returns a watch summary. - * - * @return watch summary - * @see WatchesSummary - */ - synchronized WatchesSummary getWatchesSummary() { - int totalWatches = 0; - for (Set<String> paths : watch2Paths.values()) { - totalWatches += paths.size(); - } - return new WatchesSummary (watch2Paths.size(), watchTable.size(), - totalWatches); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesPathReport.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesPathReport.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesPathReport.java deleted file mode 100644 index 6792ac9..0000000 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesPathReport.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * A watch report, essentially a mapping of path to session IDs of sessions that - * have set a watch on that path. This class is immutable. - */ -public class WatchesPathReport { - - private final Map<String, Set<Long>> path2Ids; - - /** - * Creates a new report. - * - * @param path2Ids map of paths to session IDs of sessions that have set a - * watch on that path - */ - WatchesPathReport(Map<String, Set<Long>> path2Ids) { - this.path2Ids = Collections.unmodifiableMap(deepCopy(path2Ids)); - } - - private static Map<String, Set<Long>> deepCopy(Map<String, Set<Long>> m) { - Map<String, Set<Long>> m2 = new HashMap<String, Set<Long>>(); - for (Map.Entry<String, Set<Long>> e : m.entrySet()) { - m2.put(e.getKey(), new HashSet<Long>(e.getValue())); - } - return m2; - } - - /** - * Checks if the given path has watches set. - * - * @param path path - * @return true if path has watch set - */ - public boolean hasSessions(String path) { - return path2Ids.containsKey(path); - } - /** - * Gets the session IDs of sessions that have set watches on the given path. - * The returned set is immutable. - * - * @param path session ID - * @return session IDs of sessions that have set watches on the path, or - * null if none - */ - public Set<Long> getSessions(String path) { - Set<Long> s = path2Ids.get(path); - return s != null ? Collections.unmodifiableSet(s) : null; - } - - /** - * Converts this report to a map. The returned map is mutable, and changes - * to it do not reflect back into this report. - * - * @return map representation of report - */ - public Map<String, Set<Long>> toMap() { - return deepCopy(path2Ids); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesReport.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesReport.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesReport.java deleted file mode 100644 index e4c6dc2..0000000 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesReport.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server; - -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * A watch report, essentially a mapping of session ID to paths that the session - * has set a watch on. This class is immutable. - */ -public class WatchesReport { - - private final Map<Long, Set<String>> id2paths; - - /** - * Creates a new report. - * - * @param id2paths map of session IDs to paths that each session has set - * a watch on - */ - WatchesReport(Map<Long, Set<String>> id2paths) { - this.id2paths = Collections.unmodifiableMap(deepCopy(id2paths)); - } - - private static Map<Long, Set<String>> deepCopy(Map<Long, Set<String>> m) { - Map<Long, Set<String>> m2 = new HashMap<Long, Set<String>>(); - for (Map.Entry<Long, Set<String>> e : m.entrySet()) { - m2.put(e.getKey(), new HashSet<String>(e.getValue())); - } - return m2; - } - - /** - * Checks if the given session has watches set. - * - * @param sessionId session ID - * @return true if session has paths with watches set - */ - public boolean hasPaths(long sessionId) { - return id2paths.containsKey(sessionId); - } - - /** - * Gets the paths that the given session has set watches on. The returned - * set is immutable. - * - * @param sessionId session ID - * @return paths that have watches set by the session, or null if none - */ - public Set<String> getPaths(long sessionId) { - Set<String> s = id2paths.get(sessionId); - return s != null ? Collections.unmodifiableSet(s) : null; - } - - /** - * Converts this report to a map. The returned map is mutable, and changes - * to it do not reflect back into this report. - * - * @return map representation of report - */ - public Map<Long, Set<String>> toMap() { - return deepCopy(id2paths); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesSummary.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesSummary.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesSummary.java deleted file mode 100644 index 2053b55..0000000 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/WatchesSummary.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.zookeeper.server; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * A summary of watch information. This class is immutable. - */ -public class WatchesSummary { - - /** - * The key in the map returned by {@link #toMap()} for the number of - * connections. - */ - public static final String KEY_NUM_CONNECTIONS = "num_connections"; - /** - * The key in the map returned by {@link #toMap()} for the number of paths. - */ - public static final String KEY_NUM_PATHS = "num_paths"; - /** - * The key in the map returned by {@link #toMap()} for the total number of - * watches. - */ - public static final String KEY_NUM_TOTAL_WATCHES = "num_total_watches"; - - private final int numConnections; - private final int numPaths; - private final int totalWatches; - - /** - * Creates a new summary. - * - * @param numConnections the number of sessions that have set watches - * @param numPaths the number of paths that have watches set on them - * @param totalWatches the total number of watches set - */ - WatchesSummary(int numConnections, int numPaths, int totalWatches) { - this.numConnections = numConnections; - this.numPaths = numPaths; - this.totalWatches = totalWatches; - } - - /** - * Gets the number of connections (sessions) that have set watches. - * - * @return number of connections - */ - public int getNumConnections() { - return numConnections; - } - /** - * Gets the number of paths that have watches set on them. - * - * @return number of paths - */ - public int getNumPaths() { - return numPaths; - } - /** - * Gets the total number of watches set. - * - * @return total watches - */ - public int getTotalWatches() { - return totalWatches; - } - - /** - * Converts this summary to a map. The returned map is mutable, and changes - * to it do not reflect back into this summary. - * - * @return map representation of summary - */ - public Map<String, Object> toMap() { - Map<String, Object> summary = new LinkedHashMap<String, Object>(); - summary.put(KEY_NUM_CONNECTIONS, numConnections); - summary.put(KEY_NUM_PATHS, numPaths); - summary.put(KEY_NUM_TOTAL_WATCHES, totalWatches); - return summary; - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesPathReportTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesPathReportTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesPathReportTest.java deleted file mode 100644 index c0b107d..0000000 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesPathReportTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zookeeper.server; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.apache.zookeeper.ZKTestCase; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class WatchesPathReportTest extends ZKTestCase { - private Map<String, Set<Long>> m; - private WatchesPathReport r; - @Before public void setUp() { - m = new HashMap<String, Set<Long>>(); - Set<Long> s = new HashSet<Long>(); - s.add(101L); - s.add(102L); - m.put("path1", s); - s = new HashSet<Long>(); - s.add(201L); - m.put("path2", s); - r = new WatchesPathReport(m); - } - @Test public void testHasSessions() { - assertTrue(r.hasSessions("path1")); - assertTrue(r.hasSessions("path2")); - assertFalse(r.hasSessions("path3")); - } - @Test public void testGetSessions() { - Set<Long> s = r.getSessions("path1"); - assertEquals(2, s.size()); - assertTrue(s.contains(101L)); - assertTrue(s.contains(102L)); - s = r.getSessions("path2"); - assertEquals(1, s.size()); - assertTrue(s.contains(201L)); - assertNull(r.getSessions("path3")); - } - @Test public void testToMap() { - assertEquals(m, r.toMap()); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesReportTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesReportTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesReportTest.java deleted file mode 100644 index 7f0343b..0000000 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesReportTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zookeeper.server; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.apache.zookeeper.ZKTestCase; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class WatchesReportTest extends ZKTestCase { - private Map<Long, Set<String>> m; - private WatchesReport r; - @Before public void setUp() { - m = new HashMap<Long, Set<String>>(); - Set<String> s = new HashSet<String>(); - s.add("path1a"); - s.add("path1b"); - m.put(1L, s); - s = new HashSet<String>(); - s.add("path2a"); - m.put(2L, s); - r = new WatchesReport(m); - } - @Test public void testHasPaths() { - assertTrue(r.hasPaths(1L)); - assertTrue(r.hasPaths(2L)); - assertFalse(r.hasPaths(3L)); - } - @Test public void testGetPaths() { - Set<String> s = r.getPaths(1L); - assertEquals(2, s.size()); - assertTrue(s.contains("path1a")); - assertTrue(s.contains("path1b")); - s = r.getPaths(2L); - assertEquals(1, s.size()); - assertTrue(s.contains("path2a")); - assertNull(r.getPaths(3L)); - } - @Test public void testToMap() { - assertEquals(m, r.toMap()); - } -} http://git-wip-us.apache.org/repos/asf/zookeeper/blob/a5ffb4c8/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesSummaryTest.java ---------------------------------------------------------------------- diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesSummaryTest.java b/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesSummaryTest.java deleted file mode 100644 index d679065..0000000 --- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/WatchesSummaryTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zookeeper.server; - -import java.util.Map; -import org.apache.zookeeper.ZKTestCase; -import org.junit.Before; -import org.junit.Test; -import static org.junit.Assert.*; - -public class WatchesSummaryTest extends ZKTestCase { - private WatchesSummary s; - @Before public void setUp() { - s = new WatchesSummary(1, 2, 3); - } - @Test public void testGetters() { - assertEquals(1, s.getNumConnections()); - assertEquals(2, s.getNumPaths()); - assertEquals(3, s.getTotalWatches()); - } - @Test public void testToMap() { - Map<String, Object> m = s.toMap(); - assertEquals(3, m.size()); - assertEquals(Integer.valueOf(1), m.get(WatchesSummary.KEY_NUM_CONNECTIONS)); - assertEquals(Integer.valueOf(2), m.get(WatchesSummary.KEY_NUM_PATHS)); - assertEquals(Integer.valueOf(3), m.get(WatchesSummary.KEY_NUM_TOTAL_WATCHES)); - } -}
