Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-8200: Modifying PutAzureDataLakeStorage to delete temp file if e… #4815

Closed
wants to merge 10 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
if (length > 0) {
try (final InputStream rawIn = session.read(flowFile); final BufferedInputStream bufferedIn = new BufferedInputStream(rawIn)) {
uploadContent(fileClient, bufferedIn, length);
} catch (Exception e) {
fileClient.delete();
throw e;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception e is suppressed if fileClient.delete() also throws an exception. My recommendation is to put a try-catch-finally around delete(). In the catch only an error message needs to be logged, and in the finally the original exception 'e' can be thrown forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help, corrected in the next commit

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.junit.Ignore;
import org.junit.Test;

import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -43,6 +44,11 @@
import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR_NAME_PRIMARY_URI;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class ITPutAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT {

Expand Down Expand Up @@ -241,6 +247,17 @@ public void testPutFileWithELButFileNameIsNotSpecified() {
assertFailure();
}

@Test(expected = NullPointerException.class)
public void testPutFileButFailedToAppend() {
DataLakeFileClient fileClient = mock(DataLakeFileClient.class);
InputStream stream = mock(InputStream.class);
doThrow(NullPointerException.class).when(fileClient).append(any(InputStream.class), anyLong(), anyLong());

PutAzureDataLakeStorage.uploadContent(fileClient, stream, FILE_DATA.length);

verify(fileClient).delete();
}

private Map<String, String> createAttributesMap() {
Map<String, String> attributes = new HashMap<>();

Expand Down