Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -38,12 +38,9 @@
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.Arguments;

import org.apache.hbase.thirdparty.com.google.common.io.Closeables;

Expand All @@ -65,25 +62,24 @@ public abstract class AbstractTestAsyncTableRegionReplicasRead {

protected static AsyncConnection ASYNC_CONN;

@Rule
public TestName testName = new TestName();
protected Supplier<AsyncTable<?>> getTable;

@Parameter
public Supplier<AsyncTable<?>> getTable;
public static Stream<Arguments> parameters() {
return Stream.of(
Arguments.of((Supplier<AsyncTable<?>>) AbstractTestAsyncTableRegionReplicasRead::getRawTable),
Arguments.of((Supplier<AsyncTable<?>>) AbstractTestAsyncTableRegionReplicasRead::getTable));
}

private static AsyncTable<?> getRawTable() {
return ASYNC_CONN.getTable(TABLE_NAME);
protected AbstractTestAsyncTableRegionReplicasRead(Supplier<AsyncTable<?>> getTable) {
this.getTable = getTable;
}

private static AsyncTable<?> getTable() {
return ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
protected static AsyncTable<?> getRawTable() {
return ASYNC_CONN.getTable(TABLE_NAME);
}

@Parameters
public static List<Object[]> params() {
Comment thread
Apache9 marked this conversation as resolved.
return Arrays.asList(
new Supplier<?>[] { AbstractTestAsyncTableRegionReplicasRead::getRawTable },
new Supplier<?>[] { AbstractTestAsyncTableRegionReplicasRead::getTable });
protected static AsyncTable<?> getTable() {
return ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
}

protected static volatile boolean FAIL_PRIMARY_GET = false;
Expand Down Expand Up @@ -151,7 +147,7 @@ protected static void waitUntilAllReplicasHaveRow(byte[] row) throws IOException
TEST_UTIL.waitFor(30000, () -> allReplicasHaveRow(row));
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
Closeables.close(ASYNC_CONN, true);
TEST_UTIL.shutdownMiniCluster();
Expand All @@ -171,7 +167,7 @@ protected static int getPrimaryGetCount() {
// replicaId = -1 means do not set replica
protected abstract void readAndCheck(AsyncTable<?> table, int replicaId) throws Exception;

@Test
@TestTemplate
public void testNoReplicaRead() throws Exception {
FAIL_PRIMARY_GET = false;
REPLICA_ID_TO_COUNT.clear();
Expand All @@ -183,7 +179,7 @@ public void testNoReplicaRead() throws Exception {
assertEquals(0, getSecondaryGetCount());
}

@Test
@TestTemplate
public void testReplicaRead() throws Exception {
// fail the primary get request
FAIL_PRIMARY_GET = true;
Expand All @@ -198,7 +194,7 @@ public void testReplicaRead() throws Exception {
assertEquals(count, getPrimaryGetCount());
}

@Test
@TestTemplate
public void testReadSpecificReplica() throws Exception {
FAIL_PRIMARY_GET = false;
REPLICA_ID_TO_COUNT.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.net.SocketTimeoutException;
import org.apache.hadoop.hbase.TableName;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -36,9 +36,9 @@ public abstract class AbstractTestCIOperationTimeout extends AbstractTestCITimeo

private TableName tableName;

@Before
@BeforeEach
public void setUp() throws IOException {
tableName = TableName.valueOf(name.getMethodName());
tableName = name.getTableName();
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
.setCoprocessor(SleepAndFailFirstTime.class.getName())
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -37,9 +37,9 @@ public abstract class AbstractTestCIRpcTimeout extends AbstractTestCITimeout {

private TableName tableName;

@Before
@BeforeEach
public void setUp() throws IOException {
tableName = TableName.valueOf(name.getMethodName());
tableName = name.getTableName();
TableDescriptor htd =
TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(SleepCoprocessor.class.getName())
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableNameTestExtension;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.RegionObserver;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* Based class for testing timeout logic.
Expand All @@ -46,8 +46,8 @@ public abstract class AbstractTestCITimeout {

protected static final byte[] FAM_NAM = Bytes.toBytes("f");

@Rule
public final TestName name = new TestName();
@RegisterExtension
protected final TableNameTestExtension name = new TableNameTestExtension();

/**
* This copro sleeps 20 second. The first call it fails. The second time, it works.
Expand Down Expand Up @@ -146,7 +146,7 @@ public void preDelete(final ObserverContext<? extends RegionCoprocessorEnvironme
}
}

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setBoolean(HConstants.STATUS_PUBLISHED, true);
// Up the handlers; this test needs more than usual.
Expand All @@ -157,7 +157,7 @@ public static void setUpBeforeClass() throws Exception {

}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -32,8 +32,8 @@
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

public abstract class AbstractTestRegionLocator {

Expand Down Expand Up @@ -66,7 +66,7 @@ protected static void startClusterAndCreateTable() throws Exception {
UTIL.getAdmin().balancerSwitch(false, true);
}

@After
@AfterEach
public void tearDownAfterTest() throws IOException {
clearCache(TABLE_NAME);
clearCache(TableName.META_TABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public abstract class AbstractTestResultScannerCursor extends AbstractTestScanCursor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import org.apache.hadoop.hbase.regionserver.StoreScanner;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Threads;
import org.junit.AfterClass;
import org.junit.BeforeClass;

public abstract class AbstractTestScanCursor {

Expand Down Expand Up @@ -62,8 +60,7 @@ public abstract class AbstractTestScanCursor {

protected static final int TIMEOUT = 4000;

@BeforeClass
public static void setUpBeforeClass() throws Exception {
protected static void startCluster() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();

conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, TIMEOUT);
Expand Down Expand Up @@ -97,8 +94,7 @@ private static List<Put> createPuts(byte[][] rows, byte[][] families, byte[][] q
return puts;
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
protected static void stopCluster() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.client;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.io.IOException;
import java.net.URI;
Expand Down
Loading
Loading