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

import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER;
import static org.apache.hadoop.hbase.SplitLogCounters.tot_mgr_wait_for_zk_delete;
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 Down Expand Up @@ -69,13 +69,12 @@
import org.apache.hadoop.hbase.wal.WALEditInternalHelper;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -94,18 +93,12 @@ public abstract class AbstractTestDLS {
private static final int NUM_RS = 5;
private static byte[] COLUMN_FAMILY = Bytes.toBytes("family");

@Rule
public TestName testName = new TestName();

private TableName tableName;
private SingleProcessHBaseCluster cluster;
private HMaster master;
private Configuration conf;

@Rule
public TestName name = new TestName();

@BeforeClass
@BeforeAll
public static void setup() throws Exception {
// Uncomment the following line if more verbosity is needed for
// debugging (see HBASE-12285 for details).
Expand All @@ -114,7 +107,7 @@ public static void setup() throws Exception {
TEST_UTIL.startMiniDFSCluster(3);
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
Expand Down Expand Up @@ -147,13 +140,13 @@ public boolean evaluate() throws Exception {
});
}

@Before
public void before() throws Exception {
@BeforeEach
public void before(TestInfo testInfo) throws Exception {
conf = TEST_UTIL.getConfiguration();
tableName = TableName.valueOf(testName.getMethodName());
tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
}

@After
@AfterEach
public void after() throws Exception {
TEST_UTIL.shutdownMiniHBaseCluster();
TEST_UTIL.getTestFileSystem().delete(CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.master;

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

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
import org.apache.hadoop.hbase.StartTestingClusterOption;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.master.hbck.HbckChore;
import org.apache.hadoop.hbase.master.hbck.HbckReport;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;

public abstract class AbstractTestMasterRegionMutation {

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

protected static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
protected static ServerName rs0;

protected static final AtomicBoolean ERROR_OUT = new AtomicBoolean(false);
protected static final AtomicInteger ERROR_COUNTER = new AtomicInteger(0);
protected static final AtomicBoolean FIRST_TIME_ERROR = new AtomicBoolean(true);

protected static void setUpBeforeClass(int numMasters, Class<? extends HRegion> regionImplClass)
throws Exception {
TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, regionImplClass, HRegion.class);
StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder();
builder.numMasters(numMasters).numRegionServers(3);
TEST_UTIL.startMiniCluster(builder.build());
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
rs0 = cluster.getRegionServer(0).getServerName();
TEST_UTIL.getAdmin().balancerSwitch(false, true);
}

protected static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}

@BeforeEach
protected void setUp(TestInfo testInfo) throws Exception {
TableName tableName = TableName.valueOf(testInfo.getTestMethod().orElseThrow().getName());
TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build();
int startKey = 0;
int endKey = 80000;
TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9);
}

@Test
protected void testMasterRegionMutations() throws Exception {
HbckChore hbckChore = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster());
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();

int numRegions0 = cluster.getRegionServer(0).getNumberOfOnlineRegions();
int numRegions1 = cluster.getRegionServer(1).getNumberOfOnlineRegions();
int numRegions2 = cluster.getRegionServer(2).getNumberOfOnlineRegions();

hbckChore.choreForTesting();
HbckReport hbckReport = hbckChore.getLastReport();
assertEquals(0, hbckReport.getInconsistentRegions().size());
assertEquals(0, hbckReport.getOrphanRegionsOnFS().size());
assertEquals(0, hbckReport.getOrphanRegionsOnRS().size());

ERROR_OUT.set(true);
TEST_UTIL.getAdmin().move(
cluster.getRegionServer(1).getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0);

ERROR_OUT.set(true);
TEST_UTIL.getAdmin().move(
cluster.getRegionServer(2).getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0);

HMaster master = TEST_UTIL.getHBaseCluster().getMaster();

TEST_UTIL.waitFor(5000, 1000, () -> {
LOG.info("numRegions0: {} , numRegions1: {} , numRegions2: {}", numRegions0, numRegions1,
numRegions2);
LOG.info("Online regions - server0 : {} , server1: {} , server2: {}",
cluster.getRegionServer(0).getNumberOfOnlineRegions(),
cluster.getRegionServer(1).getNumberOfOnlineRegions(),
cluster.getRegionServer(2).getNumberOfOnlineRegions());
LOG.info("Num of successfully completed procedures: {} , num of all procedures: {}",
master.getMasterProcedureExecutor().getProcedures().stream()
.filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState()
== ProcedureProtos.ProcedureState.SUCCESS)
.count(),
master.getMasterProcedureExecutor().getProcedures().size());
return (numRegions0 + numRegions1 + numRegions2)
== (cluster.getRegionServer(0).getNumberOfOnlineRegions()
+ cluster.getRegionServer(1).getNumberOfOnlineRegions()
+ cluster.getRegionServer(2).getNumberOfOnlineRegions())
&& master.getMasterProcedureExecutor().getProcedures().stream()
.filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState()
== ProcedureProtos.ProcedureState.SUCCESS)
.count() == master.getMasterProcedureExecutor().getProcedures().size();
});

