Skip to content

Commit b7aeca3

Browse files
anmolnarApache9
authored andcommitted
HBASE-22382 Refactor tests in TestFromClientSide (apache#385)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent e13d734 commit b7aeca3

File tree

2 files changed

+82
-65
lines changed

2 files changed

+82
-65
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import static org.apache.hadoop.hbase.HConstants.HBASE_MASTER_LOGCLEANER_PLUGINS;
2222
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK;
2323

24+
import com.google.protobuf.Descriptors;
25+
import com.google.protobuf.Service;
2426
import java.io.IOException;
2527
import java.io.InterruptedIOException;
2628
import java.lang.reflect.Constructor;
@@ -50,12 +52,10 @@
5052
import java.util.function.Function;
5153
import java.util.regex.Pattern;
5254
import java.util.stream.Collectors;
53-
5455
import javax.servlet.ServletException;
5556
import javax.servlet.http.HttpServlet;
5657
import javax.servlet.http.HttpServletRequest;
5758
import javax.servlet.http.HttpServletResponse;
58-
5959
import org.apache.commons.lang3.StringUtils;
6060
import org.apache.hadoop.conf.Configuration;
6161
import org.apache.hadoop.fs.Path;
@@ -190,9 +190,6 @@
190190
import org.apache.hadoop.hbase.security.AccessDeniedException;
191191
import org.apache.hadoop.hbase.security.SecurityConstants;
192192
import org.apache.hadoop.hbase.security.UserProvider;
193-
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
194-
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState;
195-
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
196193
import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
197194
import org.apache.hadoop.hbase.trace.TraceUtil;
198195
import org.apache.hadoop.hbase.util.Addressing;
@@ -226,13 +223,15 @@
226223
import org.slf4j.Logger;
227224
import org.slf4j.LoggerFactory;
228225

229-
import com.google.protobuf.Descriptors;
230-
import com.google.protobuf.Service;
231226
import com.xiaomi.infra.thirdparty.com.google.common.annotations.VisibleForTesting;
232227
import com.xiaomi.infra.thirdparty.com.google.common.collect.ImmutableSet;
233228
import com.xiaomi.infra.thirdparty.com.google.common.collect.Lists;
234229
import com.xiaomi.infra.thirdparty.com.google.common.collect.Maps;
235230

231+
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
232+
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState;
233+
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
234+
236235
/**
237236
* HMaster is the "master server" for HBase. An HBase cluster has one active
238237
* master. If many masters are started, all compete. Whichever wins goes on to

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,21 +1162,25 @@ public void testSingleRowMultipleFamily() throws Exception {
11621162

11631163
}
11641164

1165-
@Test
1166-
public void testNull() throws Exception {
1167-
final TableName tableName = TableName.valueOf(name.getMethodName());
1168-
1165+
@Test(expected = IOException.class)
1166+
public void testNullTableName() throws IOException {
11691167
// Null table name (should NOT work)
1170-
try {
1171-
TEST_UTIL.createTable((TableName)null, FAMILY);
1172-
fail("Creating a table with null name passed, should have failed");
1173-
} catch(Exception e) {}
1168+
TEST_UTIL.createTable((TableName)null, FAMILY);
1169+
fail("Creating a table with null name passed, should have failed");
1170+
}
1171+
1172+
@Test(expected = IOException.class)
1173+
public void testNullFamilyName() throws IOException {
1174+
final TableName tableName = TableName.valueOf(name.getMethodName());
11741175

11751176
// Null family (should NOT work)
1176-
try {
1177-
TEST_UTIL.createTable(tableName, new byte[][]{null});
1178-
fail("Creating a table with a null family passed, should fail");
1179-
} catch(Exception e) {}
1177+
TEST_UTIL.createTable(tableName, new byte[][]{null});
1178+
fail("Creating a table with a null family passed, should fail");
1179+
}
1180+
1181+
@Test
1182+
public void testNullRowAndQualifier() throws Exception {
1183+
final TableName tableName = TableName.valueOf(name.getMethodName());
11801184

11811185
Table ht = TEST_UTIL.createTable(tableName, FAMILY);
11821186

@@ -1206,66 +1210,78 @@ public void testNull() throws Exception {
12061210
Result result = ht.get(get);
12071211
assertEmptyResult(result);
12081212
}
1213+
}
12091214

1210-
// Use a new table
1211-
ht = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName() + "2"), FAMILY);
1215+
@Test
1216+
public void testNullEmptyQualifier() throws Exception {
1217+
final TableName tableName = TableName.valueOf(name.getMethodName());
12121218

1213-
// Empty qualifier, byte[0] instead of null (should work)
1214-
try {
1215-
Put put = new Put(ROW);
1216-
put.addColumn(FAMILY, HConstants.EMPTY_BYTE_ARRAY, VALUE);
1217-
ht.put(put);
1219+
try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) {
12181220

1219-
getTestNull(ht, ROW, FAMILY, VALUE);
1221+
// Empty qualifier, byte[0] instead of null (should work)
1222+
try {
1223+
Put put = new Put(ROW);
1224+
put.addColumn(FAMILY, HConstants.EMPTY_BYTE_ARRAY, VALUE);
1225+
ht.put(put);
12201226

1221-
scanTestNull(ht, ROW, FAMILY, VALUE);
1227+
getTestNull(ht, ROW, FAMILY, VALUE);
12221228

1223-
// Flush and try again
1229+
scanTestNull(ht, ROW, FAMILY, VALUE);
12241230

1225-
TEST_UTIL.flush();
1231+
// Flush and try again
12261232

1227-
getTestNull(ht, ROW, FAMILY, VALUE);
1233+
TEST_UTIL.flush();
12281234

1229-
scanTestNull(ht, ROW, FAMILY, VALUE);
1235+
getTestNull(ht, ROW, FAMILY, VALUE);
12301236

1231-
Delete delete = new Delete(ROW);
1232-
delete.addColumns(FAMILY, HConstants.EMPTY_BYTE_ARRAY);
1233-
ht.delete(delete);
1237+
scanTestNull(ht, ROW, FAMILY, VALUE);
1238+
1239+
Delete delete = new Delete(ROW);
1240+
delete.addColumns(FAMILY, HConstants.EMPTY_BYTE_ARRAY);
1241+
ht.delete(delete);
12341242

1235-
Get get = new Get(ROW);
1236-
Result result = ht.get(get);
1237-
assertEmptyResult(result);
1243+
Get get = new Get(ROW);
1244+
Result result = ht.get(get);
1245+
assertEmptyResult(result);
12381246

1239-
} catch(Exception e) {
1240-
throw new IOException("Using a row with null qualifier threw exception, should ");
1247+
} catch (Exception e) {
1248+
throw new IOException("Using a row with null qualifier should not throw exception");
1249+
}
12411250
}
1251+
}
12421252

1243-
// Null value
1244-
try {
1245-
Put put = new Put(ROW);
1246-
put.addColumn(FAMILY, QUALIFIER, null);
1247-
ht.put(put);
1248-
1249-
Get get = new Get(ROW);
1250-
get.addColumn(FAMILY, QUALIFIER);
1251-
Result result = ht.get(get);
1252-
assertSingleResult(result, ROW, FAMILY, QUALIFIER, null);
1253-
1254-
Scan scan = new Scan();
1255-
scan.addColumn(FAMILY, QUALIFIER);
1256-
result = getSingleScanResult(ht, scan);
1257-
assertSingleResult(result, ROW, FAMILY, QUALIFIER, null);
1258-
1259-
Delete delete = new Delete(ROW);
1260-
delete.addColumns(FAMILY, QUALIFIER);
1261-
ht.delete(delete);
1262-
1263-
get = new Get(ROW);
1264-
result = ht.get(get);
1265-
assertEmptyResult(result);
1253+
@Test
1254+
public void testNullValue() throws IOException {
1255+
final TableName tableName = TableName.valueOf(name.getMethodName());
12661256

1267-
} catch(Exception e) {
1268-
throw new IOException("Null values should be allowed, but threw exception");
1257+
try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) {
1258+
// Null value
1259+
try {
1260+
Put put = new Put(ROW);
1261+
put.addColumn(FAMILY, QUALIFIER, null);
1262+
ht.put(put);
1263+
1264+
Get get = new Get(ROW);
1265+
get.addColumn(FAMILY, QUALIFIER);
1266+
Result result = ht.get(get);
1267+
assertSingleResult(result, ROW, FAMILY, QUALIFIER, null);
1268+
1269+
Scan scan = new Scan();
1270+
scan.addColumn(FAMILY, QUALIFIER);
1271+
result = getSingleScanResult(ht, scan);
1272+
assertSingleResult(result, ROW, FAMILY, QUALIFIER, null);
1273+
1274+
Delete delete = new Delete(ROW);
1275+
delete.addColumns(FAMILY, QUALIFIER);
1276+
ht.delete(delete);
1277+
1278+
get = new Get(ROW);
1279+
result = ht.get(get);
1280+
assertEmptyResult(result);
1281+
1282+
} catch (Exception e) {
1283+
throw new IOException("Null values should be allowed, but threw exception");
1284+
}
12691285
}
12701286
}
12711287

@@ -1540,6 +1556,7 @@ public void testVersions() throws Exception {
15401556
}
15411557

15421558
@Test
1559+
@SuppressWarnings("checkstyle:MethodLength")
15431560
public void testVersionLimits() throws Exception {
15441561
final TableName tableName = TableName.valueOf(name.getMethodName());
15451562
byte [][] FAMILIES = makeNAscii(FAMILY, 3);
@@ -5975,6 +5992,7 @@ public void testNullWithReverseScan() throws Exception {
59755992
}
59765993

59775994
@Test
5995+
@SuppressWarnings("checkstyle:MethodLength")
59785996
public void testDeletesWithReverseScan() throws Exception {
59795997
final TableName tableName = TableName.valueOf(name.getMethodName());
59805998
byte[][] ROWS = makeNAscii(ROW, 6);

0 commit comments

Comments
 (0)