@Test public void testCountUpHost() { String hostname = "foo.example.org"; counter.countUpHost(hostname, 25); counter.countUpHost(hostname, 40); int res = counter.getHostCounts().get(Tools.encodeBase64(hostname)); assertEquals(65, res); }
@Test public void testIncrementHost() { String hostname = "foobar"; counter.countUpHost(hostname, 10); counter.incrementHost(hostname); int res = counter.getHostCounts().get(Tools.encodeBase64(hostname)); assertEquals(11, res); }
@Test public void testResetAllCounts() { counter.countUpTotal(100); counter.countUpHost("foo.example.org", 9001); counter.countUpStream(new ObjectId(), 5); assertEquals(100, counter.getTotalCount()); // Just to make sure. counter.resetAllCounts(); assertEquals(0, counter.getTotalCount()); assertEquals(0, counter.getHostCounts().size()); assertEquals(0, counter.getStreamCounts().size()); }
@Test public void testGetHostCounts() { String host1 = "example.org"; String host2 = "foo.example.org"; String host3 = "example.com"; Map expected = new HashMap<String, Integer>(); expected.put(Tools.encodeBase64(host1), 5); expected.put(Tools.encodeBase64(host2), 1); expected.put(Tools.encodeBase64(host3), 3); counter.countUpStream(new ObjectId(), 5); // Add a stream count for complexity. counter.countUpHost(host1, 4); counter.countUpHost(host1, 1); counter.incrementHost(host2); counter.countUpHost(host3, 3); assertEquals(expected, counter.getHostCounts()); }
@Test public void testResetHostCounts() { counter.countUpHost("lolwat", 200); counter.resetHostCounts(); assertEquals(new HashMap<String, Integer>(), counter.getHostCounts()); }