MAPREDUCE-7417. Upgrade Junit 4 to 5 in hadoop-mapreduce-client-uploader (#5019)
Co-authored-by: Ashutosh Gupta <ashugpt@amazon.com> Reviewed-by: Shilun Fan <slfan1989@apache.org> Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
This commit is contained in:
parent
168fa07801
commit
082266516a
@ -53,6 +53,21 @@
|
|||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-launcher</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Needed for generating FindBugs warnings using parent pom -->
|
<!-- Needed for generating FindBugs warnings using parent pom -->
|
||||||
|
@ -32,10 +32,9 @@
|
|||||||
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
||||||
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
import org.apache.hadoop.hdfs.HdfsConfiguration;
|
||||||
import org.apache.hadoop.util.Lists;
|
import org.apache.hadoop.util.Lists;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.Assume;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -55,6 +54,9 @@
|
|||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
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 static org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY;
|
import static org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +65,7 @@
|
|||||||
public class TestFrameworkUploader {
|
public class TestFrameworkUploader {
|
||||||
private static String testDir;
|
private static String testDir;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
String testRootDir =
|
String testRootDir =
|
||||||
new File(System.getProperty("test.build.data", "/tmp"))
|
new File(System.getProperty("test.build.data", "/tmp"))
|
||||||
@ -79,11 +81,11 @@ public void setUp() {
|
|||||||
* @throws IOException test failure
|
* @throws IOException test failure
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testHelp() throws IOException {
|
void testHelp() throws IOException {
|
||||||
String[] args = new String[]{"-help"};
|
String[] args = new String[]{"-help"};
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
boolean success = uploader.parseArguments(args);
|
boolean success = uploader.parseArguments(args);
|
||||||
Assert.assertFalse("Expected to print help", success);
|
assertFalse(success, "Expected to print help");
|
||||||
assertThat(uploader.input)
|
assertThat(uploader.input)
|
||||||
.withFailMessage("Expected ignore run")
|
.withFailMessage("Expected ignore run")
|
||||||
.isNull();
|
.isNull();
|
||||||
@ -100,11 +102,11 @@ public void testHelp() throws IOException {
|
|||||||
* @throws IOException test failure
|
* @throws IOException test failure
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWrongArgument() throws IOException {
|
void testWrongArgument() throws IOException {
|
||||||
String[] args = new String[]{"-unexpected"};
|
String[] args = new String[]{"-unexpected"};
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
boolean success = uploader.parseArguments(args);
|
boolean success = uploader.parseArguments(args);
|
||||||
Assert.assertFalse("Expected to print help", success);
|
assertFalse(success, "Expected to print help");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,7 +114,7 @@ public void testWrongArgument() throws IOException {
|
|||||||
* @throws IOException test failure
|
* @throws IOException test failure
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testArguments() throws IOException {
|
void testArguments() throws IOException {
|
||||||
String[] args =
|
String[] args =
|
||||||
new String[]{
|
new String[]{
|
||||||
"-input", "A",
|
"-input", "A",
|
||||||
@ -126,60 +128,67 @@ public void testArguments() throws IOException {
|
|||||||
"-timeout", "10"};
|
"-timeout", "10"};
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
boolean success = uploader.parseArguments(args);
|
boolean success = uploader.parseArguments(args);
|
||||||
Assert.assertTrue("Expected to print help", success);
|
assertTrue(success, "Expected to print help");
|
||||||
Assert.assertEquals("Input mismatch", "A",
|
assertEquals("A",
|
||||||
uploader.input);
|
uploader.input,
|
||||||
Assert.assertEquals("Whitelist mismatch", "B",
|
"Input mismatch");
|
||||||
uploader.whitelist);
|
assertEquals("B",
|
||||||
Assert.assertEquals("Blacklist mismatch", "C",
|
uploader.whitelist,
|
||||||
uploader.blacklist);
|
"Whitelist mismatch");
|
||||||
Assert.assertEquals("Target mismatch", "hdfs://C:8020/D",
|
assertEquals("C",
|
||||||
uploader.target);
|
uploader.blacklist,
|
||||||
Assert.assertEquals("Initial replication mismatch", 100,
|
"Blacklist mismatch");
|
||||||
uploader.initialReplication);
|
assertEquals("hdfs://C:8020/D",
|
||||||
Assert.assertEquals("Acceptable replication mismatch", 120,
|
uploader.target,
|
||||||
uploader.acceptableReplication);
|
"Target mismatch");
|
||||||
Assert.assertEquals("Final replication mismatch", 140,
|
assertEquals(100,
|
||||||
uploader.finalReplication);
|
uploader.initialReplication,
|
||||||
Assert.assertEquals("Timeout mismatch", 10,
|
"Initial replication mismatch");
|
||||||
uploader.timeout);
|
assertEquals(120,
|
||||||
|
uploader.acceptableReplication,
|
||||||
|
"Acceptable replication mismatch");
|
||||||
|
assertEquals(140,
|
||||||
|
uploader.finalReplication,
|
||||||
|
"Final replication mismatch");
|
||||||
|
assertEquals(10,
|
||||||
|
uploader.timeout,
|
||||||
|
"Timeout mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the default ways how to specify filesystems.
|
* Test the default ways how to specify filesystems.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNoFilesystem() throws IOException {
|
void testNoFilesystem() throws IOException {
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
boolean success = uploader.parseArguments(new String[]{});
|
boolean success = uploader.parseArguments(new String[]{});
|
||||||
Assert.assertTrue("Expected to parse arguments", success);
|
assertTrue(success, "Expected to parse arguments");
|
||||||
Assert.assertEquals(
|
assertEquals(
|
||||||
"Expected",
|
"file:////usr/lib/mr-framework.tar.gz#mr-framework", uploader.target, "Expected");
|
||||||
"file:////usr/lib/mr-framework.tar.gz#mr-framework", uploader.target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the default ways how to specify filesystems.
|
* Test the default ways how to specify filesystems.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultFilesystem() throws IOException {
|
void testDefaultFilesystem() throws IOException {
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://namenode:555");
|
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://namenode:555");
|
||||||
uploader.setConf(conf);
|
uploader.setConf(conf);
|
||||||
boolean success = uploader.parseArguments(new String[]{});
|
boolean success = uploader.parseArguments(new String[]{});
|
||||||
Assert.assertTrue("Expected to parse arguments", success);
|
assertTrue(success, "Expected to parse arguments");
|
||||||
Assert.assertEquals(
|
assertEquals(
|
||||||
"Expected",
|
|
||||||
"hdfs://namenode:555/usr/lib/mr-framework.tar.gz#mr-framework",
|
"hdfs://namenode:555/usr/lib/mr-framework.tar.gz#mr-framework",
|
||||||
uploader.target);
|
uploader.target,
|
||||||
|
"Expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the explicit filesystem specification.
|
* Test the explicit filesystem specification.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExplicitFilesystem() throws IOException {
|
void testExplicitFilesystem() throws IOException {
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
uploader.setConf(conf);
|
uploader.setConf(conf);
|
||||||
@ -187,18 +196,18 @@ public void testExplicitFilesystem() throws IOException {
|
|||||||
"-target",
|
"-target",
|
||||||
"hdfs://namenode:555/usr/lib/mr-framework.tar.gz#mr-framework"
|
"hdfs://namenode:555/usr/lib/mr-framework.tar.gz#mr-framework"
|
||||||
});
|
});
|
||||||
Assert.assertTrue("Expected to parse arguments", success);
|
assertTrue(success, "Expected to parse arguments");
|
||||||
Assert.assertEquals(
|
assertEquals(
|
||||||
"Expected",
|
|
||||||
"hdfs://namenode:555/usr/lib/mr-framework.tar.gz#mr-framework",
|
"hdfs://namenode:555/usr/lib/mr-framework.tar.gz#mr-framework",
|
||||||
uploader.target);
|
uploader.target,
|
||||||
|
"Expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the conflicting filesystem specification.
|
* Test the conflicting filesystem specification.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testConflictingFilesystem() throws IOException {
|
void testConflictingFilesystem() throws IOException {
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://namenode:555");
|
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://namenode:555");
|
||||||
@ -207,11 +216,11 @@ public void testConflictingFilesystem() throws IOException {
|
|||||||
"-target",
|
"-target",
|
||||||
"file:///usr/lib/mr-framework.tar.gz#mr-framework"
|
"file:///usr/lib/mr-framework.tar.gz#mr-framework"
|
||||||
});
|
});
|
||||||
Assert.assertTrue("Expected to parse arguments", success);
|
assertTrue(success, "Expected to parse arguments");
|
||||||
Assert.assertEquals(
|
assertEquals(
|
||||||
"Expected",
|
|
||||||
"file:///usr/lib/mr-framework.tar.gz#mr-framework",
|
"file:///usr/lib/mr-framework.tar.gz#mr-framework",
|
||||||
uploader.target);
|
uploader.target,
|
||||||
|
"Expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,27 +228,27 @@ public void testConflictingFilesystem() throws IOException {
|
|||||||
* @throws IOException test failure
|
* @throws IOException test failure
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCollectPackages() throws IOException, UploaderException {
|
void testCollectPackages() throws IOException, UploaderException {
|
||||||
File parent = new File(testDir);
|
File parent = new File(testDir);
|
||||||
try {
|
try {
|
||||||
parent.deleteOnExit();
|
parent.deleteOnExit();
|
||||||
Assert.assertTrue("Directory creation failed", parent.mkdirs());
|
assertTrue(parent.mkdirs(), "Directory creation failed");
|
||||||
File dirA = new File(parent, "A");
|
File dirA = new File(parent, "A");
|
||||||
Assert.assertTrue(dirA.mkdirs());
|
assertTrue(dirA.mkdirs());
|
||||||
File dirB = new File(parent, "B");
|
File dirB = new File(parent, "B");
|
||||||
Assert.assertTrue(dirB.mkdirs());
|
assertTrue(dirB.mkdirs());
|
||||||
File jarA = new File(dirA, "a.jar");
|
File jarA = new File(dirA, "a.jar");
|
||||||
Assert.assertTrue(jarA.createNewFile());
|
assertTrue(jarA.createNewFile());
|
||||||
File jarB = new File(dirA, "b.jar");
|
File jarB = new File(dirA, "b.jar");
|
||||||
Assert.assertTrue(jarB.createNewFile());
|
assertTrue(jarB.createNewFile());
|
||||||
File jarC = new File(dirA, "c.jar");
|
File jarC = new File(dirA, "c.jar");
|
||||||
Assert.assertTrue(jarC.createNewFile());
|
assertTrue(jarC.createNewFile());
|
||||||
File txtD = new File(dirA, "d.txt");
|
File txtD = new File(dirA, "d.txt");
|
||||||
Assert.assertTrue(txtD.createNewFile());
|
assertTrue(txtD.createNewFile());
|
||||||
File jarD = new File(dirB, "d.jar");
|
File jarD = new File(dirB, "d.jar");
|
||||||
Assert.assertTrue(jarD.createNewFile());
|
assertTrue(jarD.createNewFile());
|
||||||
File txtE = new File(dirB, "e.txt");
|
File txtE = new File(dirB, "e.txt");
|
||||||
Assert.assertTrue(txtE.createNewFile());
|
assertTrue(txtE.createNewFile());
|
||||||
|
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
uploader.whitelist = ".*a\\.jar,.*b\\.jar,.*d\\.jar";
|
uploader.whitelist = ".*a\\.jar,.*b\\.jar,.*d\\.jar";
|
||||||
@ -248,19 +257,22 @@ public void testCollectPackages() throws IOException, UploaderException {
|
|||||||
File.pathSeparatorChar +
|
File.pathSeparatorChar +
|
||||||
dirB.getAbsolutePath() + File.separatorChar + "*";
|
dirB.getAbsolutePath() + File.separatorChar + "*";
|
||||||
uploader.collectPackages();
|
uploader.collectPackages();
|
||||||
Assert.assertEquals("Whitelist count error", 3,
|
assertEquals(3,
|
||||||
uploader.whitelistedFiles.size());
|
uploader.whitelistedFiles.size(),
|
||||||
Assert.assertEquals("Blacklist count error", 1,
|
"Whitelist count error");
|
||||||
uploader.blacklistedFiles.size());
|
assertEquals(1,
|
||||||
|
uploader.blacklistedFiles.size(),
|
||||||
|
"Blacklist count error");
|
||||||
|
|
||||||
Assert.assertTrue("File not collected",
|
assertTrue(uploader.filteredInputFiles.contains(jarA.getAbsolutePath()),
|
||||||
uploader.filteredInputFiles.contains(jarA.getAbsolutePath()));
|
"File not collected");
|
||||||
Assert.assertFalse("File collected",
|
assertFalse(uploader.filteredInputFiles.contains(jarB.getAbsolutePath()),
|
||||||
uploader.filteredInputFiles.contains(jarB.getAbsolutePath()));
|
"File collected");
|
||||||
Assert.assertTrue("File not collected",
|
assertTrue(uploader.filteredInputFiles.contains(jarD.getAbsolutePath()),
|
||||||
uploader.filteredInputFiles.contains(jarD.getAbsolutePath()));
|
"File not collected");
|
||||||
Assert.assertEquals("Too many whitelists", 2,
|
assertEquals(2,
|
||||||
uploader.filteredInputFiles.size());
|
uploader.filteredInputFiles.size(),
|
||||||
|
"Too many whitelists");
|
||||||
} finally {
|
} finally {
|
||||||
FileUtils.deleteDirectory(parent);
|
FileUtils.deleteDirectory(parent);
|
||||||
}
|
}
|
||||||
@ -270,10 +282,10 @@ public void testCollectPackages() throws IOException, UploaderException {
|
|||||||
* Test building a tarball from source jars.
|
* Test building a tarball from source jars.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBuildTarBall()
|
void testBuildTarBall()
|
||||||
throws IOException, UploaderException, InterruptedException {
|
throws IOException, UploaderException, InterruptedException {
|
||||||
String[] testFiles = {"upload.tar", "upload.tar.gz"};
|
String[] testFiles = {"upload.tar", "upload.tar.gz"};
|
||||||
for (String testFile: testFiles) {
|
for (String testFile : testFiles) {
|
||||||
File parent = new File(testDir);
|
File parent = new File(testDir);
|
||||||
try {
|
try {
|
||||||
parent.deleteOnExit();
|
parent.deleteOnExit();
|
||||||
@ -304,14 +316,14 @@ public void testBuildTarBall()
|
|||||||
TarArchiveEntry entry2 = result.getNextTarEntry();
|
TarArchiveEntry entry2 = result.getNextTarEntry();
|
||||||
fileNames.add(entry2.getName());
|
fileNames.add(entry2.getName());
|
||||||
sizes.add(entry2.getSize());
|
sizes.add(entry2.getSize());
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File name error", fileNames.contains("a.jar"));
|
fileNames.contains("a.jar"), "File name error");
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File size error", sizes.contains((long) 13));
|
sizes.contains((long) 13), "File size error");
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File name error", fileNames.contains("b.jar"));
|
fileNames.contains("b.jar"), "File name error");
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File size error", sizes.contains((long) 14));
|
sizes.contains((long) 14), "File size error");
|
||||||
} finally {
|
} finally {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
result.close();
|
result.close();
|
||||||
@ -327,7 +339,7 @@ public void testBuildTarBall()
|
|||||||
* Test upload to HDFS.
|
* Test upload to HDFS.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpload()
|
void testUpload()
|
||||||
throws IOException, UploaderException, InterruptedException {
|
throws IOException, UploaderException, InterruptedException {
|
||||||
final String fileName = "/upload.tar.gz";
|
final String fileName = "/upload.tar.gz";
|
||||||
File parent = new File(testDir);
|
File parent = new File(testDir);
|
||||||
@ -351,14 +363,14 @@ public void testUpload()
|
|||||||
TarArchiveEntry entry2 = archiveInputStream.getNextTarEntry();
|
TarArchiveEntry entry2 = archiveInputStream.getNextTarEntry();
|
||||||
fileNames.add(entry2.getName());
|
fileNames.add(entry2.getName());
|
||||||
sizes.add(entry2.getSize());
|
sizes.add(entry2.getSize());
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File name error", fileNames.contains("a.jar"));
|
fileNames.contains("a.jar"), "File name error");
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File size error", sizes.contains((long) 13));
|
sizes.contains((long) 13), "File size error");
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File name error", fileNames.contains("b.jar"));
|
fileNames.contains("b.jar"), "File name error");
|
||||||
Assert.assertTrue(
|
assertTrue(
|
||||||
"File size error", sizes.contains((long) 14));
|
sizes.contains((long) 14), "File size error");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
FileUtils.deleteDirectory(parent);
|
FileUtils.deleteDirectory(parent);
|
||||||
@ -370,9 +382,9 @@ public void testUpload()
|
|||||||
*/
|
*/
|
||||||
private FrameworkUploader prepareTree(File parent)
|
private FrameworkUploader prepareTree(File parent)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
Assert.assertTrue(parent.mkdirs());
|
assertTrue(parent.mkdirs());
|
||||||
File dirA = new File(parent, "A");
|
File dirA = new File(parent, "A");
|
||||||
Assert.assertTrue(dirA.mkdirs());
|
assertTrue(dirA.mkdirs());
|
||||||
File jarA = new File(parent, "a.jar");
|
File jarA = new File(parent, "a.jar");
|
||||||
PrintStream printStream = new PrintStream(new FileOutputStream(jarA));
|
PrintStream printStream = new PrintStream(new FileOutputStream(jarA));
|
||||||
printStream.println("Hello World!");
|
printStream.println("Hello World!");
|
||||||
@ -393,7 +405,7 @@ private FrameworkUploader prepareTree(File parent)
|
|||||||
* Test regex pattern matching and environment variable replacement.
|
* Test regex pattern matching and environment variable replacement.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEnvironmentReplacement() throws UploaderException {
|
void testEnvironmentReplacement() throws UploaderException {
|
||||||
String input = "C/$A/B,$B,D";
|
String input = "C/$A/B,$B,D";
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("A", "X");
|
map.put("A", "X");
|
||||||
@ -401,7 +413,7 @@ public void testEnvironmentReplacement() throws UploaderException {
|
|||||||
map.put("C", "Z");
|
map.put("C", "Z");
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
String output = uploader.expandEnvironmentVariables(input, map);
|
String output = uploader.expandEnvironmentVariables(input, map);
|
||||||
Assert.assertEquals("Environment not expanded", "C/X/B,Y,D", output);
|
assertEquals("C/X/B,Y,D", output, "Environment not expanded");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,7 +421,7 @@ public void testEnvironmentReplacement() throws UploaderException {
|
|||||||
* Test regex pattern matching and environment variable replacement.
|
* Test regex pattern matching and environment variable replacement.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRecursiveEnvironmentReplacement()
|
void testRecursiveEnvironmentReplacement()
|
||||||
throws UploaderException {
|
throws UploaderException {
|
||||||
String input = "C/$A/B,$B,D";
|
String input = "C/$A/B,$B,D";
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
@ -418,7 +430,7 @@ public void testRecursiveEnvironmentReplacement()
|
|||||||
map.put("C", "Y");
|
map.put("C", "Y");
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
String output = uploader.expandEnvironmentVariables(input, map);
|
String output = uploader.expandEnvironmentVariables(input, map);
|
||||||
Assert.assertEquals("Environment not expanded", "C/X/B,Y,D", output);
|
assertEquals("C/X/B,Y,D", output, "Environment not expanded");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,20 +438,20 @@ public void testRecursiveEnvironmentReplacement()
|
|||||||
* Test native IO.
|
* Test native IO.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNativeIO() throws IOException {
|
void testNativeIO() throws IOException {
|
||||||
FrameworkUploader uploader = new FrameworkUploader();
|
FrameworkUploader uploader = new FrameworkUploader();
|
||||||
File parent = new File(testDir);
|
File parent = new File(testDir);
|
||||||
try {
|
try {
|
||||||
// Create a parent directory
|
// Create a parent directory
|
||||||
parent.deleteOnExit();
|
parent.deleteOnExit();
|
||||||
Assert.assertTrue(parent.mkdirs());
|
assertTrue(parent.mkdirs());
|
||||||
|
|
||||||
// Create a target file
|
// Create a target file
|
||||||
File targetFile = new File(parent, "a.txt");
|
File targetFile = new File(parent, "a.txt");
|
||||||
try(FileOutputStream os = new FileOutputStream(targetFile)) {
|
try (FileOutputStream os = new FileOutputStream(targetFile)) {
|
||||||
IOUtils.writeLines(Lists.newArrayList("a", "b"), null, os, StandardCharsets.UTF_8);
|
IOUtils.writeLines(Lists.newArrayList("a", "b"), null, os, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
Assert.assertFalse(uploader.checkSymlink(targetFile));
|
assertFalse(uploader.checkSymlink(targetFile));
|
||||||
|
|
||||||
// Create a symlink to the target
|
// Create a symlink to the target
|
||||||
File symlinkToTarget = new File(parent, "symlinkToTarget.txt");
|
File symlinkToTarget = new File(parent, "symlinkToTarget.txt");
|
||||||
@ -449,22 +461,22 @@ public void testNativeIO() throws IOException {
|
|||||||
Paths.get(targetFile.getAbsolutePath()));
|
Paths.get(targetFile.getAbsolutePath()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// Symlinks are not supported, so ignore the test
|
// Symlinks are not supported, so ignore the test
|
||||||
Assume.assumeTrue(false);
|
Assumptions.assumeTrue(false);
|
||||||
}
|
}
|
||||||
Assert.assertTrue(uploader.checkSymlink(symlinkToTarget));
|
assertTrue(uploader.checkSymlink(symlinkToTarget));
|
||||||
|
|
||||||
// Create a symlink to the target with /./ in the path
|
// Create a symlink to the target with /./ in the path
|
||||||
symlinkToTarget = new File(parent.getAbsolutePath() +
|
symlinkToTarget = new File(parent.getAbsolutePath() +
|
||||||
"/./symlinkToTarget2.txt");
|
"/./symlinkToTarget2.txt");
|
||||||
try {
|
try {
|
||||||
Files.createSymbolicLink(
|
Files.createSymbolicLink(
|
||||||
Paths.get(symlinkToTarget.getAbsolutePath()),
|
Paths.get(symlinkToTarget.getAbsolutePath()),
|
||||||
Paths.get(targetFile.getAbsolutePath()));
|
Paths.get(targetFile.getAbsolutePath()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// Symlinks are not supported, so ignore the test
|
// Symlinks are not supported, so ignore the test
|
||||||
Assume.assumeTrue(false);
|
Assumptions.assumeTrue(false);
|
||||||
}
|
}
|
||||||
Assert.assertTrue(uploader.checkSymlink(symlinkToTarget));
|
assertTrue(uploader.checkSymlink(symlinkToTarget));
|
||||||
|
|
||||||
// Create a symlink outside the current directory
|
// Create a symlink outside the current directory
|
||||||
File symlinkOutside = new File(parent, "symlinkToParent.txt");
|
File symlinkOutside = new File(parent, "symlinkToParent.txt");
|
||||||
@ -474,9 +486,9 @@ public void testNativeIO() throws IOException {
|
|||||||
Paths.get(parent.getAbsolutePath()));
|
Paths.get(parent.getAbsolutePath()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// Symlinks are not supported, so ignore the test
|
// Symlinks are not supported, so ignore the test
|
||||||
Assume.assumeTrue(false);
|
Assumptions.assumeTrue(false);
|
||||||
}
|
}
|
||||||
Assert.assertFalse(uploader.checkSymlink(symlinkOutside));
|
assertFalse(uploader.checkSymlink(symlinkOutside));
|
||||||
} finally {
|
} finally {
|
||||||
FileUtils.forceDelete(parent);
|
FileUtils.forceDelete(parent);
|
||||||
}
|
}
|
||||||
@ -484,14 +496,14 @@ public void testNativeIO() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPermissionSettingsOnRestrictiveUmask()
|
void testPermissionSettingsOnRestrictiveUmask()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
File parent = new File(testDir);
|
File parent = new File(testDir);
|
||||||
parent.deleteOnExit();
|
parent.deleteOnExit();
|
||||||
MiniDFSCluster cluster = null;
|
MiniDFSCluster cluster = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Assert.assertTrue("Directory creation failed", parent.mkdirs());
|
assertTrue(parent.mkdirs(), "Directory creation failed");
|
||||||
Configuration hdfsConf = new HdfsConfiguration();
|
Configuration hdfsConf = new HdfsConfiguration();
|
||||||
String namenodeDir = new File(MiniDFSCluster.getBaseDirectory(),
|
String namenodeDir = new File(MiniDFSCluster.getBaseDirectory(),
|
||||||
"name").getAbsolutePath();
|
"name").getAbsolutePath();
|
||||||
@ -525,7 +537,7 @@ public void testPermissionSettingsOnRestrictiveUmask()
|
|||||||
|
|
||||||
FileStatus fileStatus = dfs.getFileStatus(new Path(targetPath));
|
FileStatus fileStatus = dfs.getFileStatus(new Path(targetPath));
|
||||||
FsPermission perm = fileStatus.getPermission();
|
FsPermission perm = fileStatus.getPermission();
|
||||||
Assert.assertEquals("Permissions", new FsPermission(0644), perm);
|
assertEquals(new FsPermission(0644), perm, "Permissions");
|
||||||
} finally {
|
} finally {
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
cluster.close();
|
cluster.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user