Skip to content
Merged
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;

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 edu.umd.cs.findbugs.annotations.Nullable;
import java.io.Closeable;
Expand Down Expand Up @@ -2013,11 +2013,11 @@ public void verifyNumericRows(Table table, final byte[] f, int startRow, int end
get.setReplicaId(replicaId);
get.setConsistency(Consistency.TIMELINE);
Result result = table.get(get);
assertTrue(failMsg, result.containsColumn(f, null));
assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
assertTrue(result.containsColumn(f, null), failMsg);
assertEquals(1, result.getColumnCells(f, null).size(), failMsg);
Cell cell = result.getColumnLatestCell(f, null);
assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(),
cell.getValueOffset(), cell.getValueLength()));
assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength()), failMsg);
}
}

Expand All @@ -2044,14 +2044,14 @@ public void verifyNumericRows(HRegion region, final byte[] f, int startRow, int
Result result = region.get(new Get(data));

boolean hasResult = result != null && !result.isEmpty();
assertEquals(failMsg + result, present, hasResult);
assertEquals(present, hasResult, failMsg + result);
if (!present) continue;

assertTrue(failMsg, result.containsColumn(f, null));
assertEquals(failMsg, 1, result.getColumnCells(f, null).size());
assertTrue(result.containsColumn(f, null), failMsg);
assertEquals(1, result.getColumnCells(f, null).size(), failMsg);
Cell cell = result.getColumnLatestCell(f, null);
assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(),
cell.getValueOffset(), cell.getValueLength()));
assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength()), failMsg);
}
}

Expand Down Expand Up @@ -3408,8 +3408,8 @@ public void assertRegionOnlyOnServer(final RegionInfo hri, final ServerName serv
}
Collection<HRegion> hrs = rs.getOnlineRegionsLocalContext();
for (HRegion r : hrs) {
assertTrue("Region should not be double assigned",
r.getRegionInfo().getRegionId() != hri.getRegionId());
assertTrue(r.getRegionInfo().getRegionId() != hri.getRegionId(),
"Region should not be double assigned");
}
}
return; // good, we are happy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_CLOSE_KEY;
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_SPLIT_KEY;
import static org.apache.hadoop.hbase.io.hfile.CacheConfig.PREFETCH_BLOCKS_ON_OPEN_KEY;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -42,26 +42,18 @@
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ MiscTests.class, LargeTests.class })
public class TestCacheEviction {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCacheEviction.class);
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

private static final Logger LOG = LoggerFactory.getLogger(TestCacheEviction.class);
@Tag(MiscTests.TAG)
@Tag(LargeTests.TAG)
public class TestCacheEviction {

private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 1000);
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
Expand All @@ -71,7 +63,7 @@ public static void setUp() throws Exception {
UTIL.getConfiguration().set(StoreFileTrackerFactory.TRACKER_IMPL, "FILE");
}

@Before
@BeforeEach
public void testSetup() {
UTIL.getConfiguration().set(BUCKET_CACHE_IOENGINE_KEY,
"file:" + UTIL.getDataTestDir() + "/bucketcache");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@
*/
package org.apache.hadoop.hbase;

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

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext;
import org.apache.hadoop.hbase.MultithreadedTestUtil.TestThread;
import org.apache.hadoop.hbase.master.CachedClusterId;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category(MediumTests.class)
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
public class TestCachedClusterId {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCachedClusterId.class);

private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();

Expand All @@ -57,15 +55,15 @@ public void doWork() throws Exception {
}
}

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
TEST_UTIL.startMiniCluster(1);
activeMaster = TEST_UTIL.getHBaseCluster().getMaster();
clusterId = activeMaster.getClusterId();
standByMaster = TEST_UTIL.getHBaseCluster().startMaster().getMaster();
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