TEST_UTIL.waitFor(5000, 1000, () -> {
HbckChore hbck = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster());
hbck.choreForTesting();
HbckReport report = hbck.getLastReport();
return report.getInconsistentRegions().isEmpty() && report.getOrphanRegionsOnFS().isEmpty()
&& report.getOrphanRegionsOnRS().isEmpty();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,15 +39,15 @@ public abstract class AbstractTestRestartCluster {

protected abstract boolean splitWALCoordinatedByZk();

@Before
@BeforeEach
public void setUp() {
boolean splitWALCoordinatedByZk = splitWALCoordinatedByZk();
LOG.info("WAL splitting coordinated by zk {}", splitWALCoordinatedByZk);
UTIL.getConfiguration().setBoolean(HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK,
splitWALCoordinatedByZk);
}

@After
@AfterEach
public void tearDown() throws Exception {
UTIL.shutdownMiniCluster();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
package org.apache.hadoop.hbase.master;

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.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

Expand All @@ -30,7 +30,6 @@
import java.util.List;
import java.util.concurrent.Semaphore;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.monitoring.MonitoredTask;
Expand All @@ -46,34 +45,30 @@
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
import org.apache.zookeeper.KeeperException;
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.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test the {@link ActiveMasterManager}.
*/
@Category({ MasterTests.class, MediumTests.class })
@Tag(MasterTests.TAG)
@Tag(MediumTests.TAG)
public class TestActiveMasterManager {

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

private final static Logger LOG = LoggerFactory.getLogger(TestActiveMasterManager.class);
private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.startMiniZKCluster();
}

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

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
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 org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.MiniClusterRule;
import org.apache.hadoop.hbase.MiniClusterExtension;
import org.apache.hadoop.hbase.StartTestingClusterOption;
import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@Category({ MediumTests.class, MasterTests.class })
@Tag(MediumTests.TAG)
@Tag(MasterTests.TAG)
public class TestAlwaysStandByHMaster {

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

private static final StartTestingClusterOption OPTION = StartTestingClusterOption.builder()
.numAlwaysStandByMasters(1).numMasters(1).numRegionServers(1).build();

@ClassRule
public static final MiniClusterRule miniClusterRule =
MiniClusterRule.newBuilder().setMiniClusterOption(OPTION).build();
@RegisterExtension
public static final MiniClusterExtension miniClusterExtension =
MiniClusterExtension.newBuilder().setMiniClusterOption(OPTION).build();

/**
* Tests that the AlwaysStandByHMaster does not transition to active state even if no active
* master exists.
*/
@Test
public void testAlwaysStandBy() throws Exception {
HBaseTestingUtil testUtil = miniClusterRule.getTestingUtility();
HBaseTestingUtil testUtil = miniClusterExtension.getTestingUtility();
// Make sure there is an active master.
assertNotNull(testUtil.getMiniHBaseCluster().getMaster());
assertEquals(2, testUtil.getMiniHBaseCluster().getMasterThreads().size());
Expand Down
Loading