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,9 +17,9 @@
*/
package org.apache.hadoop.hbase.quotas;

import static org.junit.Assert.assertEquals;
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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -31,6 +31,7 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
Expand Down Expand Up @@ -61,7 +62,6 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -80,11 +80,11 @@ public class SpaceQuotaHelperForTests {
public static final long ONE_GIGABYTE = ONE_MEGABYTE * ONE_KILOBYTE;

private final HBaseTestingUtil testUtil;
private final TestName testName;
private final Supplier<String> testName;
private final AtomicLong counter;
private static final int NUM_RETRIES = 10;

public SpaceQuotaHelperForTests(HBaseTestingUtil testUtil, TestName testName,
public SpaceQuotaHelperForTests(HBaseTestingUtil testUtil, Supplier<String> testName,
AtomicLong counter) {
this.testUtil = Objects.requireNonNull(testUtil);
this.testName = Objects.requireNonNull(testName);
Expand Down Expand Up @@ -228,12 +228,13 @@ void verifyViolation(SpaceViolationPolicy policyToViolate, TableName tn, Mutatio
assertTrue(
msg.contains("TableNotEnabledException") || msg.contains(policyToViolate.name()));
} else {
assertTrue("Expected exception message to contain the word '" + policyToViolate.name()
+ "', but was " + msg, msg.contains(policyToViolate.name()));
assertTrue(msg.contains(policyToViolate.name()),
"Expected exception message to contain the word '" + policyToViolate.name()
+ "', but was " + msg);
}
}
assertTrue("Expected to see an exception writing data to a table exceeding its quota",
sawError);
assertTrue(sawError,
"Expected to see an exception writing data to a table exceeding its quota");
}

/**
Expand Down Expand Up @@ -273,7 +274,7 @@ void verifyNoViolation(TableName tn, Mutation m) throws Exception {
scanner.close();
}
}
assertTrue("Expected to succeed in writing data to a table not having quota ", sawSuccess);
assertTrue(sawSuccess, "Expected to succeed in writing data to a table not having quota ");
}

/**
Expand All @@ -286,8 +287,8 @@ void verifyTableUsageSnapshotForSpaceQuotaExist(TableName tn) throws Exception {
ResultScanner rs = quotaTable.getScanner(s);
sawUsageSnapshot = (rs.next() != null);
}
assertTrue("Expected to succeed in getting table usage snapshots for space quota",
sawUsageSnapshot);
assertTrue(sawUsageSnapshot,
"Expected to succeed in getting table usage snapshots for space quota");
}

/**
Expand Down Expand Up @@ -515,7 +516,7 @@ TableName getNextTableName() {
}

TableName getNextTableName(String namespace) {
return TableName.valueOf(namespace, testName.getMethodName() + counter.getAndIncrement());
return TableName.valueOf(namespace, testName.get() + counter.getAndIncrement());
}

TableName createTable() throws Exception {
Expand Down Expand Up @@ -565,7 +566,7 @@ TableName createTableWithRegions(Admin admin, String namespace, int numRegions,
TableName createTableInNamespace(NamespaceDescriptor nd) throws Exception {
final Admin admin = testUtil.getAdmin();
final TableName tn =
TableName.valueOf(nd.getName(), testName.getMethodName() + counter.getAndIncrement());
TableName.valueOf(nd.getName(), testName.get() + counter.getAndIncrement());

// Delete the old table
if (admin.tableExists(tn)) {
Expand Down Expand Up @@ -606,7 +607,7 @@ void partitionTablesByQuotaTarget(Multimap<TableName, QuotaSettings> quotas,
Map<byte[], List<Path>> generateFileToLoad(TableName tn, int numFiles, int numRowsPerFile)
throws Exception {
FileSystem fs = testUtil.getTestFileSystem();
Path baseDir = new Path(fs.getHomeDirectory(), testName.getMethodName() + "_files");
Path baseDir = new Path(fs.getHomeDirectory(), testName.get() + "_files");
fs.mkdirs(baseDir);
List<Path> hfiles = new ArrayList<>();
for (int i = 1; i <= numFiles; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,36 @@
*/
package org.apache.hadoop.hbase.quotas;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus;
import org.apache.hadoop.hbase.quotas.policies.DefaultViolationPolicyEnforcement;
import org.apache.hadoop.hbase.quotas.policies.MissingSnapshotViolationPolicyEnforcement;
import org.apache.hadoop.hbase.quotas.policies.NoWritesViolationPolicyEnforcement;
import org.apache.hadoop.hbase.regionserver.RegionServerServices;
import org.apache.hadoop.hbase.testclassification.SmallTests;
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;

/**
* Test class for {@link ActivePolicyEnforcement}.
*/
@Category(SmallTests.class)
@Tag(SmallTests.TAG)
public class TestActivePolicyEnforcement {

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

private RegionServerServices rss;

@Before
@BeforeEach
public void setup() {
rss = mock(RegionServerServices.class);
}
Expand All @@ -73,8 +67,9 @@ public void testNoPolicyReturnsNoopEnforcement() {
SpaceViolationPolicyEnforcement enforcement =
ape.getPolicyEnforcement(TableName.valueOf("nonexistent"));
assertNotNull(enforcement);
assertTrue("Expected an instance of MissingSnapshotViolationPolicyEnforcement, but got "
+ enforcement.getClass(), enforcement instanceof MissingSnapshotViolationPolicyEnforcement);
assertTrue(enforcement instanceof MissingSnapshotViolationPolicyEnforcement,
"Expected an instance of MissingSnapshotViolationPolicyEnforcement, but got "
+ enforcement.getClass());
}

@Test
Expand All @@ -84,7 +79,7 @@ public void testNoBulkLoadChecksOnNoSnapshot() {
Collections.<TableName, SpaceQuotaSnapshot> emptyMap(), mock(RegionServerServices.class));
SpaceViolationPolicyEnforcement enforcement =
ape.getPolicyEnforcement(TableName.valueOf("nonexistent"));
assertFalse("Should not check bulkloads", enforcement.shouldCheckBulkLoads());
assertFalse(enforcement.shouldCheckBulkLoads(), "Should not check bulkloads");
}

@Test
Expand All @@ -109,10 +104,10 @@ public void testNonViolatingQuotaCachesPolicyEnforcment() {
final ActivePolicyEnforcement ape =
new ActivePolicyEnforcement(Collections.emptyMap(), snapshots, rss);
SpaceViolationPolicyEnforcement policyEnforcement = ape.getPolicyEnforcement(tableName);
assertTrue("Found the wrong class: " + policyEnforcement.getClass(),
policyEnforcement instanceof DefaultViolationPolicyEnforcement);
assertTrue(policyEnforcement instanceof DefaultViolationPolicyEnforcement,
"Found the wrong class: " + policyEnforcement.getClass());
SpaceViolationPolicyEnforcement copy = ape.getPolicyEnforcement(tableName);
assertTrue("Expected the instance to be cached", policyEnforcement == copy);
assertTrue(policyEnforcement == copy, "Expected the instance to be cached");
Entry<TableName, SpaceViolationPolicyEnforcement> entry =
ape.getLocallyCachedPolicies().entrySet().iterator().next();
assertTrue(policyEnforcement == entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -38,34 +37,31 @@
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
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.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ RegionServerTests.class, MediumTests.class })
@Tag(RegionServerTests.TAG)
@Tag(MediumTests.TAG)
public class TestAtomicReadQuota {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestAtomicReadQuota.class);
private static final Logger LOG = LoggerFactory.getLogger(TestAtomicReadQuota.class);
private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
private static final TableName TABLE_NAME = TableName.valueOf(UUID.randomUUID().toString());
private static final byte[] FAMILY = Bytes.toBytes("cf");
private static final byte[] QUALIFIER = Bytes.toBytes("q");

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL);
EnvironmentEdgeManager.reset();
TEST_UTIL.deleteTable(TABLE_NAME);
TEST_UTIL.shutdownMiniCluster();
}

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true);
TEST_UTIL.getConfiguration().setInt(QuotaCache.REFRESH_CONF_KEY, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.doScans;
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh;
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.waitMinuteQuota;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -38,20 +37,17 @@
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ RegionServerTests.class, LargeTests.class })
@Tag(RegionServerTests.TAG)
@Tag(LargeTests.TAG)
public class TestBlockBytesScannedQuota {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBlockBytesScannedQuota.class);

