@@ -319,53 +319,97 @@ public void testAdminEnDisableTable() throws Exception {
319
319
Configuration conf = ObHTableTestUtil .newConfiguration ();
320
320
Connection connection = ConnectionFactory .createConnection (conf );
321
321
Admin admin = connection .getAdmin ();
322
- admin .disableTable (TableName .valueOf ("test_multi_cf" ));
323
322
assertTrue (admin .tableExists (TableName .valueOf ("n1" , "test" )));
324
323
assertTrue (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
325
- // disable a non-existed table
326
- IOException thrown = assertThrows (IOException .class ,
327
- () -> {
328
- admin .disableTable (TableName .valueOf ("tablegroup_not_exists" ));
329
- });
330
- assertTrue (thrown .getCause () instanceof ObTableException );
331
- Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
324
+ // 1. disable a non-existed table
325
+ {
326
+ IOException thrown = assertThrows (IOException .class ,
327
+ () -> {
328
+ admin .disableTable (TableName .valueOf ("tablegroup_not_exists" ));
329
+ });
330
+ assertTrue (thrown .getCause () instanceof ObTableException );
331
+ Assert .assertEquals (ResultCodes .OB_TABLEGROUP_NOT_EXIST .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
332
+ }
333
+ // 2. write an enabled table, should succeed
334
+ {
335
+ if (admin .isTableDisabled (TableName .valueOf ("test_multi_cf" ))) {
336
+ admin .enableTable (TableName .valueOf ("test_multi_cf" ));
337
+ }
338
+ batchInsert (10 , "test_multi_cf" );
339
+ batchGet (10 , "test_multi_cf" );
340
+ }
332
341
333
- // write an enabled table, should succeed
334
- batchInsert (10 , "test_multi_ch" );
335
- // disable a disabled table
336
- thrown = assertThrows (IOException .class ,
337
- () -> {
338
- admin .disableTable (TableName .valueOf ("test_multi_cf" ));
339
- });
340
- assertTrue (thrown .getCause () instanceof ObTableException );
341
- Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_DISABLED .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
342
+ // 3. disable a enable table
343
+ {
344
+ if (admin .isTableEnabled (TableName .valueOf ("test_multi_cf" ))) {
345
+ admin .disableTable (TableName .valueOf ("test_multi_cf" ));
346
+ }
347
+ // write and read disable table, should fail
348
+ try {
349
+ batchInsert (10 , "test_multi_cf" );
350
+ Assert .fail ();
351
+ } catch (IOException ex ) {
352
+ Assert .assertTrue (ex .getCause () instanceof ObTableException );
353
+ System .out .println (ex .getCause ().getMessage ());
354
+ }
355
+ try {
356
+ batchGet (10 , "test_multi_cf" );
357
+ Assert .fail ();
358
+ } catch (IOException ex ) {
359
+ Assert .assertTrue (ex .getCause () instanceof ObTableException );
360
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_ENABLED .errorCode ,
361
+ ((ObTableException ) ex .getCause ()).getErrorCode ());
362
+ }
342
363
343
- // write an enabled table, should fail
344
- batchInsert (10 , "test_multi_ch" );
345
- enDisableRead (10 , "test_multi_ch" );
364
+ }
346
365
347
- // enable a disabled table
348
- admin .enableTable (TableName .valueOf ("test_multi_cf" ));
366
+ // 4. enable a disabled table
367
+ {
368
+ if (admin .isTableDisabled (TableName .valueOf ("test_multi_cf" ))) {
369
+ admin .enableTable (TableName .valueOf ("test_multi_cf" ));
370
+ }
371
+ // write an enabled table, should succeed
372
+ batchInsert (10 , "test_multi_cf" );
373
+ batchGet (10 , "test_multi_cf" );
374
+ }
349
375
350
- // write an enabled table, should succeed
351
- batchInsert (10 , "test_multi_ch" );
352
- enDisableRead (10 , "test_multi_ch" );
376
+ // 5. enable an enabled table
377
+ {
378
+ if (admin .isTableDisabled (TableName .valueOf ("n1" , "test" ))) {
379
+ admin .enableTable (TableName .valueOf ("n1" , "test" ));
380
+ }
381
+ try {
382
+ admin .enableTable (TableName .valueOf ("n1" , "test" ));
383
+ Assert .fail ();
384
+ } catch (IOException ex ) {
385
+ Assert .assertTrue (ex .getCause () instanceof ObTableException );
386
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_DISABLED .errorCode ,
387
+ ((ObTableException ) ex .getCause ()).getErrorCode ());
388
+ }
389
+ }
353
390
354
- // enable an enabled table
355
- thrown = assertThrows (IOException .class ,
356
- () -> {
357
- admin .disableTable (TableName .valueOf ("n1" , "test" ));
358
- });
359
- assertTrue (thrown .getCause () instanceof ObTableException );
360
- Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_ENABLED .errorCode , ((ObTableException ) thrown .getCause ()).getErrorCode ());
391
+ // 6. disable a disabled table
392
+ {
393
+ if (admin .isTableEnabled (TableName .valueOf ("n1" , "test" ))) {
394
+ admin .disableTable (TableName .valueOf ("n1" , "test" ));
395
+ }
396
+ try {
397
+ admin .disableTable (TableName .valueOf ("n1" , "test" ));
398
+ Assert .fail ();
399
+ } catch (IOException ex ) {
400
+ Assert .assertTrue (ex .getCause () instanceof ObTableException );
401
+ Assert .assertEquals (ResultCodes .OB_KV_TABLE_NOT_ENABLED .errorCode ,
402
+ ((ObTableException ) ex .getCause ()).getErrorCode ());
403
+ }
404
+ }
361
405
362
- admin .deleteTable (TableName .valueOf ("n1" , "test" ));
363
406
admin .deleteTable (TableName .valueOf ("test_multi_cf" ));
364
- assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test" )));
365
407
assertFalse (admin .tableExists (TableName .valueOf ("test_multi_cf" )));
408
+ admin .deleteTable (TableName .valueOf ("n1" , "test" ));
409
+ assertFalse (admin .tableExists (TableName .valueOf ("n1" , "test" )));
366
410
}
367
411
368
- private void enDisableRead (int rows , String tablegroup ) throws Exception {
412
+ private void batchGet (int rows , String tablegroup ) throws Exception {
369
413
Configuration conf = ObHTableTestUtil .newConfiguration ();
370
414
Connection connection = ConnectionFactory .createConnection (conf );
371
415
Table table = connection .getTable (TableName .valueOf (tablegroup ));
0 commit comments