HostRequestIntervalRegistry { public long tick(String clientHostId) { if (whiteList.contains(clientHostId)) { return 0; } else if (blackList.contains(clientHostId)) { return Long.MAX_VALUE; } IntervalCount intervalCount = hostCounts.computeIfAbsent(clientHostId, s -> new IntervalCount(intervalDurationMs)); return intervalCount.resetIfExpiredAndTick(); } HostRequestIntervalRegistry(@Value("${quota.host.intervalMs}") long intervalDurationMs,
                                       @Value("${quota.host.ttlMs}") long ttlMs,
                                       @Value("${quota.host.whitelist}") String whiteList,
                                       @Value("${quota.host.blacklist}") String blackList); @PostConstruct void init(); long tick(String clientHostId); void clean(); Map<String, Long> getContent();  }
@Test public void domainFromBlackListReturnMaxValue(){ assertEquals(Long.MAX_VALUE, registry.tick("b1")); assertEquals(Long.MAX_VALUE, registry.tick("b1")); }
@Test public void emptyWhitelistParsedOk(){ registry = new HostRequestIntervalRegistry(10000L, 100L,"", "b1"); assertEquals(1L, registry.tick("aaa")); }
@Test public void emptyBlacklistParsedOk(){ registry = new HostRequestIntervalRegistry(10000L, 100L,"", ""); assertEquals(1L, registry.tick("aaa")); }
@Test public void newHostCreateNewInterval() { assertEquals(1L, registry.tick("host1")); }
@Test public void existingHostUpdated() { registry.tick("aaa"); assertEquals(1L, registry.tick("bbb")); assertEquals(2L, registry.tick("aaa")); }
@Test public void domainFromWhitelistNotCounted(){ assertEquals(0L, registry.tick("g1")); assertEquals(0L, registry.tick("g1")); assertEquals(0L, registry.tick("g2")); }