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 @@ -17,10 +17,11 @@
*/
package org.apache.hadoop.hdfs.server.datanode;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;

Expand Down Expand Up @@ -69,10 +70,10 @@
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.GenericTestUtils.DelayAnswer;
import org.apache.hadoop.util.Time;
import org.junit.After;
import org.junit.Assert;
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 org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.slf4j.event.Level;
Expand Down Expand Up @@ -112,14 +113,14 @@ public abstract class BlockReportTestBase {
resetConfiguration();
}

@Before
@BeforeEach
public void startUpCluster() throws IOException {
REPL_FACTOR = 1; //Reset if case a test has modified the value
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(REPL_FACTOR).build();
fs = cluster.getFileSystem();
}

@After
@AfterEach
public void shutDownCluster() throws IOException {
if (fs != null) {
fs.close();
Expand Down Expand Up @@ -209,7 +210,8 @@ protected abstract void sendBlockReports(DatanodeRegistration dnR, String poolId
*
* @throws java.io.IOException on an error
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_01() throws IOException {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand Down Expand Up @@ -255,8 +257,7 @@ public void blockReport_01() throws IOException {

for (int i = 0; i < blocksAfterReport.size(); i++) {
ExtendedBlock b = blocksAfterReport.get(i).getBlock();
assertEquals("Length of " + i + "th block is incorrect",
oldLengths[i], b.getNumBytes());
assertEquals(oldLengths[i], b.getNumBytes(), "Length of " + i + "th block is incorrect");
}
}

Expand All @@ -269,7 +270,8 @@ public void blockReport_01() throws IOException {
*
* @throws IOException in case of errors
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_02() throws IOException {
final String METHOD_NAME = GenericTestUtils.getMethodName();
LOG.info("Running test " + METHOD_NAME);
Expand Down Expand Up @@ -332,10 +334,10 @@ public void blockReport_02() throws IOException {

printStats();

assertEquals("Wrong number of MissingBlocks is found",
blocks2Remove.size(), cluster.getNamesystem().getMissingBlocksCount());
assertEquals("Wrong number of UnderReplicatedBlocks is found",
blocks2Remove.size(), cluster.getNamesystem().getUnderReplicatedBlocks());
assertEquals(blocks2Remove.size(), cluster.getNamesystem().getMissingBlocksCount(),
"Wrong number of MissingBlocks is found");
assertEquals(blocks2Remove.size(), cluster.getNamesystem().getUnderReplicatedBlocks(),
"Wrong number of UnderReplicatedBlocks is found");
}


Expand All @@ -346,7 +348,8 @@ public void blockReport_02() throws IOException {
*
* @throws IOException in case of an error
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_03() throws IOException {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand All @@ -360,10 +363,12 @@ public void blockReport_03() throws IOException {
sendBlockReports(dnR, poolId, reports);
printStats();

assertThat("Wrong number of corrupt blocks",
cluster.getNamesystem().getCorruptReplicaBlocks(), is(1L));
assertThat("Wrong number of PendingDeletion blocks",
cluster.getNamesystem().getPendingDeletionBlocks(), is(0L));
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
.as("Wrong number of corrupt blocks")
.isEqualTo((1L));
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
.as("Wrong number of PendingDeletion blocks")
.isEqualTo(0L);
}

/**
Expand All @@ -374,7 +379,8 @@ public void blockReport_03() throws IOException {
*
* @throws IOException in case of an error
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_04() throws IOException {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand All @@ -396,10 +402,12 @@ public void blockReport_04() throws IOException {
sendBlockReports(dnR, poolId, reports);
printStats();

assertThat("Wrong number of corrupt blocks",
cluster.getNamesystem().getCorruptReplicaBlocks(), is(0L));
assertThat("Wrong number of PendingDeletion blocks",
cluster.getNamesystem().getPendingDeletionBlocks(), is(1L));
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
.as("Wrong number of corrupt blocks")
.isEqualTo(0L);
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
.as("Wrong number of PendingDeletion blocks")
.isEqualTo(1L);
}

/**
Expand All @@ -410,7 +418,8 @@ public void blockReport_04() throws IOException {
*
* @throws IOException in case of an error
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_06() throws Exception {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand All @@ -426,8 +435,8 @@ public void blockReport_06() throws Exception {
StorageBlockReport[] reports = getBlockReports(dn, poolId, false, false);
sendBlockReports(dnR, poolId, reports);
printStats();
assertEquals("Wrong number of PendingReplication Blocks",
0, cluster.getNamesystem().getUnderReplicatedBlocks());
assertEquals(0, cluster.getNamesystem().getUnderReplicatedBlocks(),
"Wrong number of PendingReplication Blocks");
}

/**
Expand All @@ -444,7 +453,8 @@ public void blockReport_06() throws Exception {
*
* @throws IOException in case of an error
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_07() throws Exception {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand All @@ -462,23 +472,29 @@ public void blockReport_07() throws Exception {
sendBlockReports(dnR, poolId, reports);
printStats();

assertThat("Wrong number of corrupt blocks",
cluster.getNamesystem().getCorruptReplicaBlocks(), is(0L));
assertThat("Wrong number of PendingDeletion blocks",
cluster.getNamesystem().getPendingDeletionBlocks(), is(1L));
assertThat("Wrong number of PendingReplication blocks",
cluster.getNamesystem().getPendingReplicationBlocks(), is(0L));
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
.as("Wrong number of corrupt blocks")
.isEqualTo(0L);
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
.as("Wrong number of PendingDeletion blocks")
.isEqualTo(1L);
assertThat(cluster.getNamesystem().getPendingReplicationBlocks())
.as("Wrong number of PendingReplication blocks")
.isEqualTo(0L);

reports = getBlockReports(dn, poolId, false, true);
sendBlockReports(dnR, poolId, reports);
printStats();

assertThat("Wrong number of corrupt blocks",
cluster.getNamesystem().getCorruptReplicaBlocks(), is(1L));
assertThat("Wrong number of PendingDeletion blocks",
cluster.getNamesystem().getPendingDeletionBlocks(), is(1L));
assertThat("Wrong number of PendingReplication blocks",
cluster.getNamesystem().getPendingReplicationBlocks(), is(0L));
assertThat(cluster.getNamesystem().getCorruptReplicaBlocks())
.as("Wrong number of corrupt blocks")
.isEqualTo(1L);
assertThat(cluster.getNamesystem().getPendingDeletionBlocks())
.as("Wrong number of PendingDeletion blocks")
.isEqualTo(1L);
assertThat(cluster.getNamesystem().getPendingReplicationBlocks())
.as("Wrong number of PendingReplication blocks")
.isEqualTo(0L);

printStats();

Expand All @@ -496,7 +512,8 @@ public void blockReport_07() throws Exception {
*
* @throws IOException in case of an error
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_08() throws IOException {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand Down Expand Up @@ -524,8 +541,8 @@ public void blockReport_08() throws IOException {
StorageBlockReport[] reports = getBlockReports(dn, poolId, false, false);
sendBlockReports(dnR, poolId, reports);
printStats();
assertEquals("Wrong number of PendingReplication blocks",
blocks.size(), cluster.getNamesystem().getPendingReplicationBlocks());
assertEquals(blocks.size(), cluster.getNamesystem().getPendingReplicationBlocks(),
"Wrong number of PendingReplication blocks");

try {
bc.join();
Expand All @@ -538,7 +555,8 @@ public void blockReport_08() throws IOException {
// Similar to BlockReport_08 but corrupts GS and len of the TEMPORARY's
// replica block. Expect the same behaviour: NN should simply ignore this
// block
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void blockReport_09() throws IOException {
final String METHOD_NAME = GenericTestUtils.getMethodName();
Path filePath = new Path("/" + METHOD_NAME + ".dat");
Expand Down Expand Up @@ -567,8 +585,8 @@ public void blockReport_09() throws IOException {
StorageBlockReport[] reports = getBlockReports(dn, poolId, true, true);
sendBlockReports(dnR, poolId, reports);
printStats();
assertEquals("Wrong number of PendingReplication blocks",
2, cluster.getNamesystem().getPendingReplicationBlocks());
assertEquals(2, cluster.getNamesystem().getPendingReplicationBlocks(),
"Wrong number of PendingReplication blocks");

try {
bc.join();
Expand All @@ -587,7 +605,8 @@ public void blockReport_09() throws IOException {
* corrupt.
* This is a regression test for HDFS-2791.
*/
@Test(timeout=300000)
@Test
@Timeout(value = 300)
public void testOneReplicaRbwReportArrivesAfterBlockCompleted() throws Exception {
final CountDownLatch brFinished = new CountDownLatch(1);
DelayAnswer delayer = new GenericTestUtils.DelayAnswer(LOG) {
Expand Down Expand Up @@ -658,7 +677,8 @@ protected Object passThrough(InvocationOnMock invocation)
}

// See HDFS-10301
@Test(timeout = 300000)
@Test
@Timeout(value = 300)
public void testInterleavedBlockReports()
throws IOException, ExecutionException, InterruptedException {
int numConcurrentBlockReports = 3;
Expand Down Expand Up @@ -696,7 +716,7 @@ public Void call() throws IOException {
executorService.shutdown();

// Verify that the storages match before and after the test
Assert.assertArrayEquals(storageInfos, dnDescriptor.getStorageInfos());
assertArrayEquals(storageInfos, dnDescriptor.getStorageInfos());
}

private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
Expand Down Expand Up @@ -729,8 +749,7 @@ private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
LOG.debug("Has been waiting for " + waiting_period + " ms.");
}
if (waiting_period > TIMEOUT)
assertTrue("Was waiting too long to get ReplicaInfo from a datanode",
tooLongWait);
assertTrue(tooLongWait, "Was waiting too long to get ReplicaInfo from a datanode");
}

HdfsServerConstants.ReplicaState state = r.getState();
Expand All @@ -746,8 +765,7 @@ private void waitForTempReplica(Block bl, int DN_N1) throws IOException {
" is in state " + state.getValue());
}
if (Time.monotonicNow() - start > TIMEOUT)
assertTrue("Was waiting too long for a replica to become TEMPORARY",
tooLongWait);
assertTrue(tooLongWait, "Was waiting too long for a replica to become TEMPORARY");
}
if(LOG.isDebugEnabled()) {
LOG.debug("Replica state after the loop " + state.getValue());
Expand Down Expand Up @@ -910,7 +928,7 @@ public void run() {
startDNandWait(filePath, true);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Failed to start BlockChecker: " + e);
fail("Failed to start BlockChecker: " + e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@

import java.util.function.Supplier;

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

/**
* DO NOT ADD MOCKITO IMPORTS HERE Or Downstream projects may not
Expand Down Expand Up @@ -220,11 +219,12 @@ public static void reconfigureDataNode(DataNode dn, File... newVols)
dnNewDataDirs.append(newVol.getAbsolutePath());
}
try {
assertThat(
assertEquals(
dn.reconfigurePropertyImpl(
DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY,
dnNewDataDirs.toString()),
is(dn.getConf().get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY)));
dn.getConf().get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY)
);
} catch (ReconfigurationException e) {
// This can be thrown if reconfiguration tries to use a failed volume.
// We need to swallow the exception, because some of our tests want to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.hdfs.server.datanode;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -41,7 +42,6 @@
import org.apache.hadoop.hdfs.server.protocol.HeartbeatResponse;
import org.apache.hadoop.hdfs.server.protocol.NNHAStatusHeartbeat;
import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.junit.Assert;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -172,8 +172,8 @@ public DatanodeRegistration answer(InvocationOnMock invocation)
@Override
DatanodeProtocolClientSideTranslatorPB connectToNN(
InetSocketAddress nnAddr) throws IOException {
Assert.assertEquals(nnSocketAddr, nnAddr);
return namenode;
assertEquals(nnSocketAddr, nnAddr);
return namenode;
}
};
// Trigger a heartbeat so that it acknowledges the NN as active.
Expand Down
Loading