Skip to content
Open
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 @@ -159,14 +159,10 @@ public Map<String, String> properties() {

@Override
public void close() {
io.close();

if (em instanceof Closeable) {
try {
((Closeable) em).close();
} catch (IOException e) {
throw new UncheckedIOException("Failed to close encryption manager", e);
}
try (Closeable closeableManager = em instanceof Closeable ? (Closeable) em : null) {
io.close();
} catch (IOException e) {
throw new UncheckedIOException("Failed to close encryption manager", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
package org.apache.iceberg.encryption;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.io.DelegateFileIO;
Expand Down Expand Up @@ -151,6 +154,39 @@ public void closeClosesEncryptionManagerWhenCloseable() throws Exception {
verify((Closeable) em).close();
}

@Test
public void closeClosesEncryptionManagerWhenFileIOCloseFails() throws Exception {
RuntimeException fileIOFailure = new RuntimeException("FileIO close failure");
EncryptionManager em =
mock(EncryptionManager.class, withSettings().extraInterfaces(Closeable.class));
DelegateFileIO delegate = mock(DelegateFileIO.class);
doThrow(fileIOFailure).when(delegate).close();

EncryptingFileIO fileIO = EncryptingFileIO.combine(delegate, em);

assertThatThrownBy(fileIO::close).isSameAs(fileIOFailure);
verify((Closeable) em).close();
}

@Test
public void closeSuppressesEncryptionManagerFailureWhenFileIOCloseFails() throws Exception {
RuntimeException fileIOFailure = new RuntimeException("FileIO close failure");
IOException managerFailure = new IOException("Encryption manager close failure");
EncryptionManager em =
mock(EncryptionManager.class, withSettings().extraInterfaces(Closeable.class));
Closeable closeableManager = (Closeable) em;
DelegateFileIO delegate = mock(DelegateFileIO.class);
doThrow(fileIOFailure).when(delegate).close();
doThrow(managerFailure).when(closeableManager).close();

EncryptingFileIO fileIO = EncryptingFileIO.combine(delegate, em);

assertThatThrownBy(fileIO::close)
.isSameAs(fileIOFailure)
.satisfies(failure -> assertThat(failure.getSuppressed()).containsExactly(managerFailure));
verify(closeableManager).close();
}

@Test
public void properties() {
EncryptionManager em = mock(EncryptionManager.class);
Expand Down
Loading