private final static Logger LOG = LoggerFactory.getLogger(TestBlockBytesScannedQuota.class);

Expand All @@ -63,7 +59,7 @@ public class TestBlockBytesScannedQuota {
private static final TableName TABLE_NAME = TableName.valueOf("BlockBytesScannedQuotaTest");
private static final long MAX_SCANNER_RESULT_SIZE = 100 * 1024 * 1024;

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
// client should fail fast
TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 10);
Expand All @@ -86,14 +82,14 @@ public static void setUpBeforeClass() throws Exception {
TEST_UTIL.waitTableAvailable(TABLE_NAME);
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
EnvironmentEdgeManager.reset();
TEST_UTIL.deleteTable(TABLE_NAME);
TEST_UTIL.shutdownMiniCluster();
}

@After
@AfterEach
public void tearDown() throws Exception {
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerNamespaceCacheRefresh;
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerTableCacheRefresh;
import static org.apache.hadoop.hbase.quotas.ThrottleQuotaTestUtil.triggerUserCacheRefresh;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.TableName;
Expand All @@ -38,20 +37,16 @@
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category({ RegionServerTests.class, LargeTests.class })
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag(RegionServerTests.TAG)
@Tag(LargeTests.TAG)
public class TestClusterScopeQuotaThrottle {

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

private final static int REFRESH_TIME = 30 * 60000;
private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();

Expand All @@ -67,7 +62,7 @@ public class TestClusterScopeQuotaThrottle {
private final static TableName TABLE_NAME = TableName.valueOf(NAMESPACE, "TestTable");
private static Table table;

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true);
TEST_UTIL.getConfiguration().setInt(QuotaCache.REFRESH_CONF_KEY, REFRESH_TIME);
Expand All @@ -92,7 +87,7 @@ public static void setUpBeforeClass() throws Exception {
.build();
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
EnvironmentEdgeManager.reset();
for (int i = 0; i < tables.length; ++i) {
Expand All @@ -106,7 +101,7 @@ public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}

@After
@AfterEach
public void tearDown() throws Exception {
ThrottleQuotaTestUtil.clearQuotaCache(TEST_UTIL);
}
Expand Down
Loading
Loading