Skip to content
Draft
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
36 changes: 24 additions & 12 deletions core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,27 @@ protected boolean supportsEmptyNamespace() {
return false;
}

@TempDir private Path tempDir;

protected String baseTableLocation(TableIdentifier identifier) {
return BASE_TABLE_LOCATION + "/" + identifier.namespace() + "/" + identifier.name();
}

protected URI resolveStorageLocation(String location) {
return URI.create(location);
}

protected URI createStorageFile(String filename, String content) throws IOException {
Path path = tempDir.resolve(filename);
path.toFile().deleteOnExit();
Files.writeString(path, content);
return path.toUri();
}

protected void moveStorageFile(URI source, URI target) throws IOException {
Files.move(Paths.get(source), Paths.get(target), StandardCopyOption.REPLACE_EXISTING);
}

@Test
public void testCreateNamespace() {
C catalog = catalog();
Expand Down Expand Up @@ -1009,7 +1026,7 @@ public void testLoadMissingTable() {
}

@Test
public void testLoadTableWithMissingMetadataFile(@TempDir Path tempDir) throws IOException {
public void testLoadTableWithMissingMetadataFile() throws IOException {
C catalog = catalog();

if (requiresNamespaceCreate()) {
Expand All @@ -1020,22 +1037,17 @@ public void testLoadTableWithMissingMetadataFile(@TempDir Path tempDir) throws I
assertThat(catalog.tableExists(TBL)).as("Table should exist").isTrue();

Table table = catalog.loadTable(TBL);
String metadataFileLocation =
((HasTableOperations) table).operations().current().metadataFileLocation();
Path renamedMetadataFile = tempDir.resolve("tmp.json");
renamedMetadataFile.toFile().deleteOnExit();
Files.writeString(renamedMetadataFile, "metadata");
Path metadataFilePath =
metadataFileLocation.startsWith("file:")
? Paths.get(URI.create(metadataFileLocation))
: Paths.get(metadataFileLocation);
URI metadataFileLocation =
resolveStorageLocation(
((HasTableOperations) table).operations().current().metadataFileLocation());
URI renamedMetadataFileLocation = createStorageFile("tmp.json", "metadata");
try {
Files.move(metadataFilePath, renamedMetadataFile, StandardCopyOption.REPLACE_EXISTING);
moveStorageFile(metadataFileLocation, renamedMetadataFileLocation);
assertThatThrownBy(() -> catalog.loadTable(TBL))
.isInstanceOf(NotFoundException.class)
.hasMessageContaining("Failed to open input stream for file: " + metadataFileLocation);
} finally {
Files.move(renamedMetadataFile, metadataFilePath, StandardCopyOption.REPLACE_EXISTING);
moveStorageFile(renamedMetadataFileLocation, metadataFileLocation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.HasTableOperations;
Expand All @@ -32,7 +30,6 @@
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class TestInMemoryCatalog extends CatalogTests<InMemoryCatalog> {
private InMemoryCatalog catalog;
Expand Down Expand Up @@ -89,7 +86,7 @@ protected boolean supportsNestedNamespaces() {

@Test
@Override
public void testLoadTableWithMissingMetadataFile(@TempDir Path tempDir) throws IOException {
public void testLoadTableWithMissingMetadataFile() {

if (requiresNamespaceCreate()) {
catalog.createNamespace(TBL.namespace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3678,7 +3678,7 @@ private void verifyCreatePost(Namespace ns, Map<String, String> headers) {

@Test
@Override
public void testLoadTableWithMissingMetadataFile(@TempDir Path tempDir) {
public void testLoadTableWithMissingMetadataFile() {

if (requiresNamespaceCreate()) {
restCatalog.createNamespace(TBL.namespace());
Expand Down
Loading