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

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -28,12 +28,10 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.apache.hadoop.util.Lists;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.Timeout;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.conf.Configuration;
Expand All @@ -51,12 +49,13 @@
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.hdfs.util.HostsFileWriter;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

/**
* This class provide utilities for testing of the admin operations of nodes.
*/
@Timeout(600)
public class AdminStatesBaseTest {
public static final Logger LOG =
LoggerFactory.getLogger(AdminStatesBaseTest.class);
Expand All @@ -69,10 +68,9 @@ public class AdminStatesBaseTest {

final private Random myrand = new Random();

@Rule
public TemporaryFolder baseDir = new TemporaryFolder();
@Rule
public Timeout timeout = new Timeout(600, TimeUnit.SECONDS);
@SuppressWarnings("checkstyle:VisibilityModifier")
@TempDir
public java.nio.file.Path baseDir;

private HostsFileWriter hostsFileWriter;
private Configuration conf;
Expand All @@ -91,7 +89,7 @@ protected MiniDFSCluster getCluster() {
return cluster;
}

@Before
@BeforeEach
public void setup() throws IOException {
// Set up the hosts/exclude files.
hostsFileWriter = new HostsFileWriter();
Expand All @@ -118,7 +116,7 @@ public void setup() throws IOException {

}

@After
@AfterEach
public void teardown() throws IOException {
hostsFileWriter.cleanup();
shutdownCluster();
Expand Down Expand Up @@ -391,7 +389,7 @@ protected DFSClient getDfsClient(final int nnIndex) throws IOException {
protected static void validateCluster(DFSClient client, int numDNs)
throws IOException {
DatanodeInfo[] info = client.datanodeReport(DatanodeReportType.LIVE);
assertEquals("Number of Datanodes ", numDNs, info.length);
assertEquals(numDNs, info.length, "Number of Datanodes ");
}

/** Start a MiniDFSCluster.
Expand All @@ -406,7 +404,7 @@ protected void startCluster(int numNameNodes, int numDatanodes,
protected void startCluster(int numNameNodes, int numDatanodes,
boolean setupHostsFile, long[] nodesCapacity,
boolean checkDataNodeHostConfig, boolean federation) throws IOException {
MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf, baseDir.getRoot())
MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf, baseDir.toFile())
.numDataNodes(numDatanodes);
if (federation) {
builder.nnTopology(
Expand Down Expand Up @@ -441,7 +439,7 @@ protected void startSimpleCluster(int numNameNodes, int numDatanodes)


protected void startSimpleHACluster(int numDatanodes) throws IOException {
cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot())
cluster = new MiniDFSCluster.Builder(conf, baseDir.toFile())
.nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(
numDatanodes).build();
cluster.transitionToActive(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
Expand Down Expand Up @@ -190,8 +191,6 @@
import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.VersionInfo;
import org.junit.Assert;
import org.junit.Assume;
import org.apache.hadoop.util.ToolRunner;

import org.apache.hadoop.classification.VisibleForTesting;
Expand Down Expand Up @@ -1672,15 +1671,14 @@ public static long roundUpToMultiple(long val, int factor) {
}

public static void checkComponentsEquals(byte[][] expected, byte[][] actual) {
assertEquals("expected: " + DFSUtil.byteArray2PathString(expected)
+ ", actual: " + DFSUtil.byteArray2PathString(actual), expected.length,
actual.length);
assertEquals(expected.length, actual.length,
"expected: " + DFSUtil.byteArray2PathString(expected) + ", actual: "
+ DFSUtil.byteArray2PathString(actual));
int i = 0;
for (byte[] e : expected) {
byte[] actualComponent = actual[i++];
assertTrue("expected: " + DFSUtil.bytes2String(e) + ", actual: "
+ DFSUtil.bytes2String(actualComponent),
Arrays.equals(e, actualComponent));
assertTrue(Arrays.equals(e, actualComponent), "expected: " + DFSUtil.bytes2String(e)
+ ", actual: " + DFSUtil.bytes2String(actualComponent));
}
}

Expand All @@ -1699,7 +1697,7 @@ public ShortCircuitTestContext(String testName) {
this.sockDir = new TemporarySocketDirectory();
DomainSocket.disableBindPathValidation();
formerTcpReadsDisabled = DFSInputStream.tcpReadsDisabledForTesting;
Assume.assumeTrue(DomainSocket.getLoadingFailureReason() == null);
assumeTrue(DomainSocket.getLoadingFailureReason() == null);
}

public Configuration newConfiguration() {
Expand Down Expand Up @@ -1737,7 +1735,7 @@ public static void verifyFilesEqual(FileSystem fs, Path p1, Path p2, int len)
try (FSDataInputStream in1 = fs.open(p1);
FSDataInputStream in2 = fs.open(p2)) {
for (int i = 0; i < len; i++) {
assertEquals("Mismatch at byte " + i, in1.read(), in2.read());
assertEquals(in1.read(), in2.read(), "Mismatch at byte " + i);
}
}
}
Expand Down Expand Up @@ -1813,32 +1811,31 @@ public static void verifyClientStats(Configuration conf,
client.getReplicatedBlockStats();
ECBlockGroupStats ecBlockGroupStats = client.getECBlockGroupStats();

assertEquals("Under replicated stats not matching!",
aggregatedStats[ClientProtocol.GET_STATS_LOW_REDUNDANCY_IDX],
aggregatedStats[ClientProtocol.GET_STATS_UNDER_REPLICATED_IDX]);
assertEquals("Low redundancy stats not matching!",
aggregatedStats[ClientProtocol.GET_STATS_LOW_REDUNDANCY_IDX],
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_LOW_REDUNDANCY_IDX],
aggregatedStats[ClientProtocol.GET_STATS_UNDER_REPLICATED_IDX],
"Under replicated stats not matching!");
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_LOW_REDUNDANCY_IDX],
replicatedBlockStats.getLowRedundancyBlocks() +
ecBlockGroupStats.getLowRedundancyBlockGroups());
assertEquals("Corrupt blocks stats not matching!",
aggregatedStats[ClientProtocol.GET_STATS_CORRUPT_BLOCKS_IDX],
replicatedBlockStats.getCorruptBlocks() +
ecBlockGroupStats.getCorruptBlockGroups());
assertEquals("Missing blocks stats not matching!",
aggregatedStats[ClientProtocol.GET_STATS_MISSING_BLOCKS_IDX],
ecBlockGroupStats.getLowRedundancyBlockGroups(),
"Low redundancy stats not matching!");
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_CORRUPT_BLOCKS_IDX],
replicatedBlockStats.getCorruptBlocks() + ecBlockGroupStats.getCorruptBlockGroups(),
"Corrupt blocks stats not matching!");
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_MISSING_BLOCKS_IDX],
replicatedBlockStats.getMissingReplicaBlocks() +
ecBlockGroupStats.getMissingBlockGroups());
assertEquals("Missing blocks with replication factor one not matching!",
aggregatedStats[ClientProtocol.GET_STATS_MISSING_REPL_ONE_BLOCKS_IDX],
replicatedBlockStats.getMissingReplicationOneBlocks());
assertEquals("Bytes in future blocks stats not matching!",
aggregatedStats[ClientProtocol.GET_STATS_BYTES_IN_FUTURE_BLOCKS_IDX],
ecBlockGroupStats.getMissingBlockGroups(),
"Missing blocks stats not matching!");
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_MISSING_REPL_ONE_BLOCKS_IDX],
replicatedBlockStats.getMissingReplicationOneBlocks(),
"Missing blocks with replication factor one not matching!");
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_BYTES_IN_FUTURE_BLOCKS_IDX],
replicatedBlockStats.getBytesInFutureBlocks() +
ecBlockGroupStats.getBytesInFutureBlockGroups());
assertEquals("Pending deletion blocks stats not matching!",
aggregatedStats[ClientProtocol.GET_STATS_PENDING_DELETION_BLOCKS_IDX],
ecBlockGroupStats.getBytesInFutureBlockGroups(),
"Bytes in future blocks stats not matching!");
assertEquals(aggregatedStats[ClientProtocol.GET_STATS_PENDING_DELETION_BLOCKS_IDX],
replicatedBlockStats.getPendingDeletionBlocks() +
ecBlockGroupStats.getPendingDeletionBlocks());
ecBlockGroupStats.getPendingDeletionBlocks(),
"Pending deletion blocks stats not matching!");
}

/**
Expand Down Expand Up @@ -1911,8 +1908,8 @@ public static DatanodeDescriptor getExpectedPrimaryNode(NameNode nn,
ExtendedBlock blk) {
BlockManager bm0 = nn.getNamesystem().getBlockManager();
BlockInfo storedBlock = bm0.getStoredBlock(blk.getLocalBlock());
assertTrue("Block " + blk + " should be under construction, " +
"got: " + storedBlock, !storedBlock.isComplete());
assertTrue(!storedBlock.isComplete(),
"Block " + blk + " should be under construction, " + "got: " + storedBlock);
// We expect that the replica with the most recent heart beat will be
// the one to be in charge of the synchronization / recovery protocol.
final DatanodeStorageInfo[] storages = storedBlock
Expand Down Expand Up @@ -1960,8 +1957,8 @@ public static void toolRun(Tool tool, String cmd, int retcode, String contain)
}
assertEquals(retcode, ret);
if (contain != null) {
assertTrue("The real output is: " + output + ".\n It should contain: "
+ contain, output.contains(contain));
assertTrue(output.contains(contain),
"The real output is: " + output + ".\n It should contain: " + contain);
}
}

Expand Down Expand Up @@ -2365,23 +2362,23 @@ public static void verifyDelete(FsShell shell, FileSystem fs, Path path,

public static void verifyDelete(FsShell shell, FileSystem fs, Path path,
Path trashPath, boolean shouldExistInTrash) throws Exception {
assertTrue(path + " file does not exist", fs.exists(path));
assertTrue(fs.exists(path), path + " file does not exist");

// Verify that trashPath has a path component named ".Trash"
Path checkTrash = trashPath;
while (!checkTrash.isRoot() && !checkTrash.getName().equals(".Trash")) {
checkTrash = checkTrash.getParent();
}
assertEquals("No .Trash component found in trash path " + trashPath,
".Trash", checkTrash.getName());
assertEquals(".Trash", checkTrash.getName(),
"No .Trash component found in trash path " + trashPath);

String[] argv = new String[]{"-rm", "-r", path.toString()};
int res = ToolRunner.run(shell, argv);
assertEquals("rm failed", 0, res);
assertEquals(0, res, "rm failed");
if (shouldExistInTrash) {
assertTrue("File not in trash : " + trashPath, fs.exists(trashPath));
assertTrue(fs.exists(trashPath), "File not in trash : " + trashPath);
} else {
assertFalse("File in trash : " + trashPath, fs.exists(trashPath));
assertFalse(fs.exists(trashPath), "File in trash : " + trashPath);
}
}

Expand Down Expand Up @@ -2590,7 +2587,7 @@ public static NameNodeConnector getNameNodeConnector(Configuration conf,
Path filePath, int namenodeCount, boolean createMoverPath)
throws IOException {
final Collection<URI> namenodes = DFSUtil.getInternalNsRpcUris(conf);
Assert.assertEquals(namenodeCount, namenodes.size());
assertEquals(namenodeCount, namenodes.size());
NameNodeConnector.checkOtherInstanceRunning(createMoverPath);
while (true) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,29 @@
*/
package org.apache.hadoop.hdfs;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.Timeout;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* Test striped file write operation with data node failures with parameterized
* test cases.
*/
@RunWith(Parameterized.class)
public class ParameterizedTestDFSStripedOutputStreamWithFailure extends
TestDFSStripedOutputStreamWithFailureBase{
public static final Logger LOG = LoggerFactory.getLogger(
ParameterizedTestDFSStripedOutputStreamWithFailure.class);

private int base;

@Parameterized.Parameters
public static Collection<Object[]> data() {
List<Object[]> parameters = new ArrayList<>();
for (int i = 0; i <= 10; i++) {
Expand All @@ -50,21 +48,24 @@ public static Collection<Object[]> data() {
return parameters;
}

public ParameterizedTestDFSStripedOutputStreamWithFailure(int base) {
this.base = base;
public void initParameterizedTestDFSStripedOutputStreamWithFailure(int pBase) {
this.base = pBase;
}

@Test(timeout = 240000)
public void runTestWithSingleFailure() {
@ParameterizedTest
@MethodSource("data")
@Timeout(value = 240)
public void runTestWithSingleFailure(int pBase) {
initParameterizedTestDFSStripedOutputStreamWithFailure(pBase);
assumeTrue(base >= 0);
if (base > lengths.size()) {
base = base % lengths.size();
}
final int i = base;
final Integer length = getLength(i);
assumeTrue("Skip test " + i + " since length=null.", length != null);
assumeTrue("Test " + i + ", length=" + length
+ ", is not chosen to run.", RANDOM.nextInt(16) != 0);
assumeTrue(length != null, "Skip test " + i + " since length=null.");
assumeTrue(RANDOM.nextInt(16) != 0, "Test " + i + ", length=" + length
+ ", is not chosen to run.");
System.out.println("Run test " + i + ", length=" + length);
runTest(length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
ParameterizedTestDFSStripedOutputStreamWithFailureWithRandomECPolicy
.class.getName());

public ParameterizedTestDFSStripedOutputStreamWithFailureWithRandomECPolicy(
int base) {
super(base);
public ParameterizedTestDFSStripedOutputStreamWithFailureWithRandomECPolicy() {
schema = StripedFileTestUtil.getRandomNonDefaultECPolicy().getSchema();
LOG.info(schema.toString());
}
Expand Down
Loading