mpryahin commented on a change in pull request #1952: HDFS-1820. FTPFileSystem
attempts to close the outputstream even when it is not initialised.
URL: https://github.com/apache/hadoop/pull/1952#discussion_r407166378
##########
File path:
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/ftp/TestFTPFileSystem.java
##########
@@ -37,9 +54,71 @@
*/
public class TestFTPFileSystem {
+ private TestFtpServer server;
+
@Rule
public Timeout testTimeout = new Timeout(180000);
+ @Before
+ public void setUp() throws Exception {
+ server = new TestFtpServer(GenericTestUtils.getTestDir().toPath()).start();
+ }
+
+ @After
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ public void tearDown() throws Exception {
+ server.stop();
+ Files.walk(server.getFtpRoot())
+ .sorted(Comparator.reverseOrder())
+ .map(java.nio.file.Path::toFile)
+ .forEach(File::delete);
+ }
+
+ @Test
+ public void testCreateWithWritePermissions() throws Exception {
+ BaseUser user = server.addUser("test", "password", new WritePermission());
+ Configuration configuration = new Configuration();
+ configuration.set("fs.defaultFS", "ftp:///");
+ configuration.set("fs.ftp.host", "localhost");
+ configuration.setInt("fs.ftp.host.port", server.getPort());
+ configuration.set("fs.ftp.user.localhost", user.getName());
+ configuration.set("fs.ftp.password.localhost", user.getPassword());
+ configuration.set("fs.ftp.impl.disable.cache", "true");
+
+ FileSystem fs = FileSystem.get(configuration);
+ byte[] bytesExpected = "hello world".getBytes(StandardCharsets.UTF_8);
+ try (FSDataOutputStream outputStream = fs.create(new Path("test1.txt"))) {
+ outputStream.write(bytesExpected);
+ }
+ try (FSDataInputStream input = fs.open(new Path("test1.txt"))) {
+ assertThat(bytesExpected, equalTo(IOUtils.readFullyToByteArray(input)));
+ }
+ }
+
+ @Test
+ public void testCreateWithoutWritePermissions() throws Exception {
+ BaseUser user = server.addUser("test", "password");
+ Configuration configuration = new Configuration();
+ configuration.set("fs.defaultFS", "ftp:///");
+ configuration.set("fs.ftp.host", "localhost");
+ configuration.setInt("fs.ftp.host.port", server.getPort());
+ configuration.set("fs.ftp.user.localhost", user.getName());
+ configuration.set("fs.ftp.password.localhost", user.getPassword());
+ configuration.set("fs.ftp.impl.disable.cache", "true");
+
+ FileSystem fs = FileSystem.get(configuration);
+ byte[] bytesExpected = "hello world".getBytes(StandardCharsets.UTF_8);
+
+ try (FSDataOutputStream outputStream = fs.create(new Path("test1.txt"))) {
+ outputStream.write(bytesExpected);
Review comment:
fixed, thank you!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]