Skip to content

Commit

Permalink
Core, Data, Flink: Migrate TableTestBase related classes to JUnit5 (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtongue authored Apr 3, 2024
1 parent 089c944 commit ced897c
Show file tree
Hide file tree
Showing 16 changed files with 382 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.iceberg.util;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -49,7 +50,6 @@
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Types;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -163,13 +163,13 @@ public void testTaskGroupPlanningCorruptedOffset() {
TableScanUtil.planTaskGroups(CloseableIterable.withNoopClose(baseFileScanTasks), 1, 1, 0)) {
for (FileScanTask fileScanTask : task.tasks()) {
DataFile taskDataFile = fileScanTask.file();
Assertions.assertThat(taskDataFile.splitOffsets()).isNull();
assertThat(taskDataFile.splitOffsets()).isNull();
taskCount++;
}
}

// 10 tasks since the split offsets are ignored and there are 1 byte splits for a 10 byte file
Assertions.assertThat(taskCount).isEqualTo(10);
assertThat(taskCount).isEqualTo(10);
}

@Test
Expand Down Expand Up @@ -280,7 +280,7 @@ public void testTaskGroupPlanningByPartition() {
ImmutableList.of(
taskWithPartition(SPEC1, PARTITION1, 128), taskWithPartition(SPEC2, PARTITION2, 128));

Assertions.assertThatThrownBy(
assertThatThrownBy(
() -> TableScanUtil.planTaskGroups(tasks2, 128, 10, 4, SPEC2.partitionType()))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("Cannot find field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.iceberg.io;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.File;
import java.io.IOException;
Expand All @@ -38,8 +39,6 @@
import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.util.StructLikeSet;
import org.assertj.core.api.Assertions;
import org.junit.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -72,7 +71,7 @@ protected FileFormat format() {
@BeforeEach
public void setupTable() throws Exception {
this.tableDir = Files.createTempDirectory(temp, "junit").toFile();
Assert.assertTrue(tableDir.delete()); // created during table creation
assertThat(tableDir.delete()).isTrue(); // created during table creation

this.metadataDir = new File(tableDir, "metadata");
this.table = create(SCHEMA, PartitionSpec.unpartitioned());
Expand All @@ -86,10 +85,10 @@ public void testClusteredDataWriterNoRecords() throws IOException {
new ClusteredDataWriter<>(writerFactory, fileFactory, table.io(), TARGET_FILE_SIZE);

writer.close();
Assert.assertEquals("Must be no data files", 0, writer.result().dataFiles().size());
assertThat(writer.result().dataFiles()).isEmpty();

writer.close();
Assert.assertEquals("Must be no data files", 0, writer.result().dataFiles().size());
assertThat(writer.result().dataFiles()).isEmpty();
}

@TestTemplate
Expand All @@ -111,7 +110,7 @@ public void testClusteredDataWriterMultiplePartitions() throws IOException {
writer.close();

DataWriteResult result = writer.result();
Assert.assertEquals("Must be 3 data files", 3, result.dataFiles().size());
assertThat(result.dataFiles()).hasSize(3);

RowDelta rowDelta = table.newRowDelta();
result.dataFiles().forEach(rowDelta::addRows);
Expand All @@ -120,7 +119,7 @@ public void testClusteredDataWriterMultiplePartitions() throws IOException {
List<T> expectedRows =
ImmutableList.of(
toRow(1, "aaa"), toRow(2, "aaa"), toRow(3, "bbb"), toRow(4, "bbb"), toRow(5, "ccc"));
Assert.assertEquals("Records should match", toSet(expectedRows), actualRowSet("*"));
assertThat(actualRowSet("*")).isEqualTo(toSet(expectedRows));
}

@TestTemplate
Expand All @@ -139,8 +138,7 @@ public void testClusteredDataWriterOutOfOrderPartitions() throws IOException {
writer.write(toRow(4, "bbb"), spec, partitionKey(spec, "bbb"));
writer.write(toRow(5, "ccc"), spec, partitionKey(spec, "ccc"));

Assertions.assertThatThrownBy(
() -> writer.write(toRow(6, "aaa"), spec, partitionKey(spec, "aaa")))
assertThatThrownBy(() -> writer.write(toRow(6, "aaa"), spec, partitionKey(spec, "aaa")))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Encountered records that belong to already closed files")
.hasMessageEndingWith("partition 'data=aaa' in spec " + spec);
Expand All @@ -159,14 +157,14 @@ public void testClusteredEqualityDeleteWriterNoRecords() throws IOException {
writerFactory, fileFactory, table.io(), TARGET_FILE_SIZE);

writer.close();
Assert.assertEquals(0, writer.result().deleteFiles().size());
Assert.assertEquals(0, writer.result().referencedDataFiles().size());
Assert.assertFalse(writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).isEmpty();
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();

writer.close();
Assert.assertEquals(0, writer.result().deleteFiles().size());
Assert.assertEquals(0, writer.result().referencedDataFiles().size());
Assert.assertFalse(writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).isEmpty();
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();
}

@TestTemplate
Expand Down Expand Up @@ -222,17 +220,16 @@ public void testClusteredEqualityDeleteWriterMultipleSpecs() throws IOException
writer.close();

DeleteWriteResult result = writer.result();
Assert.assertEquals("Must be 3 delete files", 3, result.deleteFiles().size());
Assert.assertEquals(
"Must not reference data files", 0, writer.result().referencedDataFiles().size());
Assert.assertFalse("Must not reference data files", writer.result().referencesDataFiles());
assertThat(result.deleteFiles()).hasSize(3);
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();

RowDelta rowDelta = table.newRowDelta();
result.deleteFiles().forEach(rowDelta::addDeletes);
rowDelta.commit();

List<T> expectedRows = ImmutableList.of(toRow(11, "aaa"), toRow(12, "bbb"), toRow(13, "ccc"));
Assert.assertEquals("Records should match", toSet(expectedRows), actualRowSet("*"));
assertThat(actualRowSet("*")).isEqualTo(toSet(expectedRows));
}

@TestTemplate
Expand Down Expand Up @@ -265,13 +262,13 @@ public void testClusteredEqualityDeleteWriterOutOfOrderSpecsAndPartitions() thro
writer.write(toRow(5, "ccc"), identitySpec, partitionKey(identitySpec, "ccc"));
writer.write(toRow(6, "ddd"), identitySpec, partitionKey(identitySpec, "ddd"));

Assertions.assertThatThrownBy(
assertThatThrownBy(
() -> writer.write(toRow(7, "ccc"), identitySpec, partitionKey(identitySpec, "ccc")))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Encountered records that belong to already closed files")
.hasMessageEndingWith("partition 'data=ccc' in spec " + identitySpec);

Assertions.assertThatThrownBy(() -> writer.write(toRow(7, "aaa"), unpartitionedSpec, null))
assertThatThrownBy(() -> writer.write(toRow(7, "aaa"), unpartitionedSpec, null))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Encountered records that belong to already closed files")
.hasMessageEndingWith("spec []");
Expand All @@ -297,14 +294,14 @@ private void checkClusteredPositionDeleteWriterNoRecords(DeleteGranularity delet
writerFactory, fileFactory, table.io(), TARGET_FILE_SIZE, deleteGranularity);

writer.close();
Assert.assertEquals(0, writer.result().deleteFiles().size());
Assert.assertEquals(0, writer.result().referencedDataFiles().size());
Assert.assertFalse(writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).isEmpty();
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();

writer.close();
Assert.assertEquals(0, writer.result().deleteFiles().size());
Assert.assertEquals(0, writer.result().referencedDataFiles().size());
Assert.assertFalse(writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).isEmpty();
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();
}

@TestTemplate
Expand Down Expand Up @@ -373,17 +370,16 @@ private void checkClusteredPositionDeleteWriterMultipleSpecs(DeleteGranularity d
writer.close();

DeleteWriteResult result = writer.result();
Assert.assertEquals("Must be 3 delete files", 3, result.deleteFiles().size());
Assert.assertEquals(
"Must reference 3 data files", 3, writer.result().referencedDataFiles().size());
Assert.assertTrue("Must reference data files", writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).hasSize(3);
assertThat(writer.result().referencedDataFiles()).hasSize(3);
assertThat(writer.result().referencesDataFiles()).isTrue();

RowDelta rowDelta = table.newRowDelta();
result.deleteFiles().forEach(rowDelta::addDeletes);
rowDelta.commit();

List<T> expectedRows = ImmutableList.of(toRow(11, "aaa"), toRow(12, "bbb"), toRow(13, "ccc"));
Assert.assertEquals("Records should match", toSet(expectedRows), actualRowSet("*"));
assertThat(actualRowSet("*")).isEqualTo(toSet(expectedRows));
}

@TestTemplate
Expand Down Expand Up @@ -433,7 +429,7 @@ private void checkClusteredPositionDeleteWriterOutOfOrderSpecsAndPartitions(
identitySpec,
partitionKey(identitySpec, "ddd"));

Assertions.assertThatThrownBy(
assertThatThrownBy(
() -> {
PositionDelete<T> positionDelete = positionDelete("file-5.parquet", 1L, null);
writer.write(positionDelete, identitySpec, partitionKey(identitySpec, "ccc"));
Expand All @@ -442,7 +438,7 @@ private void checkClusteredPositionDeleteWriterOutOfOrderSpecsAndPartitions(
.hasMessageContaining("Encountered records that belong to already closed files")
.hasMessageEndingWith("partition 'data=ccc' in spec " + identitySpec);

Assertions.assertThatThrownBy(
assertThatThrownBy(
() -> {
PositionDelete<T> positionDelete = positionDelete("file-1.parquet", 3L, null);
writer.write(positionDelete, unpartitionedSpec, null);
Expand Down Expand Up @@ -516,10 +512,10 @@ public void testFanoutDataWriterNoRecords() throws IOException {
new FanoutDataWriter<>(writerFactory, fileFactory, table.io(), TARGET_FILE_SIZE);

writer.close();
Assert.assertEquals("Must be no data files", 0, writer.result().dataFiles().size());
assertThat(writer.result().dataFiles()).isEmpty();

writer.close();
Assert.assertEquals("Must be no data files", 0, writer.result().dataFiles().size());
assertThat(writer.result().dataFiles()).isEmpty();
}

@TestTemplate
Expand All @@ -541,7 +537,7 @@ public void testFanoutDataWriterMultiplePartitions() throws IOException {
writer.close();

DataWriteResult result = writer.result();
Assert.assertEquals("Must be 3 data files", 3, result.dataFiles().size());
assertThat(result.dataFiles()).hasSize(3);

RowDelta rowDelta = table.newRowDelta();
result.dataFiles().forEach(rowDelta::addRows);
Expand All @@ -550,7 +546,7 @@ public void testFanoutDataWriterMultiplePartitions() throws IOException {
List<T> expectedRows =
ImmutableList.of(
toRow(1, "aaa"), toRow(2, "aaa"), toRow(3, "bbb"), toRow(4, "bbb"), toRow(5, "ccc"));
Assert.assertEquals("Records should match", toSet(expectedRows), actualRowSet("*"));
assertThat(actualRowSet("*")).isEqualTo(toSet(expectedRows));
}

@TestTemplate
Expand All @@ -571,14 +567,14 @@ private void checkFanoutPositionOnlyDeleteWriterNoRecords(DeleteGranularity dele
writerFactory, fileFactory, table.io(), TARGET_FILE_SIZE, deleteGranularity);

writer.close();
Assert.assertEquals(0, writer.result().deleteFiles().size());
Assert.assertEquals(0, writer.result().referencedDataFiles().size());
Assert.assertFalse(writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).isEmpty();
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();

writer.close();
Assert.assertEquals(0, writer.result().deleteFiles().size());
Assert.assertEquals(0, writer.result().referencedDataFiles().size());
Assert.assertFalse(writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).isEmpty();
assertThat(writer.result().referencedDataFiles()).isEmpty();
assertThat(writer.result().referencesDataFiles()).isFalse();
}

@TestTemplate
Expand Down Expand Up @@ -657,17 +653,16 @@ private void checkFanoutPositionOnlyDeleteWriterOutOfOrderRecords(
writer.close();

DeleteWriteResult result = writer.result();
Assert.assertEquals("Must be 3 delete files", 3, result.deleteFiles().size());
Assert.assertEquals(
"Must reference 3 data files", 3, writer.result().referencedDataFiles().size());
Assert.assertTrue("Must reference data files", writer.result().referencesDataFiles());
assertThat(writer.result().deleteFiles()).hasSize(3);
assertThat(writer.result().referencedDataFiles()).hasSize(3);
assertThat(writer.result().referencesDataFiles()).isTrue();

RowDelta rowDelta = table.newRowDelta();
result.deleteFiles().forEach(rowDelta::addDeletes);
rowDelta.commit();

List<T> expectedRows = ImmutableList.of(toRow(12, "bbb"));
Assert.assertEquals("Records should match", toSet(expectedRows), actualRowSet("*"));
assertThat(actualRowSet("*")).isEqualTo(toSet(expectedRows));
}

@TestTemplate
Expand Down
Loading

0 comments on commit ced897c

Please sign in to comment.