Skip to content

Commit

Permalink
Core, Data, Flink, Spark: Improve tableDir initialization for tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra authored Nov 5, 2024
1 parent 20e0e3d commit 67ee082
Show file tree
Hide file tree
Showing 51 changed files with 32 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ public void testPartitionedDeleteIndex() {

@TestTemplate
public void testUnpartitionedTableScan() throws IOException {
File location = Files.createTempDirectory(temp, "junit").toFile();
assertThat(location.delete()).isTrue();

Table unpartitioned =
TestTables.create(location, "unpartitioned", SCHEMA, PartitionSpec.unpartitioned(), 2);
TestTables.create(tableDir, "unpartitioned", SCHEMA, PartitionSpec.unpartitioned(), 2);

DataFile unpartitionedFile = unpartitionedFile(unpartitioned.spec());
unpartitioned.newAppend().appendFile(unpartitionedFile).commit();
Expand Down
10 changes: 1 addition & 9 deletions core/src/test/java/org/apache/iceberg/FilterFilesTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
import org.apache.iceberg.types.Conversions;
import org.apache.iceberg.types.Types;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -50,12 +47,7 @@ public abstract class FilterFilesTestBase<
private final Schema schema =
new Schema(
required(1, "id", Types.IntegerType.get()), required(2, "data", Types.StringType.get()));
private File tableDir = null;

@BeforeEach
public void setupTableDir() throws IOException {
this.tableDir = Files.createTempDirectory(temp, "junit").toFile();
}
@TempDir private File tableDir;

@AfterEach
public void cleanupTables() {
Expand Down
15 changes: 7 additions & 8 deletions core/src/test/java/org/apache/iceberg/ScanTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -149,9 +147,8 @@ public void testReAddingPartitionField() throws Exception {
required(2, "b", Types.StringType.get()),
required(3, "data", Types.IntegerType.get()));
PartitionSpec initialSpec = PartitionSpec.builderFor(schema).identity("a").build();
File dir = Files.createTempDirectory(temp, "junit").toFile();
dir.delete();
this.table = TestTables.create(dir, "test_part_evolution", schema, initialSpec, formatVersion);
this.table =
TestTables.create(tableDir, "test_part_evolution", schema, initialSpec, formatVersion);
table
.newFastAppend()
.appendFile(
Expand Down Expand Up @@ -222,11 +219,13 @@ public void testDataFileSorted() throws Exception {
Schema schema =
new Schema(
required(1, "a", Types.IntegerType.get()), required(2, "b", Types.StringType.get()));
File dir = Files.createTempDirectory(temp, "junit").toFile();
dir.delete();
this.table =
TestTables.create(
dir, "test_data_file_sorted", schema, PartitionSpec.unpartitioned(), formatVersion);
tableDir,
"test_data_file_sorted",
schema,
PartitionSpec.unpartitioned(),
formatVersion);
table
.newFastAppend()
.appendFile(
Expand Down
29 changes: 0 additions & 29 deletions core/src/test/java/org/apache/iceberg/TestCreateTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import org.apache.iceberg.exceptions.CommitFailedException;
Expand All @@ -45,9 +43,6 @@ protected static List<Object> parameters() {

@TestTemplate
public void testCreateTransaction() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_create", SCHEMA, unpartitioned());

assertThat(TestTables.readMetadata("test_create")).isNull();
Expand All @@ -68,9 +63,6 @@ public void testCreateTransaction() throws IOException {

@TestTemplate
public void testCreateTransactionAndUpdateSchema() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_create", SCHEMA, unpartitioned());

assertThat(TestTables.readMetadata("test_create")).isNull();
Expand Down Expand Up @@ -105,9 +97,6 @@ public void testCreateTransactionAndUpdateSchema() throws IOException {

@TestTemplate
public void testCreateAndAppendWithTransaction() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_append", SCHEMA, unpartitioned());

assertThat(TestTables.readMetadata("test_append")).isNull();
Expand All @@ -134,9 +123,6 @@ public void testCreateAndAppendWithTransaction() throws IOException {

@TestTemplate
public void testCreateAndAppendWithTable() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_append", SCHEMA, unpartitioned());

assertThat(TestTables.readMetadata("test_append"))
Expand Down Expand Up @@ -167,9 +153,6 @@ public void testCreateAndAppendWithTable() throws IOException {

@TestTemplate
public void testCreateAndUpdatePropertiesWithTransaction() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_properties", SCHEMA, unpartitioned());

assertThat(TestTables.readMetadata("test_properties")).isNull();
Expand All @@ -196,9 +179,6 @@ public void testCreateAndUpdatePropertiesWithTransaction() throws IOException {

@TestTemplate
public void testCreateAndUpdatePropertiesWithTable() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_properties", SCHEMA, unpartitioned());

assertThat(TestTables.readMetadata("test_properties")).isNull();
Expand Down Expand Up @@ -227,9 +207,6 @@ public void testCreateAndUpdatePropertiesWithTable() throws IOException {

@TestTemplate
public void testCreateDetectsUncommittedChange() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn =
TestTables.beginCreate(tableDir, "uncommitted_change", SCHEMA, unpartitioned());

Expand All @@ -245,9 +222,6 @@ public void testCreateDetectsUncommittedChange() throws IOException {

@TestTemplate
public void testCreateDetectsUncommittedChangeOnCommit() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn =
TestTables.beginCreate(tableDir, "uncommitted_change", SCHEMA, unpartitioned());

Expand All @@ -263,9 +237,6 @@ public void testCreateDetectsUncommittedChangeOnCommit() throws IOException {

@TestTemplate
public void testCreateTransactionConflict() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Transaction txn = TestTables.beginCreate(tableDir, "test_conflict", SCHEMA, SPEC);

// append in the transaction to ensure a manifest file is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1066,7 +1065,6 @@ public void testPartitionSpecEvolutionRemoval() {
@TestTemplate
public void testPartitionColumnNamedPartition() throws Exception {
TestTables.clearTables();
this.tableDir = Files.createTempDirectory(temp, "junit").toFile();

Schema schema =
new Schema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
Expand All @@ -45,9 +44,6 @@ public class TestMetadataTableScansWithPartitionEvolution extends MetadataTableS
@BeforeEach
public void createTable() throws IOException {
TestTables.clearTables();
this.tableDir = Files.createTempDirectory(temp, "junit").toFile();
tableDir.delete();

Schema schema =
new Schema(
required(1, "id", Types.IntegerType.get()),
Expand Down
10 changes: 2 additions & 8 deletions core/src/test/java/org/apache/iceberg/TestMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -72,7 +71,8 @@ public static List<Object> parameters() {
return Arrays.asList(1, 2, 3);
}

@TempDir public Path temp;
@TempDir protected Path temp;
@TempDir private File tableDir;

private static final StructType LEAF_STRUCT_TYPE =
StructType.of(
Expand Down Expand Up @@ -676,9 +676,6 @@ public void testTruncateBinaryMetricsMode() throws IOException {

@TestTemplate
public void testSortedColumnMetrics() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue(); // created by table create

SortOrder sortOrder =
SortOrder.builderFor(SIMPLE_SCHEMA)
.asc("booleanCol")
Expand Down Expand Up @@ -739,9 +736,6 @@ public void testSortedColumnMetrics() throws IOException {

@TestTemplate
public void testMetricsForSortedNestedStructFields() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue(); // created by table create

SortOrder sortOrder =
SortOrder.builderFor(NESTED_SCHEMA)
.asc("nestedStructCol.longCol")
Expand Down
11 changes: 1 addition & 10 deletions core/src/test/java/org/apache/iceberg/TestMetricsModes.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
Expand All @@ -42,6 +41,7 @@

@ExtendWith(ParameterizedTestExtension.class)
public class TestMetricsModes {
@TempDir private File tableDir;

@Parameter private int formatVersion;

Expand Down Expand Up @@ -108,9 +108,6 @@ public void testInvalidDefaultColumnModeValue() {

@TestTemplate
public void testMetricsConfigSortedColsDefault() throws Exception {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Schema schema =
new Schema(
required(1, "col1", Types.IntegerType.get()),
Expand Down Expand Up @@ -145,9 +142,6 @@ public void testMetricsConfigSortedColsDefault() throws Exception {

@TestTemplate
public void testMetricsConfigSortedColsDefaultByInvalid() throws Exception {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Schema schema =
new Schema(
required(1, "col1", Types.IntegerType.get()),
Expand Down Expand Up @@ -181,9 +175,6 @@ public void testMetricsConfigInferredDefaultModeLimit() throws IOException {
required(2, "col2", Types.IntegerType.get()),
required(3, "col3", Types.IntegerType.get()));

File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

Table table =
TestTables.create(
tableDir,
Expand Down
5 changes: 0 additions & 5 deletions core/src/test/java/org/apache/iceberg/TestOverwrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import org.apache.iceberg.ManifestEntry.Status;
Expand Down Expand Up @@ -126,9 +124,6 @@ private static ByteBuffer longToBuffer(long value) {

@BeforeEach
public void createTestTable() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();

this.table =
TestTables.create(tableDir, TABLE_NAME, DATE_SCHEMA, PARTITION_BY_DATE, formatVersion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assumptions.assumeThat;

import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import org.apache.iceberg.exceptions.ValidationException;
Expand Down Expand Up @@ -201,8 +199,6 @@ private static ByteBuffer longToBuffer(long value) {

@BeforeEach
public void before() throws IOException {
File tableDir = Files.createTempDirectory(temp, "junit").toFile();
assertThat(tableDir.delete()).isTrue();
this.table =
TestTables.create(tableDir, TABLE_NAME, DATE_SCHEMA, PARTITION_SPEC, formatVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.types.Types.NestedField;
import org.apache.iceberg.types.Types.StructType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class TestPartitionSpecBuilderCaseSensitivity {

Expand All @@ -57,14 +51,6 @@ public class TestPartitionSpecBuilderCaseSensitivity {
required(6, "order_time", Types.TimestampType.withoutZone()),
required(7, "ORDER_TIME", Types.TimestampType.withoutZone()));

@TempDir private Path temp;
private File tableDir = null;

@BeforeEach
public void setupTableDir() throws IOException {
this.tableDir = Files.createTempDirectory(temp, "junit").toFile();
}

@AfterEach
public void cleanupTables() {
TestTables.clearTables();
Expand Down
Loading

0 comments on commit 67ee082

Please sign in to comment.