tpalfy commented on a change in pull request #3746: NIFI-6679 - Patch MoveHDFS
URL: https://github.com/apache/nifi/pull/3746#discussion_r325823361
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/MoveHDFS.java
 ##########
 @@ -357,9 +357,10 @@ public Object run() {
                         if (destinationExists) {
                             switch (processorConfig.getConflictResolution()) {
                                 case REPLACE_RESOLUTION:
-                                    if (hdfs.delete(file, false)) {
+                                    // Remove destination file (newFile) to 
replace
 
 Review comment:
   Maybe we could add some unit tests, something like this:
   ```java
   @Test
       public void testPutWhenAlreadyExistingShouldFailWhenFAIL_RESOLUTION() 
throws IOException {
           testPutWhenAlreadyExisting(MoveHDFS.FAIL_RESOLUTION, 
MoveHDFS.REL_FAILURE, "randombytes-1");
       }
   
       @Test
       public void 
testPutWhenAlreadyExistingShouldIgnoreWhenIGNORE_RESOLUTION() throws 
IOException {
           testPutWhenAlreadyExisting(MoveHDFS.IGNORE_RESOLUTION, 
MoveHDFS.REL_SUCCESS, "randombytes-1");
       }
   
       @Test
       public void 
testPutWhenAlreadyExistingShouldReplaceWhenREPLACE_RESOLUTION() throws 
IOException {
           testPutWhenAlreadyExisting(MoveHDFS.REPLACE_RESOLUTION, 
MoveHDFS.REL_SUCCESS, "randombytes-2");
       }
   
       private void testPutWhenAlreadyExisting(String conflictResolution, 
Relationship expectedDestination, String expectedContent) throws IOException {
           // GIVEN
           Files.createDirectories(Path.of(INPUT_DIRECTORY));
           Files.createDirectories(Path.of(OUTPUT_DIRECTORY));
           Files.copy(Path.of(TEST_DATA_DIRECTORY, "randombytes-2"), 
Path.of(INPUT_DIRECTORY, "randombytes-1"));
           Files.copy(Path.of(TEST_DATA_DIRECTORY, "randombytes-1"), 
Path.of(OUTPUT_DIRECTORY, "randombytes-1"));
   
           MoveHDFS processor = new MoveHDFS();
   
           TestRunner runner = TestRunners.newTestRunner(processor);
           runner.setProperty(MoveHDFS.INPUT_DIRECTORY_OR_FILE, 
INPUT_DIRECTORY);
           runner.setProperty(MoveHDFS.OUTPUT_DIRECTORY, OUTPUT_DIRECTORY);
           runner.setProperty(MoveHDFS.CONFLICT_RESOLUTION, conflictResolution);
   
           byte[] expected = Files.readAllBytes(Path.of(TEST_DATA_DIRECTORY, 
expectedContent));
   
           // WHEN
           runner.enqueue(new byte[0]);
           runner.run();
   
           // THEN
           runner.assertAllFlowFilesTransferred(expectedDestination);
   
           List<MockFlowFile> flowFiles = 
runner.getFlowFilesForRelationship(expectedDestination);
           Assert.assertEquals(1, flowFiles.size());
   
           byte[] actual = Files.readAllBytes(Path.of(OUTPUT_DIRECTORY, 
"randombytes-1"));
   
           assertArrayEquals(expected, actual);
       }
   ```

----------------------------------------------------------------
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

Reply via email to