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
5 changes: 0 additions & 5 deletions hbase-asyncfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@
*/
package org.apache.hadoop.hbase.io.asyncfs;

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 org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.asyncfs.monitor.ExcludeDatanodeManager;
import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
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;

@Category({ SmallTests.class })
@Tag(MiscTests.TAG)
@Tag(SmallTests.TAG)
public class TestExcludeDatanodeManager {

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

@Test
public void testExcludeSlowDNBySpeed() {
Configuration conf = HBaseConfiguration.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_SOCKET_TIMEOUT_KEY;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -38,7 +38,6 @@
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.asyncfs.monitor.ExcludeDatanodeManager;
import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor;
Expand All @@ -49,15 +48,12 @@
import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.ipc.RemoteException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.runners.MethodSorters;
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;

Expand All @@ -67,14 +63,10 @@
import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioSocketChannel;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category({ MiscTests.class, MediumTests.class })
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
public class TestFanOutOneBlockAsyncDFSOutput extends AsyncFSTestBase {

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

private static final Logger LOG = LoggerFactory.getLogger(TestFanOutOneBlockAsyncDFSOutput.class);
private static DistributedFileSystem FS;
private static EventLoopGroup EVENT_LOOP_GROUP;
Expand All @@ -83,10 +75,9 @@ public class TestFanOutOneBlockAsyncDFSOutput extends AsyncFSTestBase {

private static StreamSlowMonitor MONITOR;

@Rule
public TestName name = new TestName();
private Path file;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
UTIL.getConfiguration().setInt(DFS_CLIENT_SOCKET_TIMEOUT_KEY, READ_TIMEOUT_MS);
startMiniDFSCluster(3);
Expand All @@ -96,7 +87,7 @@ public static void setUp() throws Exception {
MONITOR = StreamSlowMonitor.create(UTIL.getConfiguration(), "testMonitor");
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
if (EVENT_LOOP_GROUP != null) {
EVENT_LOOP_GROUP.shutdownGracefully().get();
Expand Down Expand Up @@ -136,13 +127,17 @@ static void writeAndVerify(FileSystem fs, Path f, AsyncFSOutput out)
}
}

@BeforeEach
public void setUpBeforeEach(TestInfo testInfo) {
file = new Path("/" + testInfo.getTestMethod().get().getName());
}

@Test
public void test() throws IOException, InterruptedException, ExecutionException {
Path f = new Path("/" + name.getMethodName());
EventLoop eventLoop = EVENT_LOOP_GROUP.next();
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true,
false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
writeAndVerify(FS, f, out);
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, file,
true, false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
writeAndVerify(FS, file, out);
}

/**
Expand All @@ -151,59 +146,49 @@ public void test() throws IOException, InterruptedException, ExecutionException
*/
@Test
public void test0Recover() throws IOException, InterruptedException, ExecutionException {
Path f = new Path("/" + name.getMethodName());
EventLoop eventLoop = EVENT_LOOP_GROUP.next();
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true,
false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, file,
true, false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
byte[] b = new byte[10];
Bytes.random(b);
out.write(b, 0, b.length);
out.flush(false).get();
// restart one datanode which causes one connection broken
CLUSTER.restartDataNode(0);
out.write(b, 0, b.length);
try {
out.flush(false).get();
fail("flush should fail");
} catch (ExecutionException e) {
// we restarted one datanode so the flush should fail
LOG.info("expected exception caught", e);
}
ExecutionException e = assertThrows(ExecutionException.class, () -> out.flush(false).get());
LOG.info("expected exception caught", e);
out.recoverAndClose(null);
assertEquals(b.length, FS.getFileStatus(f).getLen());
assertEquals(b.length, FS.getFileStatus(file).getLen());
byte[] actual = new byte[b.length];
try (FSDataInputStream in = FS.open(f)) {
try (FSDataInputStream in = FS.open(file)) {
in.readFully(actual);
}
assertArrayEquals(b, actual);
}

@Test
public void testHeartbeat() throws IOException, InterruptedException, ExecutionException {
Path f = new Path("/" + name.getMethodName());
EventLoop eventLoop = EVENT_LOOP_GROUP.next();
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true,
false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, file,
true, false, (short) 3, FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
Thread.sleep(READ_TIMEOUT_MS * 2);
// the connection to datanode should still alive.
writeAndVerify(FS, f, out);
writeAndVerify(FS, file, out);
}

/**
* This is important for fencing when recover from RS crash.
*/
@Test
public void testCreateParentFailed() throws IOException {
Path f = new Path("/" + name.getMethodName() + "/test");
Path f = new Path(file, "test");
EventLoop eventLoop = EVENT_LOOP_GROUP.next();
try {
FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true, false, (short) 3,
FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
fail("should fail with parent does not exist");
} catch (RemoteException e) {
LOG.info("expected exception caught", e);
assertThat(e.unwrapRemoteException(), instanceOf(FileNotFoundException.class));
}
RemoteException e = assertThrows(RemoteException.class,
() -> FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true, false, (short) 3,
FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true));
LOG.info("expected exception caught", e);
assertThat(e.unwrapRemoteException(), instanceOf(FileNotFoundException.class));
}

@Test
Expand Down Expand Up @@ -264,19 +249,18 @@ public void testExcludeFailedConnectToDatanode()

@Test
public void testWriteLargeChunk() throws IOException, InterruptedException, ExecutionException {
Path f = new Path("/" + name.getMethodName());
EventLoop eventLoop = EVENT_LOOP_GROUP.next();
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true,
false, (short) 3, 1024 * 1024 * 1024, eventLoop, CHANNEL_CLASS, MONITOR, true);
FanOutOneBlockAsyncDFSOutput out = FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, file,
true, false, (short) 3, 1024 * 1024 * 1024, eventLoop, CHANNEL_CLASS, MONITOR, true);
byte[] b = new byte[50 * 1024 * 1024];
Bytes.random(b);
out.write(b);
consume(out.flush(false));
assertEquals(b.length, out.flush(false).get().longValue());
out.close();
assertEquals(b.length, FS.getFileStatus(f).getLen());
assertEquals(b.length, FS.getFileStatus(file).getLen());
byte[] actual = new byte[b.length];
try (FSDataInputStream in = FS.open(f)) {
try (FSDataInputStream in = FS.open(file)) {
in.readFully(actual);
}
assertArrayEquals(b, actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.asyncfs;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.ArrayList;
import java.util.Iterator;
Expand All @@ -28,7 +28,6 @@
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
Expand All @@ -37,13 +36,10 @@
import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
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.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -65,13 +61,10 @@
* in this test class we use the default value for timeout which is 60 seconds and it is enough for
* this test.
*/
@Category({ MiscTests.class, MediumTests.class })
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
public class TestFanOutOneBlockAsyncDFSOutputHang extends AsyncFSTestBase {

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

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

Expand All @@ -85,10 +78,7 @@ public class TestFanOutOneBlockAsyncDFSOutputHang extends AsyncFSTestBase {

private static FanOutOneBlockAsyncDFSOutput OUT;

@Rule
public TestName name = new TestName();

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
startMiniDFSCluster(2);
FS = CLUSTER.getFileSystem();
Expand All @@ -101,7 +91,7 @@ public static void setUp() throws Exception {
FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS, MONITOR, true);
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
if (OUT != null) {
OUT.recoverAndClose(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.io.asyncfs;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mockConstruction;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
Expand All @@ -27,19 +27,17 @@
import java.lang.reflect.Method;
import java.util.Optional;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.DFSOutputStream;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.DummyDFSOutputStream;
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.MockedConstruction;

import org.apache.hbase.thirdparty.io.netty.channel.Channel;
Expand All @@ -54,19 +52,16 @@
* <p>
* See HBASE-28955 for more details.
*/
@Category({ MiscTests.class, MediumTests.class })
@Tag(MiscTests.TAG)
@Tag(MediumTests.TAG)
public class TestLeaseRenewal extends AsyncFSTestBase {

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

private static DistributedFileSystem FS;
private static EventLoopGroup EVENT_LOOP_GROUP;
private static Class<? extends Channel> CHANNEL_CLASS;
private static StreamSlowMonitor MONITOR;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
startMiniDFSCluster(3);
FS = CLUSTER.getFileSystem();
Expand All @@ -75,7 +70,7 @@ public static void setUp() throws Exception {
MONITOR = StreamSlowMonitor.create(UTIL.getConfiguration(), "testMonitor");
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
if (EVENT_LOOP_GROUP != null) {
EVENT_LOOP_GROUP.shutdownGracefully().get();
Expand Down
Loading