mneethiraj commented on code in PR #442: URL: https://github.com/apache/ranger/pull/442#discussion_r1881218926
########## agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestCacheMap.java: ########## @@ -28,89 +28,79 @@ import java.util.Set; public class TestCacheMap { - private static final Logger LOG = LoggerFactory.getLogger(TestCacheMap.class); - private static CacheMap<String, String> testCacheMap; - private static int initialCapacity = 16; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - if(LOG.isDebugEnabled()) { - LOG.debug("==> TestCacheMap.setUpBeforeClass(), initialCapacity:" + initialCapacity); - } - - testCacheMap = new CacheMap<String, String>(initialCapacity); - - if(LOG.isDebugEnabled()) { - LOG.debug("<== TestCacheMap.setUpBeforeClass(), initialCapacity:" + initialCapacity); - } - } - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - @Test - public void runTests() { - - if(LOG.isDebugEnabled()) { - LOG.debug("==> TestCacheMap.runTests(), First batch of " + initialCapacity + " inserts starting from 0"); - } - for (int i = 0; i < initialCapacity; i++) { - String key = String.valueOf(i); - String value = key; - - if (LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), Inserting into Cache, key:" + key + ", value:" + value); - } - testCacheMap.put(key, value); - if (LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), Cache Size after insert(): " + testCacheMap.size()); - } - } - - if(LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), First batch of " + initialCapacity/2 + " retrieves counting down from " + (initialCapacity/2-1)); - } - - for (int i = initialCapacity/2 - 1; i >= 0; i--) { - String key = String.valueOf(i); - if (LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), Searching Cache, key:" + key); - } - String value = testCacheMap.get(key); - if (value == null || !value.equals(key)) { - LOG.error("TestCacheMap.runTests(), Did not get correct value for key, key:" + key + ", value:" + value); - } - } - if(LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), Second batch of " + initialCapacity/2 + " inserts starting from " + initialCapacity); - } - for (int i = initialCapacity; i < initialCapacity+initialCapacity/2; i++) { - String key = String.valueOf(i); - String value = key; - - if (LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), Inserting into Cache, key:" + key + ", value:" + value); - } - testCacheMap.put(key, value); - if (LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), Cache Size after insert(): " + testCacheMap.size()); - } - } - - Set<String> keySet = testCacheMap.keySet(); - - if (LOG.isDebugEnabled()) { - LOG.debug("TestCacheMap.runTests(), KeySet Size:" + keySet.size()); - LOG.debug("TestCacheMap.runTests(), printing keys.."); - - int i = 0; - - for (String key : keySet) { - LOG.debug("TestCacheMap.runTests(), index:" + i++ + ", key:" + key); - } - - LOG.debug("<== TestCacheMap.runTests()"); - } - - } + private static final Logger LOG = LoggerFactory.getLogger(TestCacheMap.class); + + private static CacheMap<String, String> testCacheMap; + private static final int initialCapacity = 16; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + LOG.debug("==> TestCacheMap.setUpBeforeClass(), initialCapacity:{}", initialCapacity); + + testCacheMap = new CacheMap<>(initialCapacity); + + LOG.debug("<== TestCacheMap.setUpBeforeClass(), initialCapacity:{}", initialCapacity); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Test + public void runTests() { + LOG.debug("==> TestCacheMap.runTests(), First batch of {} inserts starting from 0", initialCapacity); + + for (int i = 0; i < initialCapacity; i++) { + String key = String.valueOf(i); + String value = key; + + LOG.debug("TestCacheMap.runTests(), Inserting into Cache, key:{}, value:{}", key, value); + + testCacheMap.put(key, value); + + LOG.debug("TestCacheMap.runTests(), Cache Size after insert(): {}", testCacheMap.size()); + } + + LOG.debug("TestCacheMap.runTests(), First batch of {} retrieves counting down from {}", initialCapacity / 2, (initialCapacity / 2 - 1)); + + for (int i = initialCapacity / 2 - 1; i >= 0; i--) { + String key = String.valueOf(i); + + LOG.debug("TestCacheMap.runTests(), Searching Cache, key:{}", key); + + String value = testCacheMap.get(key); + + if (value == null || !value.equals(key)) { + LOG.error("TestCacheMap.runTests(), Did not get correct value for key, key:{}, value:{}", key, value); + } + } + + LOG.debug("TestCacheMap.runTests(), Second batch of {} inserts starting from {}", initialCapacity / 2, initialCapacity); + + for (int i = initialCapacity; i < initialCapacity + initialCapacity / 2; i++) { + String key = String.valueOf(i); + String value = key; + + LOG.debug("TestCacheMap.runTests(), Inserting into Cache, key:{}, value:{}", key, value); + + testCacheMap.put(key, value); + + LOG.debug("TestCacheMap.runTests(), Cache Size after insert(): {}", testCacheMap.size()); + } + + Set<String> keySet = testCacheMap.keySet(); + + if (LOG.isDebugEnabled()) { Review Comment: The whole block is only for debug logging; hence skipping the block when debug is disabled. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org