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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*/
package org.apache.hadoop.hbase.replication.regionserver;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -66,16 +67,15 @@
import org.apache.hadoop.hbase.wal.WALFactory;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
import org.apache.hadoop.hbase.wal.WALProvider;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

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

public abstract class TestBasicWALEntryStream extends WALEntryStreamTestBase {

@Before
@BeforeEach
public void setUp() throws Exception {
initWAL();
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public void testWALKeySerialization() throws Exception {
WALKeyImpl key =
new WALKeyImpl(info.getEncodedNameAsBytes(), tableName, EnvironmentEdgeManager.currentTime(),
new ArrayList<UUID>(), 0L, 0L, mvcc, scopes, attributes);
Assert.assertEquals(attributes, key.getExtendedAttributes());
assertEquals(attributes, key.getExtendedAttributes());

WALProtos.WALKey.Builder builder = key.getBuilder(WALCellCodec.getNoneCompressor());
WALProtos.WALKey serializedKey = builder.build();
Expand All @@ -256,14 +256,14 @@ public void testWALKeySerialization() throws Exception {
deserializedKey.readFieldsFromPb(serializedKey, WALCellCodec.getNoneUncompressor());

// equals() only checks region name, sequence id and write time
Assert.assertEquals(key, deserializedKey);
assertEquals(key, deserializedKey);
// can't use Map.equals() because byte arrays use reference equality
Assert.assertEquals(key.getExtendedAttributes().keySet(),
assertEquals(key.getExtendedAttributes().keySet(),
deserializedKey.getExtendedAttributes().keySet());
for (Map.Entry<String, byte[]> entry : deserializedKey.getExtendedAttributes().entrySet()) {
Assert.assertArrayEquals(key.getExtendedAttribute(entry.getKey()), entry.getValue());
assertArrayEquals(key.getExtendedAttribute(entry.getKey()), entry.getValue());
}
Assert.assertEquals(key.getReplicationScopes(), deserializedKey.getReplicationScopes());
assertEquals(key.getReplicationScopes(), deserializedKey.getReplicationScopes());
}

private ReplicationSource mockReplicationSource(boolean recovered, Configuration conf) {
Expand Down Expand Up @@ -430,8 +430,8 @@ public String explainFailure() throws Exception {
assertEquals(walPath, entryBatch.getLastWalPath());

long walLength = fs.getFileStatus(walPath).getLen();
assertTrue("Position " + entryBatch.getLastWalPosition() + " is out of range, file length is "
+ walLength, entryBatch.getLastWalPosition() <= walLength);
assertTrue(entryBatch.getLastWalPosition() <= walLength, "Position "
+ entryBatch.getLastWalPosition() + " is out of range, file length is " + walLength);
assertEquals(1, entryBatch.getNbEntries());
assertTrue(entryBatch.isEndOfFile());

Expand Down Expand Up @@ -656,14 +656,14 @@ public void testEOFExceptionForRecoveredQueueWithMultipleLogs() throws Exception
// Create a reader thread.
ReplicationSourceWALReader reader = new ReplicationSourceWALReader(fs, conf, localLogQueue, 0,
getDummyFilter(), source, fakeWalGroupId);
assertEquals("Initial log queue size is not correct", 2,
localLogQueue.getQueueSize(fakeWalGroupId));
assertEquals(2, localLogQueue.getQueueSize(fakeWalGroupId),
"Initial log queue size is not correct");
reader.start();
reader.join();

// remove empty log from logQueue.
assertEquals(0, localLogQueue.getQueueSize(fakeWalGroupId));
assertEquals("Log queue should be empty", 0, localLogQueue.getQueueSize(fakeWalGroupId));
assertEquals(0, localLogQueue.getQueueSize(fakeWalGroupId), "Log queue should be empty");
}

private PriorityBlockingQueue<Path> getQueue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,22 @@
*/
package org.apache.hadoop.hbase.replication.regionserver;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
import org.apache.hadoop.hbase.wal.AsyncFSWALProvider;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;

/**
* TestBasicWALEntryStream with {@link AsyncFSWALProvider} as the WAL provider.
*/
@Category({ ReplicationTests.class, MediumTests.class })
@Tag(ReplicationTests.TAG)
@Tag(MediumTests.TAG)
public class TestBasicWALEntryStreamAsyncFSWAL extends TestBasicWALEntryStream {

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

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, AsyncFSWALProvider.class,
AbstractFSWALProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,22 @@
*/
package org.apache.hadoop.hbase.replication.regionserver;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
import org.apache.hadoop.hbase.wal.FSHLogProvider;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;

/**
* TestBasicWALEntryStream with {@link FSHLogProvider} as the WAL provider.
*/
@Category({ ReplicationTests.class, MediumTests.class })
@Tag(ReplicationTests.TAG)
@Tag(MediumTests.TAG)
public class TestBasicWALEntryStreamFSHLog extends TestBasicWALEntryStream {

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

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, FSHLogProvider.class,
AbstractFSWALProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.replication.regionserver;

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

Expand All @@ -27,28 +27,25 @@
import java.util.List;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
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;

/**
* Tests for DumpReplicationQueues tool
*/
@Tag(ReplicationTests.TAG)
@Tag(SmallTests.TAG)
@Category({ ReplicationTests.class, SmallTests.class })
public class TestDumpReplicationQueues {

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

/**
* Makes sure dumpQueues returns wals znodes ordered chronologically.
* @throws Exception if dumpqueues finds any error while handling list of znodes.
Expand Down Expand Up @@ -82,16 +79,13 @@ public void testDumpReplicationReturnsWalSorted() throws Exception {
dumpQueues.setConf(config);
String dump = dumpQueues.dumpQueues(zkWatcherMock, peerIds, false);
String[] parsedDump = dump.split("Replication position for");
assertEquals("Parsed dump should have 4 parts.", 4, parsedDump.length);
assertTrue(
"First wal should be rs1%2C60964%2C1549394085556.1549394101426, but got: " + parsedDump[1],
parsedDump[1].indexOf("rs1%2C60964%2C1549394085556.1549394101426") >= 0);
assertTrue(
"Second wal should be rs1%2C60964%2C1549394085556.1549394101427, but got: " + parsedDump[2],
parsedDump[2].indexOf("rs1%2C60964%2C1549394085556.1549394101427") >= 0);
assertTrue(
"Third wal should be rs1%2C60964%2C1549394085556.1549394101428, but got: " + parsedDump[3],
parsedDump[3].indexOf("rs1%2C60964%2C1549394085556.1549394101428") >= 0);
assertEquals(4, parsedDump.length, "Parsed dump should have 4 parts.");
assertTrue(parsedDump[1].indexOf("rs1%2C60964%2C1549394085556.1549394101426") >= 0,
"First wal should be rs1%2C60964%2C1549394085556.1549394101426, but got: " + parsedDump[1]);
assertTrue(parsedDump[2].indexOf("rs1%2C60964%2C1549394085556.1549394101427") >= 0,
"Second wal should be rs1%2C60964%2C1549394085556.1549394101427, but got: " + parsedDump[2]);
assertTrue(parsedDump[3].indexOf("rs1%2C60964%2C1549394085556.1549394101428") >= 0,
"Third wal should be rs1%2C60964%2C1549394085556.1549394101428, but got: " + parsedDump[3]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
*/
package org.apache.hadoop.hbase.replication.regionserver;

import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.atomic.AtomicLong;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.HTestConst;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
import org.apache.hadoop.hbase.testclassification.LargeTests;
Expand All @@ -42,25 +43,20 @@
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.Assert;
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.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ ReplicationTests.class, LargeTests.class })
@Tag(ReplicationTests.TAG)
@Tag(LargeTests.TAG)
public class TestGlobalReplicationThrottler {

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

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

private static final int REPLICATION_SOURCE_QUOTA = 200;
private static int numOfPeer = 0;
private static Configuration conf1;
Expand All @@ -74,10 +70,9 @@ public class TestGlobalReplicationThrottler {
private static final byte[] ROW = Bytes.toBytes("r");
private static final byte[][] ROWS = HTestConst.makeNAscii(ROW, 100);

@Rule
public TestName name = new TestName();
private String testName;

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() throws Exception {
conf1 = HBaseConfiguration.create();
conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
Expand Down Expand Up @@ -111,7 +106,7 @@ public static void setUpBeforeClass() throws Exception {
numOfPeer = admin1.getPeersCount();
}

@AfterClass
@AfterAll
public static void tearDownAfterClass() throws Exception {
utility2.shutdownMiniCluster();
utility1.shutdownMiniCluster();
Expand All @@ -121,14 +116,14 @@ public static void tearDownAfterClass() throws Exception {
volatile private boolean testQuotaNonZero = false;

@Test
public void testQuota() throws IOException {
final TableName tableName = TableName.valueOf(name.getMethodName());
HTableDescriptor table = new HTableDescriptor(tableName);
HColumnDescriptor fam = new HColumnDescriptor(famName);
fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
table.addFamily(fam);
utility1.getAdmin().createTable(table);
utility2.getAdmin().createTable(table);
public void testQuota(TestInfo testInfo) throws Exception {
testName = testInfo.getTestMethod().get().getName();
final TableName tableName = TableName.valueOf(testName);
TableDescriptor tableDescriptor =
TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder
.newBuilder(famName).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).build();
utility1.getAdmin().createTable(tableDescriptor);
utility2.getAdmin().createTable(tableDescriptor);

Thread watcher = new Thread(() -> {
Replication replication = (Replication) utility1.getMiniHBaseCluster().getRegionServer(0)
Expand Down Expand Up @@ -183,8 +178,8 @@ public void testQuota() throws IOException {
}

watcher.interrupt();
Assert.assertTrue(testQuotaPass);
Assert.assertTrue(testQuotaNonZero);
assertTrue(testQuotaPass);
assertTrue(testQuotaNonZero);
}

}
Loading
Loading