OutputLineFilter { public Boolean apply(Map<String, Object> lineMap, Input input) { boolean isLogFilteredOut = false; LRUCache inputLruCache = input.getCache(); if (inputLruCache != null && "service".equals(input.getConfigs().get(LogFeederConstants.ROW_TYPE))) { String logMessage = (String) lineMap.get(input.getCacheKeyField()); Long timestamp = null; if (lineMap.containsKey((LogFeederConstants.IN_MEMORY_TIMESTAMP))) { timestamp = (Long) lineMap.get(LogFeederConstants.IN_MEMORY_TIMESTAMP); } if (logMessage != null && timestamp != null) { isLogFilteredOut = !inputLruCache.isEntryReplaceable(logMessage, timestamp); if (!isLogFilteredOut) { inputLruCache.put(logMessage, timestamp); } else { LOG.debug("Log line filtered out: {} (file: {}, dedupInterval: {}, lastDedupEnabled: {})", logMessage, inputLruCache.getFileName(), inputLruCache.getDedupInterval(), inputLruCache.isLastDedupEnabled()); } } } if (lineMap.containsKey(LogFeederConstants.IN_MEMORY_TIMESTAMP)) { lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); } return isLogFilteredOut; }  Boolean apply(Map<String, Object> lineMap, Input input);  }
@Test public void testApplyWithFilterOutByDedupInterval() { EasyMock.expect(inputMock.getCache()).andReturn(createLruCache(DEFAULT_DUMMY_MESSAGE, 100L, false)); EasyMock.expect(inputMock.getConfigs()).andReturn(generateInputConfigs()); EasyMock.expect(inputMock.getCacheKeyField()).andReturn(CACHE_KEY_FIELD); EasyMock.replay(inputMock); boolean result = underTest.apply(generateLineMap(), inputMock); EasyMock.verify(inputMock); assertTrue(result); }
@Test public void testApplyDoNotFilterOutDataByDedupInterval() { EasyMock.expect(inputMock.getCache()).andReturn(createLruCache(DEFAULT_DUMMY_MESSAGE, 10L, false)); EasyMock.expect(inputMock.getConfigs()).andReturn(generateInputConfigs()); EasyMock.expect(inputMock.getCacheKeyField()).andReturn(CACHE_KEY_FIELD); EasyMock.replay(inputMock); boolean result = underTest.apply(generateLineMap(), inputMock); EasyMock.verify(inputMock); assertFalse(result); }
@Test public void testApplyWithFilterOutByDedupLast() { EasyMock.expect(inputMock.getCache()).andReturn(createLruCache(DEFAULT_DUMMY_MESSAGE, 10L, true)); EasyMock.expect(inputMock.getConfigs()).andReturn(generateInputConfigs()); EasyMock.expect(inputMock.getCacheKeyField()).andReturn(CACHE_KEY_FIELD); EasyMock.replay(inputMock); boolean result = underTest.apply(generateLineMap(), inputMock); EasyMock.verify(inputMock); assertTrue(result); }
@Test public void testApplyDoNotFilterOutDataByDedupLast() { EasyMock.expect(inputMock.getCache()).andReturn(createLruCache("myMessage2", 10L, true)); EasyMock.expect(inputMock.getConfigs()).andReturn(generateInputConfigs()); EasyMock.expect(inputMock.getCacheKeyField()).andReturn(CACHE_KEY_FIELD); EasyMock.replay(inputMock); boolean result = underTest.apply(generateLineMap(), inputMock); EasyMock.verify(inputMock); assertFalse(result); }
@Test public void testApplyWithoutLruCache() { EasyMock.expect(inputMock.getCache()).andReturn(null); EasyMock.replay(inputMock); boolean result = underTest.apply(generateLineMap(), inputMock); EasyMock.verify(inputMock); assertFalse(result); }
@Test public void testApplyWithoutInMemoryTimestamp() { EasyMock.expect(inputMock.getCache()).andReturn(createLruCache(DEFAULT_DUMMY_MESSAGE, 100L, true)); EasyMock.expect(inputMock.getConfigs()).andReturn(generateInputConfigs()); EasyMock.expect(inputMock.getCacheKeyField()).andReturn(CACHE_KEY_FIELD); EasyMock.replay(inputMock); Map<String, Object> lineMap = generateLineMap(); lineMap.remove(LogFeederConstants.IN_MEMORY_TIMESTAMP); boolean result = underTest.apply(lineMap, inputMock); EasyMock.verify(inputMock); assertFalse(result); }
@Test public void testApplyWithoutLogMessage() { EasyMock.expect(inputMock.getCache()).andReturn(createLruCache(DEFAULT_DUMMY_MESSAGE, 100L, true)); EasyMock.expect(inputMock.getConfigs()).andReturn(generateInputConfigs()); EasyMock.expect(inputMock.getCacheKeyField()).andReturn(CACHE_KEY_FIELD); EasyMock.replay(inputMock); Map<String, Object> lineMap = generateLineMap(); lineMap.remove(CACHE_KEY_FIELD); boolean result = underTest.apply(lineMap, inputMock); EasyMock.verify(inputMock); assertFalse(result); }