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 @@ -19,10 +19,10 @@

import static org.apache.hadoop.hbase.HBaseTestingUtil.fam1;
import static org.apache.hadoop.hbase.HBaseTestingUtil.fam2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -38,7 +38,6 @@
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MultithreadedTestUtil;
Expand Down Expand Up @@ -70,29 +69,23 @@
import org.apache.hadoop.hbase.testclassification.VerySlowRegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WAL;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Testing of HRegion.incrementColumnValue, HRegion.increment, and HRegion.append
*/
@Category({ VerySlowRegionServerTests.class, LargeTests.class }) // Starts 100 threads
@Tag(VerySlowRegionServerTests.TAG)
@Tag(LargeTests.TAG) // Starts 100 threads
public class TestAtomicOperation {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestAtomicOperation.class);

private static final Logger LOG = LoggerFactory.getLogger(TestAtomicOperation.class);
@Rule
public TestName name = new TestName();
private String name;

HRegion region = null;
private HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
Expand All @@ -107,12 +100,13 @@ public class TestAtomicOperation {
static final byte[] row = Bytes.toBytes("rowA");
static final byte[] row2 = Bytes.toBytes("rowB");

@Before
public void setup() {
tableName = Bytes.toBytes(name.getMethodName());
@BeforeEach
public void setup(TestInfo testInfo) {
this.name = testInfo.getTestMethod().get().getName();
tableName = Bytes.toBytes(name);
}

@After
@AfterEach
public void teardown() throws IOException {
if (region != null) {
CacheConfig cacheConfig = region.getStores().get(0).getCacheConfig();
Expand All @@ -133,11 +127,11 @@ public void teardown() throws IOException {

/**
* Test basic append operation. More tests in
* @see org.apache.hadoop.hbase.client.TestFromClientSide#testAppend()
* {@link org.apache.hadoop.hbase.client.FromClientSideTest5#testAppend()}.
*/
@Test
public void testAppend() throws IOException {
initHRegion(tableName, name.getMethodName(), fam1);
initHRegion(tableName, name, fam1);
String v1 =
"Ultimate Answer to the Ultimate Question of Life," + " The Universe, and Everything";
String v2 = " is... 42.";
Expand All @@ -157,7 +151,7 @@ public void testAppend() throws IOException {
@Test
public void testAppendWithMultipleFamilies() throws IOException {
final byte[] fam3 = Bytes.toBytes("colfamily31");
initHRegion(tableName, name.getMethodName(), fam1, fam2, fam3);
initHRegion(tableName, name, fam1, fam2, fam3);
String v1 = "Appended";
String v2 = "Value";

Expand All @@ -166,8 +160,8 @@ public void testAppendWithMultipleFamilies() throws IOException {
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
a.addColumn(fam2, qual2, Bytes.toBytes(v2));
Result result = region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE);
assertTrue("Expected an empty result but result contains " + result.size() + " keys",
result.isEmpty());
assertTrue(result.isEmpty(),
"Expected an empty result but result contains " + result.size() + " keys");

a = new Append(row);
a.addColumn(fam2, qual2, Bytes.toBytes(v1));
Expand All @@ -182,10 +176,10 @@ public void testAppendWithMultipleFamilies() throws IOException {
byte[] actualValue3 = result.getValue(fam3, qual3);
byte[] actualValue4 = result.getValue(fam1, qual2);

assertNotNull("Value1 should bot be null", actualValue1);
assertNotNull("Value2 should bot be null", actualValue2);
assertNotNull("Value3 should bot be null", actualValue3);
assertNotNull("Value4 should bot be null", actualValue4);
assertNotNull(actualValue1, "Value1 should bot be null");
assertNotNull(actualValue2, "Value2 should bot be null");
assertNotNull(actualValue3, "Value3 should bot be null");
assertNotNull(actualValue4, "Value4 should bot be null");
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v1 + v2), actualValue1));
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2 + v1), actualValue2));
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2), actualValue3));
Expand All @@ -194,7 +188,7 @@ public void testAppendWithMultipleFamilies() throws IOException {

@Test
public void testAppendWithNonExistingFamily() throws IOException {
initHRegion(tableName, name.getMethodName(), fam1);
initHRegion(tableName, name, fam1);
final String v1 = "Value";
final Append a = new Append(row);
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
Expand All @@ -212,7 +206,7 @@ public void testAppendWithNonExistingFamily() throws IOException {

@Test
public void testIncrementWithNonExistingFamily() throws IOException {
initHRegion(tableName, name.getMethodName(), fam1);
initHRegion(tableName, name, fam1);
final Increment inc = new Increment(row);
inc.addColumn(fam1, qual1, 1);
inc.addColumn(fam2, qual2, 1);
Expand All @@ -237,7 +231,7 @@ public void testIncrementMultiThreads() throws IOException {
boolean fast = true;
LOG.info("Starting test testIncrementMultiThreads");
// run a with mixed column families (1 and 3 versions)
initHRegion(tableName, name.getMethodName(), new int[] { 1, 3 }, fam1, fam2);
initHRegion(tableName, name, new int[] { 1, 3 }, fam1, fam2);

// Create 100 threads, each will increment by its own quantity. All 100 threads update the
// same row over two column families.
Expand Down Expand Up @@ -343,8 +337,8 @@ public void run() {
Bytes.toLong(result.getValue(fam1, qual2)));
long fam1Increment = Bytes.toLong(result.getValue(fam1, qual1)) * 3;
long fam2Increment = Bytes.toLong(result.getValue(fam2, qual3));
assertEquals("fam1=" + fam1Increment + ", fam2=" + fam2Increment, fam1Increment,
fam2Increment);
assertEquals(fam1Increment, fam2Increment,
"fam1=" + fam1Increment + ", fam2=" + fam2Increment);
}
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -357,7 +351,7 @@ public void run() {
public void testAppendMultiThreads() throws IOException {
LOG.info("Starting test testAppendMultiThreads");
// run a with mixed column families (1 and 3 versions)
initHRegion(tableName, name.getMethodName(), new int[] { 1, 3 }, fam1, fam2);
initHRegion(tableName, name, new int[] { 1, 3 }, fam1, fam2);

int numThreads = 100;
int opsPerThread = 100;
Expand Down Expand Up @@ -421,7 +415,7 @@ public void run() {
@Test
public void testRowMutationMultiThreads() throws IOException {
LOG.info("Starting test testRowMutationMultiThreads");
initHRegion(tableName, name.getMethodName(), fam1);
initHRegion(tableName, name, fam1);

// create 10 threads, each will alternate between adding and
// removing a column
Expand Down Expand Up @@ -512,7 +506,7 @@ public void run() {
public void testMultiRowMutationMultiThreads() throws IOException {

LOG.info("Starting test testMultiRowMutationMultiThreads");
initHRegion(tableName, name.getMethodName(), fam1);
initHRegion(tableName, name, fam1);

// create 10 threads, each will alternate between adding and
// removing a column
Expand Down Expand Up @@ -639,7 +633,7 @@ public void testPutAndCheckAndPutInParallel() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
TableDescriptorBuilder tableDescriptorBuilder =
TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
TableDescriptorBuilder.newBuilder(TableName.valueOf(name));
ColumnFamilyDescriptor columnFamilyDescriptor =
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.regionserver;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -28,7 +28,6 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
Expand All @@ -47,26 +46,26 @@
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ RegionServerTests.class, SmallTests.class })
@Tag(RegionServerTests.TAG)
@Tag(SmallTests.TAG)
public class TestBlocksRead {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBlocksRead.class);

private static final Logger LOG = LoggerFactory.getLogger(TestBlocksRead.class);
@Rule
public TestName testName = new TestName();
private String testName;

@BeforeEach
public void setTestName(TestInfo testInfo) {
this.testName = testInfo.getTestMethod().get().getName();
}

static final BloomType[] BLOOM_TYPE =
new BloomType[] { BloomType.ROWCOL, BloomType.ROW, BloomType.NONE };
Expand All @@ -76,13 +75,13 @@ public class TestBlocksRead {
private final String DIR = TEST_UTIL.getDataTestDir("TestBlocksRead").toString();
private Configuration conf = TEST_UTIL.getConfiguration();

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
// disable compactions in this test.
TEST_UTIL.getConfiguration().setInt("hbase.hstore.compactionThreshold", 10000);
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
EnvironmentEdgeManagerTestHelper.reset();
}
Expand Down Expand Up @@ -164,8 +163,8 @@ private Cell[] getData(String family, String row, List<String> columns, int expB
kvs = region.get(get).rawCells();
long blocksEnd = getBlkAccessCount(cf);
if (expBlocks[i] != -1) {
assertEquals("Blocks Read Check for Bloom: " + bloomType, expBlocks[i],
blocksEnd - blocksStart);
assertEquals(expBlocks[i], blocksEnd - blocksStart,
"Blocks Read Check for Bloom: " + bloomType);
}
System.out.println("Blocks Read for Bloom: " + bloomType + " = " + (blocksEnd - blocksStart)
+ "Expected = " + expBlocks[i]);
Expand Down Expand Up @@ -194,11 +193,11 @@ private void deleteFamily(String family, String row, long version) throws IOExce

private static void verifyData(Cell kv, String expectedRow, String expectedCol,
long expectedVersion) {
assertTrue("RowCheck", CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow)));
assertTrue("ColumnCheck", CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol)));
assertEquals("TSCheck", expectedVersion, kv.getTimestamp());
assertTrue("ValueCheck",
CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion)));
assertTrue(CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow)), "RowCheck");
assertTrue(CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol)), "ColumnCheck");
assertEquals(expectedVersion, kv.getTimestamp(), "TSCheck");
assertTrue(CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion)),
"ValueCheck");
}

