@@ -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