/**
* Checks tests are categorized.
* <p>
* @deprecated Will be removed after we fully upgrade to junit5, so keep it as is.
*/
@Deprecated
@Category({ MiscTests.class, SmallTests.class })
public class TestCheckTestClasses {

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

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 java.io.IOException;
import java.util.EnumSet;
import java.util.List;
Expand All @@ -34,33 +38,29 @@
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread;
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.junit.AfterClass;
import org.junit.Assert;
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;

/**
* Test the ClusterStatus.
*/
@Category(MediumTests.class)
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
public class TestClientClusterStatus {

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

private static HBaseTestingUtil UTIL;
private static Admin ADMIN;
private final static int SLAVES = 5;
private final static int MASTERS = 3;
private static SingleProcessHBaseCluster CLUSTER;
private static HRegionServer DEAD;

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
Configuration conf = HBaseConfiguration.create();
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName());
Expand All @@ -87,8 +87,7 @@ public void testNone() throws Exception {
ClusterMetrics status1 = ADMIN.getClusterMetrics(EnumSet.noneOf(Option.class));
// Do a rough compare. More specific compares can fail because all regions not deployed yet
// or more requests than expected.
Assert.assertEquals(status0.getLiveServerMetrics().size(),
status1.getLiveServerMetrics().size());
assertEquals(status0.getLiveServerMetrics().size(), status1.getLiveServerMetrics().size());
}

@Test
Expand All @@ -108,29 +107,29 @@ public void testLiveAndDeadServersStatus() throws Exception {
@Override
public boolean evaluate() throws Exception {
ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
Assert.assertNotNull(status);
assertNotNull(status);
return status.getRegionCount() > 0;
}
});
// Retrieve live servers and dead servers info.
EnumSet<Option> options =
EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS, Option.SERVERS_NAME);
ClusterMetrics status = ADMIN.getClusterMetrics(options);
Assert.assertNotNull(status);
Assert.assertNotNull(status.getLiveServerMetrics().keySet());
assertNotNull(status);
assertNotNull(status.getLiveServerMetrics().keySet());
// exclude a dead region server
Assert.assertEquals(SLAVES - 1, numRs);
assertEquals(SLAVES - 1, numRs);
// live servers = nums of regionservers
// By default, HMaster don't carry any regions so it won't report its load.
// Hence, it won't be in the server list.
Assert.assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
Assert.assertTrue(status.getRegionCount() > 0);
Assert.assertNotNull(status.getDeadServerNames());
Assert.assertEquals(1, status.getDeadServerNames().size());
assertEquals(status.getLiveServerMetrics().keySet().size(), numRs);
assertTrue(status.getRegionCount() > 0);
assertNotNull(status.getDeadServerNames());
assertEquals(1, status.getDeadServerNames().size());
ServerName deadServerName = status.getDeadServerNames().iterator().next();
Assert.assertEquals(DEAD.getServerName(), deadServerName);
Assert.assertNotNull(status.getServersName());
Assert.assertEquals(numRs, status.getServersName().size());
assertEquals(DEAD.getServerName(), deadServerName);
assertNotNull(status.getServersName());
assertEquals(numRs, status.getServersName().size());
}

@Test
Expand All @@ -149,29 +148,29 @@ public void testMasterAndBackupMastersStatus() throws Exception {
activeName = active.getServerName();
}
}
Assert.assertNotNull(active);
Assert.assertEquals(1, numActive);
Assert.assertEquals(MASTERS, masterThreads.size());
assertNotNull(active);
assertEquals(1, numActive);
assertEquals(MASTERS, masterThreads.size());
// Retrieve master and backup masters infos only.
EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
ClusterMetrics status = ADMIN.getClusterMetrics(options);
Assert.assertTrue(status.getMasterName().equals(activeName));
Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
assertTrue(status.getMasterName().equals(activeName));
assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
}

@Test
public void testOtherStatusInfos() throws Exception {
EnumSet<Option> options = EnumSet.of(Option.MASTER_COPROCESSORS, Option.HBASE_VERSION,
Option.CLUSTER_ID, Option.BALANCER_ON);
ClusterMetrics status = ADMIN.getClusterMetrics(options);
Assert.assertTrue(status.getMasterCoprocessorNames().size() == 1);
Assert.assertNotNull(status.getHBaseVersion());
Assert.assertNotNull(status.getClusterId());
Assert.assertTrue(status.getAverageLoad() == 0.0);
Assert.assertNotNull(status.getBalancerOn());
assertTrue(status.getMasterCoprocessorNames().size() == 1);
assertNotNull(status.getHBaseVersion());
assertNotNull(status.getClusterId());
assertTrue(status.getAverageLoad() == 0.0);
assertNotNull(status.getBalancerOn());
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
if (ADMIN != null) ADMIN.close();
UTIL.shutdownMiniCluster();
Expand All @@ -181,10 +180,10 @@ public static void tearDownAfterClass() throws Exception {
public void testObserver() throws IOException {
int preCount = MyObserver.PRE_COUNT.get();
int postCount = MyObserver.POST_COUNT.get();
Assert.assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream()
assertTrue(ADMIN.getClusterMetrics().getMasterCoprocessorNames().stream()
.anyMatch(s -> s.equals(MyObserver.class.getSimpleName())));
Assert.assertEquals(preCount + 1, MyObserver.PRE_COUNT.get());
Assert.assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
assertEquals(preCount + 1, MyObserver.PRE_COUNT.get());
assertEquals(postCount + 1, MyObserver.POST_COUNT.get());
}

public static class MyObserver implements MasterCoprocessor, MasterObserver {
Expand Down
Loading