Skip to content
Open
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.HBaseTestingUtility;
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() {
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.HBaseTestingUtility;
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 for {@link ConnectionImplementation}.
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<RegionCoprocessorEnvironment> e,
}
}

@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 @@ -18,10 +18,10 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;
Expand All @@ -39,9 +39,9 @@
import org.apache.hadoop.hbase.regionserver.Region;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -58,7 +58,7 @@ public abstract class ClientPushbackTestBase {
private static final byte[] qualifier = Bytes.toBytes("q");
private static final long flushSizeBytes = 512;

@BeforeClass
@BeforeAll
public static void setupCluster() throws Exception {
Configuration conf = UTIL.getConfiguration();
// enable backpressure
Expand All @@ -77,7 +77,7 @@ public static void setupCluster() throws Exception {
UTIL.createTable(tableName, family);
}

@AfterClass
@AfterAll
public static void cleanupCluster() throws Exception {
UTIL.shutdownMiniCluster();
}
Expand Down Expand Up @@ -112,23 +112,23 @@ public void testClientTracksServerPushback() throws Exception {

// get the stats for the region hosting our table
ClientBackoffPolicy backoffPolicy = getBackoffPolicy();
assertTrue("Backoff policy is not correctly configured",
backoffPolicy instanceof ExponentialClientBackoffPolicy);
assertTrue(backoffPolicy instanceof ExponentialClientBackoffPolicy,
"Backoff policy is not correctly configured");

ServerStatisticTracker stats = getStatisticsTracker();
assertNotNull("No stats configured for the client!", stats);
assertNotNull(stats, "No stats configured for the client!");
// get the names so we can query the stats
ServerName server = rs.getServerName();
byte[] regionName = region.getRegionInfo().getRegionName();

// check to see we found some load on the memstore
ServerStatistics serverStats = stats.getStats(server);
ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName);
assertEquals("We did not find some load on the memstore", load,
regionStats.getMemStoreLoadPercent());
assertEquals(load, regionStats.getMemStoreLoadPercent(),
"We did not find some load on the memstore");
// check that the load reported produces a nonzero delay
long backoffTime = backoffPolicy.getBackoffTime(server, regionName, serverStats);
assertNotEquals("Reported load does not produce a backoff", 0, backoffTime);
assertNotEquals(0, backoffTime, "Reported load does not produce a backoff");
LOG.debug("Backoff calculated for " + region.getRegionInfo().getRegionNameAsString() + " @ "
+ server + " is " + backoffTime);

Expand All @@ -153,12 +153,12 @@ public void testClientTracksServerPushback() throws Exception {

assertEquals(1, runnerStats.delayRunners.getCount());
assertEquals(1, runnerStats.normalRunners.getCount());
assertEquals("", runnerStats.delayIntevalHist.getSnapshot().getMean(), (double) backoffTime,
0.1);
assertEquals(runnerStats.delayIntevalHist.getSnapshot().getMean(), (double) backoffTime, 0.1,
"");

latch.await(backoffTime * 2, TimeUnit.MILLISECONDS);
assertNotEquals("AsyncProcess did not submit the work time", 0, endTime.get());
assertTrue("AsyncProcess did not delay long enough", endTime.get() - startTime >= backoffTime);
assertNotEquals(0, endTime.get(), "AsyncProcess did not submit the work time");
assertTrue(endTime.get() - startTime >= backoffTime, "AsyncProcess did not delay long enough");
}

@Test
Expand All @@ -173,7 +173,7 @@ public void testMutateRowStats() throws IOException {
mutateRow(mutations);

ServerStatisticTracker stats = getStatisticsTracker();
assertNotNull("No stats configured for the client!", stats);
assertNotNull(stats, "No stats configured for the client!");
// get the names so we can query the stats
ServerName server = rs.getServerName();
byte[] regionName = region.getRegionInfo().getRegionName();
Expand Down
Loading
Loading