This is an automated email from the ASF dual-hosted git repository. mmiller pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push: new 6a2b949 Remove log4j from CombinerTest. Fixes #1512 6a2b949 is described below commit 6a2b94987548ecbcd2655d0c3016d809877fd94c Author: Mike Miller <mmil...@apache.org> AuthorDate: Wed Feb 19 09:17:42 2020 -0500 Remove log4j from CombinerTest. Fixes #1512 --- .../accumulo/core/iterators/CombinerTestUtil.java | 4 ++ .../accumulo/core/iterators/user/CombinerTest.java | 71 ++++++++-------------- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java b/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java index 88b22ea..fc9ac31 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java @@ -22,4 +22,8 @@ public class CombinerTestUtil { public static void clearLogCache() { Combiner.loggedMsgCache.invalidateAll(); } + + public static long cacheSize() { + return Combiner.loggedMsgCache.size(); + } } diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java index 35c45a1..b247369 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; -import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -54,9 +53,6 @@ import org.apache.accumulo.core.iterators.TypedValueCombiner; import org.apache.accumulo.core.iterators.ValueFormatException; import org.apache.accumulo.core.iteratorsImpl.system.MultiIterator; import org.apache.hadoop.io.Text; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.WriterAppender; import org.junit.Test; public class CombinerTest { @@ -845,62 +841,46 @@ public class CombinerTest { private void runDeleteHandlingTest(TreeMap<Key,Value> input, TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env) throws Exception { - runDeleteHandlingTest(input, expected, rofco, env, null, true); + runDeleteHandlingTest(input, expected, rofco, env, false, true); } private void runDeleteHandlingTest(TreeMap<Key,Value> input, TreeMap<Key,Value> expected, - Boolean rofco, IteratorEnvironment env, String expectedLog) throws Exception { + Boolean rofco, IteratorEnvironment env, boolean expectedLog) throws Exception { runDeleteHandlingTest(input, expected, rofco, env, expectedLog, true); - if (expectedLog != null) { + if (expectedLog) { // run test again... should not see log message again because cache is not cleared - runDeleteHandlingTest(input, expected, rofco, env, null, false); + runDeleteHandlingTest(input, expected, rofco, env, true, false); } } private void runDeleteHandlingTest(TreeMap<Key,Value> input, TreeMap<Key,Value> expected, - Boolean rofco, IteratorEnvironment env, String expectedLog, boolean clearLogMsgCache) + Boolean rofco, IteratorEnvironment env, boolean expectedLog, boolean clearLogMsgCache) throws Exception { boolean deepCopy = expected == null; if (clearLogMsgCache) { CombinerTestUtil.clearLogCache(); } + Combiner ai = new SummingCombiner(); - StringWriter writer = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout("%p, %m%n"), writer); - Logger logger = Logger.getLogger(Combiner.class); - boolean additivity = logger.getAdditivity(); - try { - logger.addAppender(appender); - logger.setAdditivity(false); - - Combiner ai = new SummingCombiner(); - - IteratorSetting is = new IteratorSetting(1, SummingCombiner.class); - SummingCombiner.setEncodingType(is, LongCombiner.StringEncoder.class); - Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001"))); - if (rofco != null) { - Combiner.setReduceOnFullCompactionOnly(is, rofco); - } - - ai.init(new SortedMapIterator(input), is.getOptions(), env); + IteratorSetting is = new IteratorSetting(1, SummingCombiner.class); + SummingCombiner.setEncodingType(is, LongCombiner.StringEncoder.class); + Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001"))); + if (rofco != null) { + Combiner.setReduceOnFullCompactionOnly(is, rofco); + } - if (deepCopy) - assertEquals(expected, readAll(ai.deepCopy(env))); - assertEquals(expected, readAll(ai)); + ai.init(new SortedMapIterator(input), is.getOptions(), env); - } finally { - logger.removeAppender(appender); - logger.setAdditivity(additivity); - } + if (deepCopy) + assertEquals(expected, readAll(ai.deepCopy(env))); + assertEquals(expected, readAll(ai)); - String logMsgs = writer.toString(); - if (expectedLog == null) { - assertEquals("Expected 0 length log message, but got : " + logMsgs, 0, logMsgs.length()); + long logSize = CombinerTestUtil.cacheSize(); + if (!expectedLog) { + assertEquals("Expected 0 log messages, but got : " + logSize, 0, logSize); } else { - logMsgs = logMsgs.replace('\n', ' '); - assertTrue("Did not match pattern [" + expectedLog + "] in [" + logMsgs + "]", - logMsgs.matches(expectedLog)); + assertTrue("Expected >0 log messages, but got : " + logSize, logSize > 0); } } @@ -928,15 +908,12 @@ public class CombinerTest { runDeleteHandlingTest(input, expected, true, fullMajcIe); runDeleteHandlingTest(input, expected, true, SCAN_IE); - runDeleteHandlingTest(input, expected, false, fullMajcIe, ".*ERROR.*ACCUMULO-2232.*"); + runDeleteHandlingTest(input, expected, false, fullMajcIe, true); runDeleteHandlingTest(input, expected, false, SCAN_IE); - runDeleteHandlingTest(input, expected, false, paritalMajcIe, - ".*ERROR.*SummingCombiner.*ACCUMULO-2232.*"); - runDeleteHandlingTest(input, expected, null, paritalMajcIe, - ".*ERROR.*SummingCombiner.*ACCUMULO-2232.*"); - runDeleteHandlingTest(input, expected, null, fullMajcIe, - ".*ERROR.*SummingCombiner.*ACCUMULO-2232.*"); + runDeleteHandlingTest(input, expected, false, paritalMajcIe, true); + runDeleteHandlingTest(input, expected, null, paritalMajcIe, true); + runDeleteHandlingTest(input, expected, null, fullMajcIe, true); } /**