From 0b26ccdaa1b8700e7958aeebbaf9cad81e737dd0 Mon Sep 17 00:00:00 2001 From: Mike Drob Date: Fri, 30 Jun 2017 12:13:56 -0500 Subject: [PATCH] HBASE-18303 Clean up @Parameter boilerplate --- .../hbase/filter/TestKeyOnlyFilter.java | 15 ++++--------- .../hbase/HBaseCommonTestingUtility.java | 22 +++++++++++++++++++ .../apache/hadoop/hbase/types/TestStruct.java | 18 +++++++-------- .../hbase/util/TestByteBufferUtils.java | 8 ++----- .../codec/keyvalue/TestKeyValueTool.java | 16 +++++++------- .../codec/prefixtree/row/TestRowEncoder.java | 6 +---- .../hbase/rest/TestMultiRowResource.java | 5 +---- .../hadoop/hbase/HBaseTestingUtility.java | 20 +---------------- .../encoding/TestSeekToBlockWithEncoders.java | 4 ++-- .../hbase/io/hfile/TestCacheOnWrite.java | 3 ++- .../hadoop/hbase/io/hfile/TestHFile.java | 3 ++- .../hbase/io/hfile/TestHFileBlockIndex.java | 3 ++- .../hbase/io/hfile/TestHFileWriterV3.java | 3 ++- .../hbase/util/TestCoprocessorScanPolicy.java | 3 ++- 14 files changed, 59 insertions(+), 70 deletions(-) diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java index 33e3cd9b2eb..f957b592f72 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.hadoop.hbase.ByteBufferKeyValue; import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.Type; import org.apache.hadoop.hbase.KeyValueUtil; @@ -44,20 +45,12 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class TestKeyOnlyFilter { - private final boolean lenAsVal; + @Parameterized.Parameter + public boolean lenAsVal; @Parameters public static Collection parameters() { - List paramList = new ArrayList<>(2); - { - paramList.add(new Object[] { false }); - paramList.add(new Object[] { true }); - } - return paramList; - } - - public TestKeyOnlyFilter(boolean lenAsVal) { - this.lenAsVal = lenAsVal; + return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED; } @Test diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java index e1910467235..1790f4a9399 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java @@ -20,6 +20,8 @@ package org.apache.hadoop.hbase; import java.io.File; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import java.util.UUID; import org.apache.commons.io.FileUtils; @@ -28,6 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.io.compress.Compression; /** * Common helpers for testing HBase that do not depend on specific server/etc. things. @@ -37,6 +40,25 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience; public class HBaseCommonTestingUtility { protected static final Log LOG = LogFactory.getLog(HBaseCommonTestingUtility.class); + /** Compression algorithms to use in parameterized JUnit 4 tests */ + public static final List COMPRESSION_ALGORITHMS_PARAMETERIZED = + Arrays.asList(new Object[][] { + { Compression.Algorithm.NONE }, + { Compression.Algorithm.GZ } + }); + + /** This is for unit tests parameterized with a two booleans. */ + public static final List BOOLEAN_PARAMETERIZED = + Arrays.asList(new Object[][] { + {false}, + {true} + }); + + /** Compression algorithms to use in testing */ + public static final Compression.Algorithm[] COMPRESSION_ALGORITHMS = { + Compression.Algorithm.NONE, Compression.Algorithm.GZ + }; + protected Configuration conf; public HBaseCommonTestingUtility() { diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java index 8dc239ba07e..4fcaaec8564 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/types/TestStruct.java @@ -47,17 +47,15 @@ import org.junit.runners.Parameterized.Parameters; @Category({MiscTests.class, SmallTests.class}) public class TestStruct { - private Struct generic; - @SuppressWarnings("rawtypes") - private DataType specialized; - private Object[][] constructorArgs; + @Parameterized.Parameter(value = 0) + public Struct generic; - public TestStruct(Struct generic, @SuppressWarnings("rawtypes") DataType specialized, - Object[][] constructorArgs) { - this.generic = generic; - this.specialized = specialized; - this.constructorArgs = constructorArgs; - } + @SuppressWarnings("rawtypes") + @Parameterized.Parameter(value = 1) + public DataType specialized; + + @Parameterized.Parameter(value = 2) + public Object[][] constructorArgs; @Parameters public static Collection params() { diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java index ee03c7b970c..81923cadd11 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java @@ -44,6 +44,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -69,12 +70,7 @@ public class TestByteBufferUtils { @Parameterized.Parameters public static Collection parameters() { - List paramList = new ArrayList<>(2); - { - paramList.add(new Object[] { false }); - paramList.add(new Object[] { true }); - } - return paramList; + return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED; } private static void setUnsafe(String fieldName, boolean value) throws Exception { diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/keyvalue/TestKeyValueTool.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/keyvalue/TestKeyValueTool.java index 9e27942cf2a..3e5f0f80fe2 100644 --- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/keyvalue/TestKeyValueTool.java +++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/keyvalue/TestKeyValueTool.java @@ -31,12 +31,15 @@ import org.apache.hadoop.hbase.codec.prefixtree.row.TestRowData; import org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataRandomKeyValuesWithTags; import org.apache.hadoop.hbase.codec.prefixtree.row.data.TestRowDataTrivialWithTags; import org.junit.Assert; +import org.junit.Assume; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import static org.junit.Assume.assumeFalse; + @Category({MiscTests.class, SmallTests.class}) @RunWith(Parameterized.class) public class TestKeyValueTool { @@ -46,17 +49,14 @@ public class TestKeyValueTool { return TestRowData.InMemory.getAllAsObjectArray(); } - private TestRowData rows; - - public TestKeyValueTool(TestRowData testRows) { - this.rows = testRows; - } + @Parameterized.Parameter + public TestRowData rows; @Test public void testRoundTripToBytes() { - if(rows instanceof TestRowDataTrivialWithTags || rows instanceof TestRowDataRandomKeyValuesWithTags) { - return; - } + assumeFalse(rows instanceof TestRowDataTrivialWithTags); + assumeFalse(rows instanceof TestRowDataRandomKeyValuesWithTags); + List kvs = rows.getInputs(); ByteBuffer bb = KeyValueTestUtil.toByteBufferAndRewind(kvs, false); List roundTrippedKvs = KeyValueTestUtil.rewindThenToList(bb, false, false); diff --git a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestRowEncoder.java b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestRowEncoder.java index 22119bef928..a8e5feb8684 100644 --- a/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestRowEncoder.java +++ b/hbase-prefix-tree/src/test/java/org/apache/hadoop/hbase/codec/prefixtree/row/TestRowEncoder.java @@ -55,11 +55,7 @@ public class TestRowEncoder { @Parameters public static Collection parameters() { - List parameters = Lists.newArrayList(); - for (TestRowData testRows : TestRowData.InMemory.getAll()) { - parameters.add(new Object[] { testRows }); - } - return parameters; + return TestRowData.InMemory.getAllAsObjectArray(); } protected TestRowData rows; diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java index 2a0b4600ea2..537a293f633 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestMultiRowResource.java @@ -82,10 +82,7 @@ public class TestMultiRowResource { @Parameterized.Parameters public static Collection data() { - List params = new ArrayList<>(2); - params.add(new Object[] {Boolean.TRUE}); - params.add(new Object[] {Boolean.FALSE}); - return params; + return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED; } public TestMultiRowResource(Boolean csrf) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 8761ef64392..44aeb887266 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -216,26 +216,8 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { /** Filesystem URI used for map-reduce mini-cluster setup */ private static String FS_URI; - /** Compression algorithms to use in parameterized JUnit 4 tests */ - public static final List COMPRESSION_ALGORITHMS_PARAMETERIZED = - Arrays.asList(new Object[][] { - { Compression.Algorithm.NONE }, - { Compression.Algorithm.GZ } - }); - - /** This is for unit tests parameterized with a two booleans. */ - public static final List BOOLEAN_PARAMETERIZED = - Arrays.asList(new Object[][] { - {false}, - {true} - }); - /** This is for unit tests parameterized with a single boolean. */ public static final List MEMSTORETS_TAGS_PARAMETRIZED = memStoreTSAndTagsCombination(); - /** Compression algorithms to use in testing */ - public static final Compression.Algorithm[] COMPRESSION_ALGORITHMS ={ - Compression.Algorithm.NONE, Compression.Algorithm.GZ - }; /** * Checks to see if a specific port is available. @@ -278,7 +260,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { private static List bloomAndCompressionCombinations() { List configurations = new ArrayList<>(); for (Compression.Algorithm comprAlgo : - HBaseTestingUtility.COMPRESSION_ALGORITHMS) { + HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS) { for (BloomType bloomType : BloomType.values()) { configurations.add(new Object[] { comprAlgo, bloomType }); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java index cc70dc1ba81..4a7f2ebd526 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestSeekToBlockWithEncoders.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.io.compress.Compression; @@ -51,7 +51,7 @@ public class TestSeekToBlockWithEncoders { @Parameters public static Collection parameters() { - return HBaseTestingUtility.BOOLEAN_PARAMETERIZED; + return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED; } public TestSeekToBlockWithEncoders(boolean useOffheapData) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java index d4f8a59d427..950beec05d7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCacheOnWrite.java @@ -41,6 +41,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.CellComparator; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -179,7 +180,7 @@ public class TestCacheOnWrite { List params = new ArrayList<>(); for (BlockCache blockCache : getBlockCaches()) { for (CacheOnWriteType cowType : CacheOnWriteType.values()) { - for (Compression.Algorithm compress : HBaseTestingUtility.COMPRESSION_ALGORITHMS) { + for (Compression.Algorithm compress : HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS) { for (boolean cacheCompressedData : new boolean[] { false, true }) { params.add(new Object[] { cowType, compress, cacheCompressedData, blockCache }); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java index d20943048d9..62a7c489b3f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFile.java @@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.ArrayBackedTag; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -440,7 +441,7 @@ public class TestHFile { public void testNullMetaBlocks() throws Exception { if (cacheConf == null) cacheConf = new CacheConfig(conf); for (Compression.Algorithm compressAlgo : - HBaseTestingUtility.COMPRESSION_ALGORITHMS) { + HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS) { Path mFile = new Path(ROOT_DIR, "nometa_" + compressAlgo + ".hfile"); FSDataOutputStream fout = createFSOutput(mFile); HFileContext meta = new HFileContextBuilder().withCompression(compressAlgo) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java index bdd3de2d7b3..3d1af90ade0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileBlockIndex.java @@ -44,6 +44,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueUtil; @@ -73,7 +74,7 @@ public class TestHFileBlockIndex { @Parameters public static Collection compressionAlgorithms() { - return HBaseTestingUtility.COMPRESSION_ALGORITHMS_PARAMETERIZED; + return HBaseCommonTestingUtility.COMPRESSION_ALGORITHMS_PARAMETERIZED; } public TestHFileBlockIndex(Compression.Algorithm compr) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java index 0bf20b3a2bd..400c72f0578 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileWriterV3.java @@ -39,6 +39,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparator; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -81,7 +82,7 @@ public class TestHFileWriterV3 { } @Parameters public static Collection parameters() { - return HBaseTestingUtility.BOOLEAN_PARAMETERIZED; + return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED; } @Before diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java index 2a44243379c..993a1fdf101 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java @@ -31,6 +31,7 @@ import java.util.NavigableSet; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -89,7 +90,7 @@ public class TestCoprocessorScanPolicy { @Parameters public static Collection parameters() { - return HBaseTestingUtility.BOOLEAN_PARAMETERIZED; + return HBaseCommonTestingUtility.BOOLEAN_PARAMETERIZED; } public TestCoprocessorScanPolicy(boolean parallelSeekEnable) {