HBASE-26643 Addendum align the test code with branch-2

This commit is contained in:
Duo Zhang 2022-01-08 00:11:28 +08:00
parent 443bf30a5d
commit 69520ad199

View File

@ -19,15 +19,15 @@ package org.apache.hadoop.hbase.master.procedure;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.StartMiniClusterOption;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.AsyncAdmin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.Table;
@ -59,7 +59,11 @@ public class TestCreateTableNoRegionServer {
private static final Logger LOG = LoggerFactory.getLogger(TestCreateTableNoRegionServer.class); private static final Logger LOG = LoggerFactory.getLogger(TestCreateTableNoRegionServer.class);
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static TableName TABLE_NAME = TableName.valueOf("test");
private static byte[] FAMILY = Bytes.toBytes("f1");
private static CountDownLatch ARRIVE; private static CountDownLatch ARRIVE;
@ -77,8 +81,9 @@ public class TestCreateTableNoRegionServer {
if (e.getClassName().equals(CreateTableProcedure.class.getName()) && if (e.getClassName().equals(CreateTableProcedure.class.getName()) &&
e.getMethodName().equals("executeFromState")) { e.getMethodName().equals("executeFromState")) {
for (Procedure<?> proc : getProcedures()) { for (Procedure<?> proc : getProcedures()) {
if (proc instanceof CreateTableProcedure && ((CreateTableProcedure) proc) if (proc instanceof CreateTableProcedure && !proc.isFinished() &&
.getCurrentStateId() == CreateTableState.CREATE_TABLE_ASSIGN_REGIONS_VALUE) { ((CreateTableProcedure) proc)
.getCurrentStateId() == CreateTableState.CREATE_TABLE_ASSIGN_REGIONS_VALUE) {
return true; return true;
} }
} }
@ -107,7 +112,7 @@ public class TestCreateTableNoRegionServer {
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
UTIL.startMiniCluster( UTIL.startMiniCluster(
StartTestingClusterOption.builder().masterClass(HMasterForTest.class).build()); StartMiniClusterOption.builder().masterClass(HMasterForTest.class).build());
// this may cause dead lock if there is no live region server and want to start a new server. // this may cause dead lock if there is no live region server and want to start a new server.
// In JmxCacheBuster we will reinitialize the metrics system so it will get some metrics which // In JmxCacheBuster we will reinitialize the metrics system so it will get some metrics which
// will need to access meta, since there is no region server, the request will hang there for a // will need to access meta, since there is no region server, the request will hang there for a
@ -124,12 +129,12 @@ public class TestCreateTableNoRegionServer {
@Test @Test
public void testCreate() throws Exception { public void testCreate() throws Exception {
TableDescriptor td = TableDescriptorBuilder.newBuilder(TableName.valueOf("test")) TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLE_NAME)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of("f1")).build(); .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
AsyncAdmin admin = UTIL.getAsyncConnection().getAdmin(); Admin admin = UTIL.getAdmin();
ARRIVE = new CountDownLatch(1); ARRIVE = new CountDownLatch(1);
RESUME = new CountDownLatch(1); RESUME = new CountDownLatch(1);
CompletableFuture<Void> future = admin.createTable(td); Future<Void> future = admin.createTableAsync(td);
ARRIVE.await(); ARRIVE.await();
UTIL.getMiniHBaseCluster().stopRegionServer(0).join(); UTIL.getMiniHBaseCluster().stopRegionServer(0).join();
@ -153,9 +158,9 @@ public class TestCreateTableNoRegionServer {
// the creation should finally be done // the creation should finally be done
future.get(30, TimeUnit.SECONDS); future.get(30, TimeUnit.SECONDS);
// make sure we could put to the table // make sure we could put to the table
try (Table table = UTIL.getConnection().getTableBuilder(td.getTableName(), null) try (Table table = UTIL.getConnection().getTableBuilder(TABLE_NAME, null)
.setOperationTimeout(5000).build()) { .setOperationTimeout(5000).build()) {
table.put(new Put(Bytes.toBytes(0)).addColumn(td.getColumnFamilies()[0].getName(), table.put(new Put(Bytes.toBytes(0)).addColumn(FAMILY,
Bytes.toBytes("q"), Bytes.toBytes(0))); Bytes.toBytes("q"), Bytes.toBytes(0)));
} }
} }