Skip to content

Commit 55aff4c

Browse files
HBASE-27851 Fix TestListTablesByState which is silently failing due to a surefire bug (#5227)
surefire version 3.0.0-M6 has a bug where tests end up being removed from the test results if they fail with a long exception message. See: https://issues.apache.org/jira/browse/SUREFIRE-2079 TestListTablesByState is currently failing due to an error. However, it is being missed because of the surefire bug. I found this while testing the final surfire 3.0.0 version which fixes the bug and the test then shows up as failing. Co-authored-by: Jonathan Albrecht <[email protected]> Signed-off-by: Duo Zhang <[email protected]>
1 parent 5cea811 commit 55aff4c

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestListTablesByState.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import org.apache.hadoop.hbase.HBaseTestingUtil;
2222
import org.apache.hadoop.hbase.TableName;
2323
import org.apache.hadoop.hbase.client.Admin;
24+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
2425
import org.apache.hadoop.hbase.client.TableDescriptor;
2526
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
2627
import org.apache.hadoop.hbase.testclassification.MasterTests;
2728
import org.apache.hadoop.hbase.testclassification.MediumTests;
29+
import org.apache.hadoop.hbase.util.Bytes;
2830
import org.junit.AfterClass;
2931
import org.junit.Assert;
32+
import org.junit.Before;
3033
import org.junit.BeforeClass;
3134
import org.junit.ClassRule;
3235
import org.junit.Test;
@@ -40,7 +43,12 @@ public class TestListTablesByState {
4043

4144
private static HBaseTestingUtil UTIL;
4245
private static Admin ADMIN;
43-
private final static int SLAVES = 1;
46+
private static final int SLAVES = 1;
47+
private static final byte[] COLUMN = Bytes.toBytes("cf");
48+
private static final TableName TABLE = TableName.valueOf("test");
49+
private static final TableDescriptor TABLE_DESC = TableDescriptorBuilder.newBuilder(TABLE)
50+
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(COLUMN).setMaxVersions(3).build())
51+
.build();
4452

4553
@BeforeClass
4654
public static void setUpBeforeClass() throws Exception {
@@ -49,26 +57,33 @@ public static void setUpBeforeClass() throws Exception {
4957
ADMIN = UTIL.getAdmin();
5058
}
5159

60+
@Before
61+
public void before() throws Exception {
62+
if (ADMIN.tableExists(TABLE)) {
63+
if (ADMIN.isTableEnabled(TABLE)) {
64+
ADMIN.disableTable(TABLE);
65+
}
66+
67+
ADMIN.deleteTable(TABLE);
68+
}
69+
}
70+
5271
@Test
5372
public void testListTableNamesByState() throws Exception {
54-
TableName testTableName = TableName.valueOf("test");
55-
TableDescriptor testTableDesc = TableDescriptorBuilder.newBuilder(testTableName).build();
56-
ADMIN.createTable(testTableDesc);
57-
ADMIN.disableTable(testTableName);
58-
Assert.assertEquals(ADMIN.listTableNamesByState(false).get(0), testTableName);
59-
ADMIN.enableTable(testTableName);
60-
Assert.assertEquals(ADMIN.listTableNamesByState(true).get(0), testTableName);
73+
ADMIN.createTable(TABLE_DESC);
74+
ADMIN.disableTable(TABLE);
75+
Assert.assertEquals(ADMIN.listTableNamesByState(false).get(0), TABLE);
76+
ADMIN.enableTable(TABLE);
77+
Assert.assertEquals(ADMIN.listTableNamesByState(true).get(0), TABLE);
6178
}
6279

6380
@Test
6481
public void testListTableDescriptorByState() throws Exception {
65-
TableName testTableName = TableName.valueOf("test");
66-
TableDescriptor testTableDesc = TableDescriptorBuilder.newBuilder(testTableName).build();
67-
ADMIN.createTable(testTableDesc);
68-
ADMIN.disableTable(testTableName);
69-
Assert.assertEquals(ADMIN.listTableDescriptorsByState(false).get(0), testTableDesc);
70-
ADMIN.enableTable(testTableName);
71-
Assert.assertEquals(ADMIN.listTableDescriptorsByState(true).get(0), testTableDesc);
82+
ADMIN.createTable(TABLE_DESC);
83+
ADMIN.disableTable(TABLE);
84+
Assert.assertEquals(ADMIN.listTableDescriptorsByState(false).get(0).getTableName(), TABLE);
85+
ADMIN.enableTable(TABLE);
86+
Assert.assertEquals(ADMIN.listTableDescriptorsByState(true).get(0).getTableName(), TABLE);
7287
}
7388

7489
@AfterClass

0 commit comments

Comments
 (0)