From f2d99cc768aa195456a39fecab42d41b7bd0479e Mon Sep 17 00:00:00 2001 From: Andor Molnar Date: Mon, 15 Jul 2019 16:26:48 +0200 Subject: [PATCH 1/4] HBASE-22382. Refactored testNull() into multiple tests --- .../hbase/client/TestFromClientSide.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index ec44bd09bf1d..0cbb643224cb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -1156,20 +1156,28 @@ public void testSingleRowMultipleFamily() throws Exception { } @Test - public void testNull() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); - + public void testNull_TableName() { // Null table name (should NOT work) try { TEST_UTIL.createTable((TableName)null, FAMILY); fail("Creating a table with null name passed, should have failed"); } catch(Exception e) {} + } + + @Test + public void testNull_FamilyName() { + final TableName tableName = TableName.valueOf(name.getMethodName()); // Null family (should NOT work) try { TEST_UTIL.createTable(tableName, new byte[][]{null}); fail("Creating a table with a null family passed, should fail"); } catch(Exception e) {} + } + + @Test + public void testNull_RowAndQualifier() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { @@ -1201,9 +1209,13 @@ public void testNull() throws Exception { assertEmptyResult(result); } } + } - // Use a new table - try (Table ht = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName() + "2"), FAMILY)) { + @Test + public void testNull_EmptyQualifier() throws Exception { + final TableName tableName = TableName.valueOf(name.getMethodName()); + + try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { // Empty qualifier, byte[0] instead of null (should work) try { @@ -1234,7 +1246,14 @@ public void testNull() throws Exception { } catch (Exception e) { throw new IOException("Using a row with null qualifier threw exception, should "); } + } + } + @Test + public void testNull_Value() throws IOException { + final TableName tableName = TableName.valueOf(name.getMethodName()); + + try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { // Null value try { Put put = new Put(ROW); From 85366821691bb6c067316194c77435f4f7643bc4 Mon Sep 17 00:00:00 2001 From: Andor Molnar Date: Mon, 15 Jul 2019 16:45:33 +0200 Subject: [PATCH 2/4] HBASE-22382. Suppress checkstyle warning on testVersionLimits() and testDeletesWithReverseScan() --- .../java/org/apache/hadoop/hbase/client/TestFromClientSide.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index 0cbb643224cb..7a67cf200887 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -1569,6 +1569,7 @@ public void testVersions() throws Exception { } @Test + @SuppressWarnings("checkstyle:MethodLength") public void testVersionLimits() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); byte [][] FAMILIES = makeNAscii(FAMILY, 3); @@ -5984,6 +5985,7 @@ public void testNullWithReverseScan() throws Exception { } @Test + @SuppressWarnings("checkstyle:MethodLength") public void testDeletesWithReverseScan() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); byte[][] ROWS = makeNAscii(ROW, 6); From dfe1d5ba570f881e479859435a256f62dda02a5d Mon Sep 17 00:00:00 2001 From: Andor Molnar Date: Fri, 19 Jul 2019 11:22:09 +0200 Subject: [PATCH 3/4] HBASE-22382. Change test naming to camel case --- .../apache/hadoop/hbase/client/TestFromClientSide.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index 7a67cf200887..8bd1448abfc7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -1156,7 +1156,7 @@ public void testSingleRowMultipleFamily() throws Exception { } @Test - public void testNull_TableName() { + public void testNullTableName() { // Null table name (should NOT work) try { TEST_UTIL.createTable((TableName)null, FAMILY); @@ -1165,7 +1165,7 @@ public void testNull_TableName() { } @Test - public void testNull_FamilyName() { + public void testNullFamilyName() { final TableName tableName = TableName.valueOf(name.getMethodName()); // Null family (should NOT work) @@ -1176,7 +1176,7 @@ public void testNull_FamilyName() { } @Test - public void testNull_RowAndQualifier() throws Exception { + public void testNullRowAndQualifier() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { @@ -1212,7 +1212,7 @@ public void testNull_RowAndQualifier() throws Exception { } @Test - public void testNull_EmptyQualifier() throws Exception { + public void testNullEmptyQualifier() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { @@ -1250,7 +1250,7 @@ public void testNull_EmptyQualifier() throws Exception { } @Test - public void testNull_Value() throws IOException { + public void testNullValue() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) { From ddcd7ef29e64e394fb0357dd4ab1a302202af2e1 Mon Sep 17 00:00:00 2001 From: Andor Molnar Date: Tue, 23 Jul 2019 14:00:29 +0200 Subject: [PATCH 4/4] HBASE-22382. Refactored test to take advantage of JUnit expected exception, fixed language --- .../hbase/client/TestFromClientSide.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index 8bd1448abfc7..38231037aac4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -1155,24 +1155,20 @@ public void testSingleRowMultipleFamily() throws Exception { } } - @Test - public void testNullTableName() { + @Test(expected = IOException.class) + public void testNullTableName() throws IOException { // Null table name (should NOT work) - try { - TEST_UTIL.createTable((TableName)null, FAMILY); - fail("Creating a table with null name passed, should have failed"); - } catch(Exception e) {} + TEST_UTIL.createTable((TableName)null, FAMILY); + fail("Creating a table with null name passed, should have failed"); } - @Test - public void testNullFamilyName() { + @Test(expected = IOException.class) + public void testNullFamilyName() throws IOException { final TableName tableName = TableName.valueOf(name.getMethodName()); // Null family (should NOT work) - try { - TEST_UTIL.createTable(tableName, new byte[][]{null}); - fail("Creating a table with a null family passed, should fail"); - } catch(Exception e) {} + TEST_UTIL.createTable(tableName, new byte[][]{null}); + fail("Creating a table with a null family passed, should fail"); } @Test @@ -1244,7 +1240,7 @@ public void testNullEmptyQualifier() throws Exception { assertEmptyResult(result); } catch (Exception e) { - throw new IOException("Using a row with null qualifier threw exception, should "); + throw new IOException("Using a row with null qualifier should not throw exception"); } } }