private static long getBlkAccessCount(byte[] cf) {
Expand All @@ -213,7 +212,7 @@ public void testBlocksRead() throws Exception {
byte[] TABLE = Bytes.toBytes("testBlocksRead");
String FAMILY = "cf1";
Cell[] kvs;
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
this.region = initHRegion(TABLE, testName, conf, FAMILY);

try {
putData(FAMILY, "row", "col1", 1);
Expand Down Expand Up @@ -267,7 +266,7 @@ public void testLazySeekBlocksRead() throws Exception {
byte[] TABLE = Bytes.toBytes("testLazySeekBlocksRead");
String FAMILY = "cf1";
Cell[] kvs;
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
this.region = initHRegion(TABLE, testName, conf, FAMILY);

try {
// File 1
Expand Down Expand Up @@ -373,7 +372,7 @@ public void testBlocksStoredWhenCachingDisabled() throws Exception {
String FAMILY = "cf1";

BlockCache blockCache = BlockCacheFactory.createBlockCache(conf);
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY, blockCache);
this.region = initHRegion(TABLE, testName, conf, FAMILY, blockCache);

try {
putData(FAMILY, "row", "col1", 1);
Expand Down Expand Up @@ -417,7 +416,7 @@ public void testLazySeekBlocksReadWithDelete() throws Exception {
byte[] TABLE = Bytes.toBytes("testLazySeekBlocksReadWithDelete");
String FAMILY = "cf1";
Cell[] kvs;
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
this.region = initHRegion(TABLE, testName, conf, FAMILY);
try {
deleteFamily(FAMILY, "row", 200);
for (int i = 0; i < 100; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
package org.apache.hadoop.hbase.regionserver;

import static org.apache.hadoop.hbase.HTestConst.addContent;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ExtendedCell;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -43,19 +42,15 @@
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@SuppressWarnings("deprecation")
@Category({ RegionServerTests.class, SmallTests.class })
@Tag(RegionServerTests.TAG)
@Tag(SmallTests.TAG)
public class TestBlocksScanned {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBlocksScanned.class);

private static byte[] FAMILY = Bytes.toBytes("family");
private static byte[] COL = Bytes.toBytes("col");
private static byte[] START_KEY = Bytes.toBytes("aaa");
Expand All @@ -66,7 +61,7 @@ public class TestBlocksScanned {
private Configuration conf;
private Path testDir;

@Before
@BeforeEach
public void setUp() throws Exception {
TEST_UTIL = new HBaseTestingUtil();
conf = TEST_UTIL.getConfiguration();
Expand Down
Loading