Skip to content
Closed
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 @@ -30,13 +30,13 @@
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -87,11 +87,11 @@
import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.Lists;
import org.apache.hadoop.util.Time;
import org.junit.Before;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
Expand Down Expand Up @@ -122,8 +122,9 @@ public class TestBPOfferService {
GenericTestUtils.setLogLevel(DataNode.LOG, Level.TRACE);
}

@Rule
public TemporaryFolder baseDir = new TemporaryFolder();
@SuppressWarnings("checkstyle:VisibilityModifier")
@TempDir
java.nio.file.Path baseDir;

private DatanodeProtocolClientSideTranslatorPB mockNN1;
private DatanodeProtocolClientSideTranslatorPB mockNN2;
Expand All @@ -138,7 +139,7 @@ public class TestBPOfferService {
private boolean isSlownode;
private String mockStorageID;

@Before
@BeforeEach
public void setupMocks() throws Exception {
mockNN1 = setupNNMock(0);
mockNN2 = setupNNMock(1);
Expand Down Expand Up @@ -166,7 +167,7 @@ public void setupMocks() throws Exception {
Mockito.doReturn(dataSetLockManager).when(mockDn).getDataSetLockManager();
}

@After
@AfterEach
public void checkDataSetLockManager() {
dataSetLockManager.lockLeakCheck();
// make sure no lock Leak.
Expand Down Expand Up @@ -831,9 +832,8 @@ public void testReportBadBlockWhenStandbyNNTimesOut() throws Exception {
.getStorageType());
Thread.sleep(10000);
long difference = secondCallTime - firstCallTime;
assertTrue("Active namenode reportBadBlock processing should be "
+ "independent of standby namenode reportBadBlock processing ",
difference < 5000);
assertTrue(difference < 5000, "Active namenode reportBadBlock processing should be "
+ "independent of standby namenode reportBadBlock processing ");
} finally {
bpos.stop();
bpos.join();
Expand Down Expand Up @@ -871,9 +871,9 @@ public void testTrySendErrorReportWhenStandbyNNTimesOut() throws Exception {
bpos.trySendErrorReport(DatanodeProtocol.INVALID_BLOCK, errorString);
Thread.sleep(10000);
long difference = secondCallTime - firstCallTime;
assertTrue("Active namenode trySendErrorReport processing "
assertTrue(difference < 5000, "Active namenode trySendErrorReport processing "
+ "should be independent of standby namenode trySendErrorReport"
+ " processing ", difference < 5000);
+ " processing ");
} finally {
bpos.stop();
bpos.join();
Expand Down Expand Up @@ -911,8 +911,8 @@ public void testTrySendErrorReportWhenNNThrowsIOException()
String errorString = "Can't send invalid block " + FAKE_BLOCK;
bpos.trySendErrorReport(DatanodeProtocol.INVALID_BLOCK, errorString);
GenericTestUtils.waitFor(() -> secondCallTime != 0, 100, 20000);
assertTrue("Active namenode didn't add the report back to the queue "
+ "when errorReport threw IOException", secondCallTime != 0);
assertTrue(secondCallTime != 0, "Active namenode didn't add the report back to the queue "
+ "when errorReport threw IOException");
} finally {
bpos.stop();
bpos.join();
Expand Down Expand Up @@ -1025,9 +1025,7 @@ public Boolean get() {
// Send register command back to Datanode to reRegister().
// After reRegister IBRs should be cleared.
datanodeCommands[1] = new DatanodeCommand[] { new RegisterCommand() };
assertEquals(
"IBR size before reRegister should be non-0", 1, getStandbyIBRSize(
bpos));
assertEquals(1, getStandbyIBRSize(bpos), "IBR size before reRegister should be non-0");
bpos.triggerHeartbeatForTests();
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
Expand Down Expand Up @@ -1082,7 +1080,8 @@ public void testNNHAStateUpdateFromVersionRequest() throws Exception {

}

@Test(timeout = 30000)
@Test
@Timeout(value = 30)
public void testRefreshNameNodes() throws Exception {

BPOfferService bpos = setupBPOSForNNs(mockDn, mockNN1, mockNN2);
Expand Down Expand Up @@ -1156,7 +1155,8 @@ public void testRefreshNameNodes() throws Exception {
}
}

@Test(timeout = 15000)
@Test
@Timeout(value = 15)
public void testRefreshLeaseId() throws Exception {
Mockito.when(mockNN1.sendHeartbeat(
Mockito.any(DatanodeRegistration.class),
Expand Down Expand Up @@ -1221,7 +1221,8 @@ public Object answer(InvocationOnMock invocation)
}
}

@Test(timeout = 15000)
@Test
@Timeout(value = 15)
public void testSetIsSlownode() throws Exception {
assertEquals(mockDn.isSlownode(), false);
Mockito.when(mockNN1.sendHeartbeat(
Expand Down Expand Up @@ -1259,10 +1260,11 @@ public void testSetIsSlownode() throws Exception {
}
}

@Test(timeout = 15000)
@Test
@Timeout(value = 15)
public void testCommandProcessingThread() throws Exception {
Configuration conf = new HdfsConfiguration();
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build()) {
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.toFile()).build()) {
List<DataNode> datanodes = cluster.getDataNodes();
assertEquals(datanodes.size(), 1);
DataNode datanode = datanodes.get(0);
Expand All @@ -1273,19 +1275,20 @@ public void testCommandProcessingThread() throws Exception {
DFSTestUtil.createFile(fs, file, 10240L, (short)1, 0L);

MetricsRecordBuilder mrb = getMetrics(datanode.getMetrics().name());
assertTrue("Process command nums is not expected.",
getLongCounter("NumProcessedCommands", mrb) > 0);
assertTrue(getLongCounter("NumProcessedCommands", mrb) > 0,
"Process command nums is not expected.");
assertEquals(0, getLongCounter("SumOfActorCommandQueueLength", mrb));
// Check new metric result about processedCommandsOp.
// One command send back to DataNode here is #FinalizeCommand.
assertCounter("ProcessedCommandsOpNumOps", 1L, mrb);
}
}

@Test(timeout = 5000)
@Test
@Timeout(value = 5)
public void testCommandProcessingThreadExit() throws Exception {
Configuration conf = new HdfsConfiguration();
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.toFile()).
numDataNodes(1).build()) {
List<DataNode> datanodes = cluster.getDataNodes();
DataNode dataNode = datanodes.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import org.apache.hadoop.test.MetricsAsserts;
import org.apache.hadoop.util.Time;
import org.slf4j.event.Level;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* This test verifies that incremental block reports are sent in batch mode
Expand Down Expand Up @@ -161,7 +161,7 @@ public Boolean call() throws Exception {
});
}
for(int i = 0; i < NUM_FILES; i++) {
Assert.assertTrue(verifyService.take().get());
Assertions.assertTrue(verifyService.take().get());
}
final long testEndTime = Time.monotonicNow();

Expand Down Expand Up @@ -247,7 +247,7 @@ static boolean verifyFile(Path f, DistributedFileSystem dfs) {
for(int i = 0; i < numBlocks; i++) {
in.read(computed);
nextBytes(i, seed, expected);
Assert.assertArrayEquals(expected, computed);
Assertions.assertArrayEquals(expected, computed);
}
return true;
} catch(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.hadoop.hdfs.server.protocol.ReceivedDeletedBlockInfo.BlockStatus;
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.test.MetricsAsserts;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
import org.apache.hadoop.hdfs.server.protocol.DatanodeStorage;
import org.apache.hadoop.hdfs.server.protocol.StorageBlockReport;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

/**
* This test verifies NameNode behavior when it gets unexpected block reports
Expand All @@ -68,7 +66,7 @@ public class TestBlockHasMultipleReplicasOnSameDN {
private DFSClient client;
private String bpid;

@Before
@BeforeEach
public void startUpCluster() throws IOException {
conf = new HdfsConfiguration();
cluster = new MiniDFSCluster.Builder(conf)
Expand All @@ -79,7 +77,7 @@ public void startUpCluster() throws IOException {
bpid = cluster.getNamesystem().getBlockPoolId();
}

@After
@AfterEach
public void shutDownCluster() throws IOException {
if (cluster != null) {
fs.close();
Expand Down Expand Up @@ -142,8 +140,8 @@ public void testBlockHasMultipleReplicasOnSameDN() throws IOException {
// Make sure that each block has two replicas, one on each DataNode.
for (LocatedBlock locatedBlock : locatedBlocks.getLocatedBlocks()) {
DatanodeInfo[] locations = locatedBlock.getLocations();
assertThat(locations.length, is((int) NUM_DATANODES));
assertThat(locations[0].getDatanodeUuid(), not(locations[1].getDatanodeUuid()));
assertThat(locations.length).isEqualTo((int) NUM_DATANODES);
assertThat(locations[0].getDatanodeUuid()).isNotEqualTo(locations[1].getDatanodeUuid());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hdfs.server.datanode;

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

import java.io.IOException;
import java.net.InetSocketAddress;
Expand All @@ -31,9 +31,9 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand All @@ -47,7 +47,7 @@ public class TestBlockPoolManager {
private final StringBuilder log = new StringBuilder();
private int mockIdx = 1;

@Before
@BeforeEach
public void setupBPM() {
bpm = new BlockPoolManager(mockDN){

Expand Down Expand Up @@ -159,9 +159,9 @@ public void testInternalNameService() throws Exception {
bpm.refreshNamenodes(conf);
assertEquals("create #1\n", log.toString());
Map<String, BPOfferService> map = bpm.getBpByNameserviceId();
Assert.assertFalse(map.containsKey("ns2"));
Assert.assertFalse(map.containsKey("ns3"));
Assert.assertTrue(map.containsKey("ns1"));
Assertions.assertFalse(map.containsKey("ns2"));
Assertions.assertFalse(map.containsKey("ns3"));
Assertions.assertTrue(map.containsKey("ns1"));
log.setLength(0);
}

Expand All @@ -179,18 +179,18 @@ public void testNameServiceNeedToBeResolved() throws Exception {
"create #2\n" +
"create #3\n", log.toString());
Map<String, BPOfferService> map = bpm.getBpByNameserviceId();
Assert.assertTrue(map.containsKey("ns1"));
Assert.assertTrue(map.containsKey("ns2"));
Assert.assertTrue(map.containsKey("ns3"));
Assert.assertEquals(2, map.get("ns3").getBPServiceActors().size());
Assert.assertEquals("ns3-" + MockDomainNameResolver.FQDN_1 + "-8020",
Assertions.assertTrue(map.containsKey("ns1"));
Assertions.assertTrue(map.containsKey("ns2"));
Assertions.assertTrue(map.containsKey("ns3"));
Assertions.assertEquals(2, map.get("ns3").getBPServiceActors().size());
Assertions.assertEquals("ns3-" + MockDomainNameResolver.FQDN_1 + "-8020",
map.get("ns3").getBPServiceActors().get(0).getNnId());
Assert.assertEquals("ns3-" + MockDomainNameResolver.FQDN_2 + "-8020",
Assertions.assertEquals("ns3-" + MockDomainNameResolver.FQDN_2 + "-8020",
map.get("ns3").getBPServiceActors().get(1).getNnId());
Assert.assertEquals(
Assertions.assertEquals(
new InetSocketAddress(MockDomainNameResolver.FQDN_1, 8020),
map.get("ns3").getBPServiceActors().get(0).getNNSocketAddress());
Assert.assertEquals(
Assertions.assertEquals(
new InetSocketAddress(MockDomainNameResolver.FQDN_2, 8020),
map.get("ns3").getBPServiceActors().get(1).getNNSocketAddress());
log.setLength(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package org.apache.hadoop.hdfs.server.datanode;

import org.apache.hadoop.hdfs.server.common.Storage;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;

import java.io.File;
Expand All @@ -27,8 +28,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Test that BlockPoolSliceStorage can correctly generate trash and
Expand All @@ -52,7 +52,7 @@ private static class StubBlockPoolSliceStorage extends BlockPoolSliceStorage {
String clusterId) {
super(namespaceID, bpID, cTime, clusterId);
addStorageDir(new StorageDirectory(new File("/tmp/dontcare/" + bpID)));
assertThat(getStorageDirs().size(), is(1));
assertThat(getStorageDirs().size()).isEqualTo(1);
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public void getTrashDirectoryForBlockFile(String fileName, int nestingLevel) {

ReplicaInfo info = Mockito.mock(ReplicaInfo.class);
Mockito.when(info.getBlockURI()).thenReturn(new File(testFilePath).toURI());
assertThat(storage.getTrashDirectory(info), is(expectedTrashPath));
assertThat(storage.getTrashDirectory(info)).isEqualTo(expectedTrashPath);
}

/*
Expand All @@ -134,12 +134,13 @@ public void getRestoreDirectoryForBlockFile(String fileName, int nestingLevel) {
blockFileSubdir.substring(0, blockFileSubdir.length() - 1);

LOG.info("Generated deleted file path {}", deletedFilePath);
assertThat(storage.getRestoreDirectory(new File(deletedFilePath)),
is(expectedRestorePath));
assertThat(storage.getRestoreDirectory(new File(deletedFilePath)))
.isEqualTo(expectedRestorePath);

}

@Test (timeout=300000)
@Test
@Timeout(value = 300)
public void testGetTrashAndRestoreDirectories() {
storage = makeBlockPoolStorage();

Expand Down
Loading