You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by et...@apache.org on 2023/12/22 07:37:10 UTC
(iceberg) branch main updated: Spark 3.5: Migrate tests to JUnit5 in data directory (#9341)
This is an automated email from the ASF dual-hosted git repository.
etudenhoefner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new 3d53060e28 Spark 3.5: Migrate tests to JUnit5 in data directory (#9341)
3d53060e28 is described below
commit 3d53060e2868da4bb9eb939e6f492e6fbcc9688d
Author: Chinmay Bhat <12...@users.noreply.github.com>
AuthorDate: Fri Dec 22 13:07:04 2023 +0530
Spark 3.5: Migrate tests to JUnit5 in data directory (#9341)
---
.../apache/iceberg/spark/data/AvroDataTest.java | 8 +-
.../apache/iceberg/spark/data/GenericsHelpers.java | 176 +++++++--------
...ataTest.java => ParameterizedAvroDataTest.java} | 44 ++--
.../org/apache/iceberg/spark/data/TestHelpers.java | 241 +++++++++------------
.../apache/iceberg/spark/data/TestOrcWrite.java | 16 +-
.../iceberg/spark/data/TestParquetAvroReader.java | 26 +--
.../iceberg/spark/data/TestParquetAvroWriter.java | 16 +-
.../iceberg/spark/data/TestSparkAvroEnums.java | 17 +-
.../iceberg/spark/data/TestSparkAvroReader.java | 6 +-
.../iceberg/spark/data/TestSparkDateTimes.java | 14 +-
.../data/TestSparkOrcReadMetadataColumns.java | 51 +++--
.../iceberg/spark/data/TestSparkOrcReader.java | 16 +-
.../data/TestSparkParquetReadMetadataColumns.java | 55 +++--
.../iceberg/spark/data/TestSparkParquetReader.java | 37 ++--
.../iceberg/spark/data/TestSparkParquetWriter.java | 18 +-
.../spark/data/TestSparkRecordOrcReaderWriter.java | 30 +--
...estParquetDictionaryEncodedVectorizedReads.java | 20 +-
...naryFallbackToPlainEncodingVectorizedReads.java | 8 +-
.../vectorized/TestParquetVectorizedReads.java | 57 +++--
.../apache/iceberg/spark/source/TestAvroScan.java | 20 +-
.../iceberg/spark/source/TestDataFrameWrites.java | 109 +++++-----
.../iceberg/spark/source/TestParquetScan.java | 64 +++---
22 files changed, 507 insertions(+), 542 deletions(-)
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java
index 95def56bcc..8f90a51a6e 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java
@@ -22,6 +22,7 @@ import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.iceberg.Schema;
@@ -34,9 +35,8 @@ import org.apache.iceberg.types.Types.LongType;
import org.apache.iceberg.types.Types.MapType;
import org.apache.iceberg.types.Types.StructType;
import org.apache.spark.sql.internal.SQLConf;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public abstract class AvroDataTest {
@@ -63,7 +63,7 @@ public abstract class AvroDataTest {
required(117, "dec_38_10", Types.DecimalType.of(38, 10)) // Spark's maximum precision
);
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir protected Path temp;
@Test
public void testSimpleStruct() throws IOException {
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/GenericsHelpers.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/GenericsHelpers.java
index a94d6525a7..501b46878b 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/GenericsHelpers.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/GenericsHelpers.java
@@ -19,6 +19,7 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.spark.SparkSchemaUtil.convert;
+import static org.assertj.core.api.Assertions.assertThat;
import static scala.collection.JavaConverters.mapAsJavaMapConverter;
import static scala.collection.JavaConverters.seqAsJavaListConverter;
@@ -47,8 +48,6 @@ import org.apache.spark.sql.catalyst.util.ArrayData;
import org.apache.spark.sql.catalyst.util.MapData;
import org.apache.spark.sql.types.Decimal;
import org.apache.spark.unsafe.types.UTF8String;
-import org.assertj.core.api.Assertions;
-import org.junit.Assert;
import scala.collection.Seq;
public class GenericsHelpers {
@@ -84,8 +83,9 @@ public class GenericsHelpers {
private static void assertEqualsSafe(Types.MapType map, Map<?, ?> expected, Map<?, ?> actual) {
Type keyType = map.keyType();
Type valueType = map.valueType();
- Assert.assertEquals(
- "Should have the same number of keys", expected.keySet().size(), actual.keySet().size());
+ assertThat(actual.keySet())
+ .as("Should have the same number of keys")
+ .hasSameSizeAs(expected.keySet());
for (Object expectedKey : expected.keySet()) {
Object matchingKey = null;
@@ -99,7 +99,7 @@ public class GenericsHelpers {
}
}
- Assert.assertNotNull("Should have a matching key", matchingKey);
+ assertThat(matchingKey).as("Should have a matching key").isNotNull();
assertEqualsSafe(valueType, expected.get(expectedKey), actual.get(matchingKey));
}
}
@@ -116,90 +116,83 @@ public class GenericsHelpers {
case LONG:
case FLOAT:
case DOUBLE:
- Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
+ assertThat(actual).as("Primitive value should be equal to expected").isEqualTo(expected);
break;
case DATE:
- Assertions.assertThat(expected)
- .as("Should expect a LocalDate")
- .isInstanceOf(LocalDate.class);
- Assertions.assertThat(actual).as("Should be a Date").isInstanceOf(Date.class);
- Assert.assertEquals(
- "ISO-8601 date should be equal", expected.toString(), actual.toString());
+ assertThat(expected).as("Should expect a LocalDate").isInstanceOf(LocalDate.class);
+ assertThat(actual).as("Should be a Date").isInstanceOf(Date.class);
+ assertThat(actual.toString())
+ .as("ISO-8601 date should be equal")
+ .isEqualTo(String.valueOf(expected));
break;
case TIMESTAMP:
Types.TimestampType timestampType = (Types.TimestampType) type;
if (timestampType.shouldAdjustToUTC()) {
// Timestamptz
- Assertions.assertThat(actual).as("Should be a Timestamp").isInstanceOf(Timestamp.class);
+ assertThat(actual).as("Should be a Timestamp").isInstanceOf(Timestamp.class);
Timestamp ts = (Timestamp) actual;
// milliseconds from nanos has already been added by getTime
OffsetDateTime actualTs =
EPOCH.plusNanos((ts.getTime() * 1_000_000) + (ts.getNanos() % 1_000_000));
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Should expect an OffsetDateTime")
.isInstanceOf(OffsetDateTime.class);
- Assert.assertEquals("Timestamp should be equal", expected, actualTs);
+
+ assertThat(actualTs).as("Timestamp should be equal").isEqualTo(expected);
} else {
// Timestamp
- Assertions.assertThat(actual)
- .as("Should be a LocalDateTime")
- .isInstanceOf(LocalDateTime.class);
- LocalDateTime ts = (LocalDateTime) actual;
+ assertThat(actual).as("Should be a LocalDateTime").isInstanceOf(LocalDateTime.class);
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Should expect an LocalDateTime")
.isInstanceOf(LocalDateTime.class);
- Assert.assertEquals("Timestamp should be equal", expected, ts);
+
+ assertThat(actual).as("Timestamp should be equal").isEqualTo(expected);
}
break;
case STRING:
- Assertions.assertThat(actual).as("Should be a String").isInstanceOf(String.class);
- Assert.assertEquals("Strings should be equal", String.valueOf(expected), actual);
+ assertThat(actual).as("Should be a String").isInstanceOf(String.class);
+ assertThat(actual.toString())
+ .as("Strings should be equal")
+ .isEqualTo(String.valueOf(expected));
break;
case UUID:
- Assertions.assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
- Assertions.assertThat(actual).as("Should be a String").isInstanceOf(String.class);
- Assert.assertEquals("UUID string representation should match", expected.toString(), actual);
+ assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
+ assertThat(actual).as("Should be a String").isInstanceOf(String.class);
+ assertThat(actual.toString())
+ .as("UUID string representation should match")
+ .isEqualTo(String.valueOf(expected));
break;
case FIXED:
- Assertions.assertThat(expected).as("Should expect a byte[]").isInstanceOf(byte[].class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals("Bytes should match", (byte[]) expected, (byte[]) actual);
+ assertThat(expected).as("Should expect a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Bytes should match").isEqualTo(expected);
break;
case BINARY:
- Assertions.assertThat(expected)
- .as("Should expect a ByteBuffer")
- .isInstanceOf(ByteBuffer.class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals(
- "Bytes should match", ((ByteBuffer) expected).array(), (byte[]) actual);
+ assertThat(expected).as("Should expect a ByteBuffer").isInstanceOf(ByteBuffer.class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Bytes should match").isEqualTo(((ByteBuffer) expected).array());
break;
case DECIMAL:
- Assertions.assertThat(expected)
- .as("Should expect a BigDecimal")
- .isInstanceOf(BigDecimal.class);
- Assertions.assertThat(actual).as("Should be a BigDecimal").isInstanceOf(BigDecimal.class);
- Assert.assertEquals("BigDecimals should be equal", expected, actual);
+ assertThat(expected).as("Should expect a BigDecimal").isInstanceOf(BigDecimal.class);
+ assertThat(actual).as("Should be a BigDecimal").isInstanceOf(BigDecimal.class);
+ assertThat(actual).as("BigDecimals should be equal").isEqualTo(expected);
break;
case STRUCT:
- Assertions.assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
- Assertions.assertThat(actual).as("Should be a Row").isInstanceOf(Row.class);
+ assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
+ assertThat(actual).as("Should be a Row").isInstanceOf(Row.class);
assertEqualsSafe(type.asNestedType().asStructType(), (Record) expected, (Row) actual);
break;
case LIST:
- Assertions.assertThat(expected)
- .as("Should expect a Collection")
- .isInstanceOf(Collection.class);
- Assertions.assertThat(actual).as("Should be a Seq").isInstanceOf(Seq.class);
+ assertThat(expected).as("Should expect a Collection").isInstanceOf(Collection.class);
+ assertThat(actual).as("Should be a Seq").isInstanceOf(Seq.class);
List<?> asList = seqAsJavaListConverter((Seq<?>) actual).asJava();
assertEqualsSafe(type.asNestedType().asListType(), (Collection<?>) expected, asList);
break;
case MAP:
- Assertions.assertThat(expected).as("Should expect a Collection").isInstanceOf(Map.class);
- Assertions.assertThat(actual)
- .as("Should be a Map")
- .isInstanceOf(scala.collection.Map.class);
+ assertThat(expected).as("Should expect a Collection").isInstanceOf(Map.class);
+ assertThat(actual).as("Should be a Map").isInstanceOf(scala.collection.Map.class);
Map<String, ?> asMap =
mapAsJavaMapConverter((scala.collection.Map<String, ?>) actual).asJava();
assertEqualsSafe(type.asNestedType().asMapType(), (Map<?, ?>) expected, asMap);
@@ -264,86 +257,81 @@ public class GenericsHelpers {
case LONG:
case FLOAT:
case DOUBLE:
- Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
+ assertThat(actual).as("Primitive value should be equal to expected").isEqualTo(expected);
break;
case DATE:
- Assertions.assertThat(expected)
- .as("Should expect a LocalDate")
- .isInstanceOf(LocalDate.class);
+ assertThat(expected).as("Should expect a LocalDate").isInstanceOf(LocalDate.class);
int expectedDays = (int) ChronoUnit.DAYS.between(EPOCH_DAY, (LocalDate) expected);
- Assert.assertEquals("Primitive value should be equal to expected", expectedDays, actual);
+ assertThat(actual)
+ .as("Primitive value should be equal to expected")
+ .isEqualTo(expectedDays);
break;
case TIMESTAMP:
Types.TimestampType timestampType = (Types.TimestampType) type;
if (timestampType.shouldAdjustToUTC()) {
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Should expect an OffsetDateTime")
.isInstanceOf(OffsetDateTime.class);
long expectedMicros = ChronoUnit.MICROS.between(EPOCH, (OffsetDateTime) expected);
- Assert.assertEquals(
- "Primitive value should be equal to expected", expectedMicros, actual);
+ assertThat(actual)
+ .as("Primitive value should be equal to expected")
+ .isEqualTo(expectedMicros);
} else {
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Should expect an LocalDateTime")
.isInstanceOf(LocalDateTime.class);
long expectedMicros =
ChronoUnit.MICROS.between(EPOCH, ((LocalDateTime) expected).atZone(ZoneId.of("UTC")));
- Assert.assertEquals(
- "Primitive value should be equal to expected", expectedMicros, actual);
+ assertThat(actual)
+ .as("Primitive value should be equal to expected")
+ .isEqualTo(expectedMicros);
}
break;
case STRING:
- Assertions.assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
- Assert.assertEquals("Strings should be equal", expected, actual.toString());
+ assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
+ assertThat(actual.toString())
+ .as("Strings should be equal")
+ .isEqualTo(String.valueOf(expected));
break;
case UUID:
- Assertions.assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
- Assertions.assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
- Assert.assertEquals(
- "UUID string representation should match", expected.toString(), actual.toString());
+ assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
+ assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
+ assertThat(actual.toString())
+ .as("UUID string representation should match")
+ .isEqualTo(String.valueOf(expected));
break;
case FIXED:
- Assertions.assertThat(expected).as("Should expect a byte[]").isInstanceOf(byte[].class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals("Bytes should match", (byte[]) expected, (byte[]) actual);
+ assertThat(expected).as("Should expect a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Bytes should match").isEqualTo(expected);
break;
case BINARY:
- Assertions.assertThat(expected)
- .as("Should expect a ByteBuffer")
- .isInstanceOf(ByteBuffer.class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals(
- "Bytes should match", ((ByteBuffer) expected).array(), (byte[]) actual);
+ assertThat(expected).as("Should expect a ByteBuffer").isInstanceOf(ByteBuffer.class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Bytes should match").isEqualTo(((ByteBuffer) expected).array());
break;
case DECIMAL:
- Assertions.assertThat(expected)
- .as("Should expect a BigDecimal")
- .isInstanceOf(BigDecimal.class);
- Assertions.assertThat(actual).as("Should be a Decimal").isInstanceOf(Decimal.class);
- Assert.assertEquals(
- "BigDecimals should be equal", expected, ((Decimal) actual).toJavaBigDecimal());
+ assertThat(expected).as("Should expect a BigDecimal").isInstanceOf(BigDecimal.class);
+ assertThat(actual).as("Should be a Decimal").isInstanceOf(Decimal.class);
+ assertThat(((Decimal) actual).toJavaBigDecimal())
+ .as("BigDecimals should be equal")
+ .isEqualTo(expected);
break;
case STRUCT:
- Assertions.assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
- Assertions.assertThat(actual)
- .as("Should be an InternalRow")
- .isInstanceOf(InternalRow.class);
+ assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
+ assertThat(actual).as("Should be an InternalRow").isInstanceOf(InternalRow.class);
assertEqualsUnsafe(
type.asNestedType().asStructType(), (Record) expected, (InternalRow) actual);
break;
case LIST:
- Assertions.assertThat(expected)
- .as("Should expect a Collection")
- .isInstanceOf(Collection.class);
- Assertions.assertThat(actual).as("Should be an ArrayData").isInstanceOf(ArrayData.class);
+ assertThat(expected).as("Should expect a Collection").isInstanceOf(Collection.class);
+ assertThat(actual).as("Should be an ArrayData").isInstanceOf(ArrayData.class);
assertEqualsUnsafe(
type.asNestedType().asListType(), (Collection<?>) expected, (ArrayData) actual);
break;
case MAP:
- Assertions.assertThat(expected).as("Should expect a Map").isInstanceOf(Map.class);
- Assertions.assertThat(actual)
- .as("Should be an ArrayBasedMapData")
- .isInstanceOf(MapData.class);
+ assertThat(expected).as("Should expect a Map").isInstanceOf(Map.class);
+ assertThat(actual).as("Should be an ArrayBasedMapData").isInstanceOf(MapData.class);
assertEqualsUnsafe(type.asNestedType().asMapType(), (Map<?, ?>) expected, (MapData) actual);
break;
case TIME:
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/ParameterizedAvroDataTest.java
similarity index 92%
copy from spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java
copy to spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/ParameterizedAvroDataTest.java
index 95def56bcc..85effe7d39 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/AvroDataTest.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/ParameterizedAvroDataTest.java
@@ -22,6 +22,7 @@ import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.iceberg.Schema;
@@ -34,11 +35,15 @@ import org.apache.iceberg.types.Types.LongType;
import org.apache.iceberg.types.Types.MapType;
import org.apache.iceberg.types.Types.StructType;
import org.apache.spark.sql.internal.SQLConf;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.io.TempDir;
-public abstract class AvroDataTest {
+/**
+ * Copy of {@link AvroDataTest} that marks tests with @{@link org.junit.jupiter.api.TestTemplate}
+ * instead of @{@link Test} to make the tests work in a parameterized environment.
+ */
+public abstract class ParameterizedAvroDataTest {
protected abstract void writeAndValidate(Schema schema) throws IOException;
@@ -63,14 +68,14 @@ public abstract class AvroDataTest {
required(117, "dec_38_10", Types.DecimalType.of(38, 10)) // Spark's maximum precision
);
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir protected Path temp;
- @Test
+ @TestTemplate
public void testSimpleStruct() throws IOException {
writeAndValidate(TypeUtil.assignIncreasingFreshIds(new Schema(SUPPORTED_PRIMITIVES.fields())));
}
- @Test
+ @TestTemplate
public void testStructWithRequiredFields() throws IOException {
writeAndValidate(
TypeUtil.assignIncreasingFreshIds(
@@ -78,7 +83,7 @@ public abstract class AvroDataTest {
Lists.transform(SUPPORTED_PRIMITIVES.fields(), Types.NestedField::asRequired))));
}
- @Test
+ @TestTemplate
public void testStructWithOptionalFields() throws IOException {
writeAndValidate(
TypeUtil.assignIncreasingFreshIds(
@@ -86,13 +91,13 @@ public abstract class AvroDataTest {
Lists.transform(SUPPORTED_PRIMITIVES.fields(), Types.NestedField::asOptional))));
}
- @Test
+ @TestTemplate
public void testNestedStruct() throws IOException {
writeAndValidate(
TypeUtil.assignIncreasingFreshIds(new Schema(required(1, "struct", SUPPORTED_PRIMITIVES))));
}
- @Test
+ @TestTemplate
public void testArray() throws IOException {
Schema schema =
new Schema(
@@ -102,7 +107,7 @@ public abstract class AvroDataTest {
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testArrayOfStructs() throws IOException {
Schema schema =
TypeUtil.assignIncreasingFreshIds(
@@ -113,7 +118,7 @@ public abstract class AvroDataTest {
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testMap() throws IOException {
Schema schema =
new Schema(
@@ -126,18 +131,17 @@ public abstract class AvroDataTest {
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testNumericMapKey() throws IOException {
Schema schema =
new Schema(
required(0, "id", LongType.get()),
- optional(
- 1, "data", MapType.ofOptional(2, 3, Types.LongType.get(), Types.StringType.get())));
+ optional(1, "data", MapType.ofOptional(2, 3, LongType.get(), Types.StringType.get())));
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testComplexMapKey() throws IOException {
Schema schema =
new Schema(
@@ -148,7 +152,7 @@ public abstract class AvroDataTest {
MapType.ofOptional(
2,
3,
- Types.StructType.of(
+ StructType.of(
required(4, "i", Types.IntegerType.get()),
optional(5, "s", Types.StringType.get())),
Types.StringType.get())));
@@ -156,7 +160,7 @@ public abstract class AvroDataTest {
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testMapOfStructs() throws IOException {
Schema schema =
TypeUtil.assignIncreasingFreshIds(
@@ -170,7 +174,7 @@ public abstract class AvroDataTest {
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testMixedTypes() throws IOException {
StructType structType =
StructType.of(
@@ -227,7 +231,7 @@ public abstract class AvroDataTest {
writeAndValidate(schema);
}
- @Test
+ @TestTemplate
public void testTimestampWithoutZone() throws IOException {
Schema schema =
TypeUtil.assignIncreasingFreshIds(
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestHelpers.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestHelpers.java
index 8e6b576ddf..c73ef630ac 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestHelpers.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestHelpers.java
@@ -19,6 +19,7 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.spark.SparkSchemaUtil.convert;
+import static org.assertj.core.api.Assertions.assertThat;
import static scala.collection.JavaConverters.mapAsJavaMapConverter;
import static scala.collection.JavaConverters.seqAsJavaListConverter;
@@ -77,8 +78,6 @@ import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.vectorized.ColumnarBatch;
import org.apache.spark.unsafe.types.UTF8String;
-import org.assertj.core.api.Assertions;
-import org.junit.Assert;
import scala.collection.Seq;
public class TestHelpers {
@@ -143,7 +142,7 @@ public class TestHelpers {
}
}
- Assert.assertNotNull("Should have a matching key", matchingKey);
+ assertThat(matchingKey).as("Should have a matching key").isNotNull();
assertEqualsSafe(valueType, expected.get(expectedKey), actual.get(matchingKey));
}
}
@@ -163,88 +162,79 @@ public class TestHelpers {
case LONG:
case FLOAT:
case DOUBLE:
- Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
+ assertThat(actual).as("Primitive value should be equal to expected").isEqualTo(expected);
break;
case DATE:
- Assertions.assertThat(expected).as("Should be an int").isInstanceOf(Integer.class);
- Assertions.assertThat(actual).as("Should be a Date").isInstanceOf(Date.class);
- int daysFromEpoch = (Integer) expected;
- LocalDate date = ChronoUnit.DAYS.addTo(EPOCH_DAY, daysFromEpoch);
- Assert.assertEquals("ISO-8601 date should be equal", date.toString(), actual.toString());
+ assertThat(expected).as("Should be an int").isInstanceOf(Integer.class);
+ assertThat(actual).as("Should be a Date").isInstanceOf(Date.class);
+ LocalDate date = ChronoUnit.DAYS.addTo(EPOCH_DAY, (Integer) expected);
+ assertThat(actual.toString())
+ .as("ISO-8601 date should be equal")
+ .isEqualTo(String.valueOf(date));
break;
case TIMESTAMP:
Types.TimestampType timestampType = (Types.TimestampType) type;
- Assertions.assertThat(expected).as("Should be a long").isInstanceOf(Long.class);
+ assertThat(expected).as("Should be a long").isInstanceOf(Long.class);
if (timestampType.shouldAdjustToUTC()) {
- Assertions.assertThat(actual).as("Should be a Timestamp").isInstanceOf(Timestamp.class);
+ assertThat(actual).as("Should be a Timestamp").isInstanceOf(Timestamp.class);
Timestamp ts = (Timestamp) actual;
// milliseconds from nanos has already been added by getTime
long tsMicros = (ts.getTime() * 1000) + ((ts.getNanos() / 1000) % 1000);
- Assert.assertEquals("Timestamp micros should be equal", expected, tsMicros);
+ assertThat(tsMicros).as("Timestamp micros should be equal").isEqualTo(expected);
} else {
- Assertions.assertThat(actual)
- .as("Should be a LocalDateTime")
- .isInstanceOf(LocalDateTime.class);
+ assertThat(actual).as("Should be a LocalDateTime").isInstanceOf(LocalDateTime.class);
LocalDateTime ts = (LocalDateTime) actual;
Instant instant = ts.toInstant(ZoneOffset.UTC);
// milliseconds from nanos has already been added by getTime
long tsMicros = (instant.toEpochMilli() * 1000) + ((ts.getNano() / 1000) % 1000);
- Assert.assertEquals("Timestamp micros should be equal", expected, tsMicros);
+ assertThat(tsMicros).as("Timestamp micros should be equal").isEqualTo(expected);
}
break;
case STRING:
- Assertions.assertThat(actual).as("Should be a String").isInstanceOf(String.class);
- Assert.assertEquals("Strings should be equal", String.valueOf(expected), actual);
+ assertThat(actual).as("Should be a String").isInstanceOf(String.class);
+ assertThat(actual).as("Strings should be equal").isEqualTo(String.valueOf(expected));
break;
case UUID:
- Assertions.assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
- Assertions.assertThat(actual).as("Should be a String").isInstanceOf(String.class);
- Assert.assertEquals("UUID string representation should match", expected.toString(), actual);
+ assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
+ assertThat(actual).as("Should be a String").isInstanceOf(String.class);
+ assertThat(actual.toString())
+ .as("UUID string representation should match")
+ .isEqualTo(String.valueOf(expected));
break;
case FIXED:
- Assertions.assertThat(expected)
- .as("Should expect a Fixed")
- .isInstanceOf(GenericData.Fixed.class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals(
- "Bytes should match", ((GenericData.Fixed) expected).bytes(), (byte[]) actual);
+ assertThat(expected).as("Should expect a Fixed").isInstanceOf(GenericData.Fixed.class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual)
+ .as("Bytes should match")
+ .isEqualTo(((GenericData.Fixed) expected).bytes());
break;
case BINARY:
- Assertions.assertThat(expected)
- .as("Should expect a ByteBuffer")
- .isInstanceOf(ByteBuffer.class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals(
- "Bytes should match", ((ByteBuffer) expected).array(), (byte[]) actual);
+ assertThat(expected).as("Should expect a ByteBuffer").isInstanceOf(ByteBuffer.class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Bytes should match").isEqualTo(((ByteBuffer) expected).array());
break;
case DECIMAL:
- Assertions.assertThat(expected)
- .as("Should expect a BigDecimal")
- .isInstanceOf(BigDecimal.class);
- Assertions.assertThat(actual).as("Should be a BigDecimal").isInstanceOf(BigDecimal.class);
- Assert.assertEquals("BigDecimals should be equal", expected, actual);
+ assertThat(expected).as("Should expect a BigDecimal").isInstanceOf(BigDecimal.class);
+ assertThat(actual).as("Should be a BigDecimal").isInstanceOf(BigDecimal.class);
+ assertThat(actual).as("BigDecimals should be equal").isEqualTo(expected);
break;
case STRUCT:
- Assertions.assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
- Assertions.assertThat(actual).as("Should be a Row").isInstanceOf(Row.class);
+ assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
+ assertThat(actual).as("Should be a Row").isInstanceOf(Row.class);
assertEqualsSafe(type.asNestedType().asStructType(), (Record) expected, (Row) actual);
break;
case LIST:
- Assertions.assertThat(expected)
- .as("Should expect a Collection")
- .isInstanceOf(Collection.class);
- Assertions.assertThat(actual).as("Should be a Seq").isInstanceOf(Seq.class);
+ assertThat(expected).as("Should expect a Collection").isInstanceOf(Collection.class);
+ assertThat(actual).as("Should be a Seq").isInstanceOf(Seq.class);
List<?> asList = seqAsJavaListConverter((Seq<?>) actual).asJava();
assertEqualsSafe(type.asNestedType().asListType(), (Collection) expected, asList);
break;
case MAP:
- Assertions.assertThat(expected).as("Should expect a Collection").isInstanceOf(Map.class);
- Assertions.assertThat(actual)
- .as("Should be a Map")
- .isInstanceOf(scala.collection.Map.class);
+ assertThat(expected).as("Should expect a Collection").isInstanceOf(Map.class);
+ assertThat(actual).as("Should be a Map").isInstanceOf(scala.collection.Map.class);
Map<String, ?> asMap =
mapAsJavaMapConverter((scala.collection.Map<String, ?>) actual).asJava();
assertEqualsSafe(type.asNestedType().asMapType(), (Map<String, ?>) expected, asMap);
@@ -304,22 +294,21 @@ public class TestHelpers {
switch (type.typeId()) {
case LONG:
- Assertions.assertThat(actual).as("Should be a long").isInstanceOf(Long.class);
+ assertThat(actual).as("Should be a long").isInstanceOf(Long.class);
if (expected instanceof Integer) {
- Assert.assertEquals("Values didn't match", ((Number) expected).longValue(), actual);
+ assertThat(actual).as("Values didn't match").isEqualTo(((Number) expected).longValue());
} else {
- Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
+ assertThat(actual).as("Primitive value should be equal to expected").isEqualTo(expected);
}
break;
case DOUBLE:
- Assertions.assertThat(actual).as("Should be a double").isInstanceOf(Double.class);
+ assertThat(actual).as("Should be a double").isInstanceOf(Double.class);
if (expected instanceof Float) {
- Assert.assertEquals(
- "Values didn't match",
- Double.doubleToLongBits(((Number) expected).doubleValue()),
- Double.doubleToLongBits((double) actual));
+ assertThat(Double.doubleToLongBits((double) actual))
+ .as("Values didn't match")
+ .isEqualTo(Double.doubleToLongBits(((Number) expected).doubleValue()));
} else {
- Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
+ assertThat(actual).as("Primitive value should be equal to expected").isEqualTo(expected);
}
break;
case INTEGER:
@@ -327,63 +316,53 @@ public class TestHelpers {
case BOOLEAN:
case DATE:
case TIMESTAMP:
- Assert.assertEquals("Primitive value should be equal to expected", expected, actual);
+ assertThat(actual).as("Primitive value should be equal to expected").isEqualTo(expected);
break;
case STRING:
- Assertions.assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
- Assert.assertEquals("Strings should be equal", expected, actual.toString());
+ assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
+ assertThat(actual.toString()).as("Strings should be equal").isEqualTo(expected);
break;
case UUID:
- Assertions.assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
- Assertions.assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
- Assert.assertEquals(
- "UUID string representation should match", expected.toString(), actual.toString());
+ assertThat(expected).as("Should expect a UUID").isInstanceOf(UUID.class);
+ assertThat(actual).as("Should be a UTF8String").isInstanceOf(UTF8String.class);
+ assertThat(actual.toString())
+ .as("UUID string representation should match")
+ .isEqualTo(String.valueOf(expected));
break;
case FIXED:
- Assertions.assertThat(expected)
- .as("Should expect a Fixed")
- .isInstanceOf(GenericData.Fixed.class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals(
- "Bytes should match", ((GenericData.Fixed) expected).bytes(), (byte[]) actual);
+ assertThat(expected).as("Should expect a Fixed").isInstanceOf(GenericData.Fixed.class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual)
+ .as("Bytes should match")
+ .isEqualTo(((GenericData.Fixed) expected).bytes());
break;
case BINARY:
- Assertions.assertThat(expected)
- .as("Should expect a ByteBuffer")
- .isInstanceOf(ByteBuffer.class);
- Assertions.assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
- Assert.assertArrayEquals(
- "Bytes should match", ((ByteBuffer) expected).array(), (byte[]) actual);
+ assertThat(expected).as("Should expect a ByteBuffer").isInstanceOf(ByteBuffer.class);
+ assertThat(actual).as("Should be a byte[]").isInstanceOf(byte[].class);
+ assertThat(actual).as("Bytes should match").isEqualTo(((ByteBuffer) expected).array());
break;
case DECIMAL:
- Assertions.assertThat(expected)
- .as("Should expect a BigDecimal")
- .isInstanceOf(BigDecimal.class);
- Assertions.assertThat(actual).as("Should be a Decimal").isInstanceOf(Decimal.class);
- Assert.assertEquals(
- "BigDecimals should be equal", expected, ((Decimal) actual).toJavaBigDecimal());
+ assertThat(expected).as("Should expect a BigDecimal").isInstanceOf(BigDecimal.class);
+ assertThat(actual).as("Should be a Decimal").isInstanceOf(Decimal.class);
+ assertThat(((Decimal) actual).toJavaBigDecimal())
+ .as("BigDecimals should be equal")
+ .isEqualTo(expected);
break;
case STRUCT:
- Assertions.assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
- Assertions.assertThat(actual)
- .as("Should be an InternalRow")
- .isInstanceOf(InternalRow.class);
+ assertThat(expected).as("Should expect a Record").isInstanceOf(Record.class);
+ assertThat(actual).as("Should be an InternalRow").isInstanceOf(InternalRow.class);
assertEqualsUnsafe(
type.asNestedType().asStructType(), (Record) expected, (InternalRow) actual);
break;
case LIST:
- Assertions.assertThat(expected)
- .as("Should expect a Collection")
- .isInstanceOf(Collection.class);
- Assertions.assertThat(actual).as("Should be an ArrayData").isInstanceOf(ArrayData.class);
+ assertThat(expected).as("Should expect a Collection").isInstanceOf(Collection.class);
+ assertThat(actual).as("Should be an ArrayData").isInstanceOf(ArrayData.class);
assertEqualsUnsafe(
type.asNestedType().asListType(), (Collection) expected, (ArrayData) actual);
break;
case MAP:
- Assertions.assertThat(expected).as("Should expect a Map").isInstanceOf(Map.class);
- Assertions.assertThat(actual)
- .as("Should be an ArrayBasedMapData")
- .isInstanceOf(MapData.class);
+ assertThat(expected).as("Should expect a Map").isInstanceOf(Map.class);
+ assertThat(actual).as("Should be an ArrayBasedMapData").isInstanceOf(MapData.class);
assertEqualsUnsafe(type.asNestedType().asMapType(), (Map) expected, (MapData) actual);
break;
case TIME:
@@ -403,7 +382,7 @@ public class TestHelpers {
public static void assertEquals(
String prefix, Types.StructType type, InternalRow expected, Row actual) {
if (expected == null || actual == null) {
- Assert.assertEquals(prefix, expected, actual);
+ assertThat(actual).as(prefix).isEqualTo(expected);
} else {
List<Types.NestedField> fields = type.fields();
for (int c = 0; c < fields.size(); ++c) {
@@ -419,10 +398,9 @@ public class TestHelpers {
case DECIMAL:
case DATE:
case TIMESTAMP:
- Assert.assertEquals(
- prefix + "." + fieldName + " - " + childType,
- getValue(expected, c, childType),
- getPrimitiveValue(actual, c, childType));
+ assertThat(getPrimitiveValue(actual, c, childType))
+ .as(prefix + "." + fieldName + " - " + childType)
+ .isEqualTo(getValue(expected, c, childType));
break;
case UUID:
case FIXED:
@@ -466,9 +444,9 @@ public class TestHelpers {
private static void assertEqualsLists(
String prefix, Types.ListType type, ArrayData expected, List actual) {
if (expected == null || actual == null) {
- Assert.assertEquals(prefix, expected, actual);
+ assertThat(actual).as(prefix).isEqualTo(expected);
} else {
- Assert.assertEquals(prefix + " length", expected.numElements(), actual.size());
+ assertThat(actual.size()).as(prefix + "length").isEqualTo(expected.numElements());
Type childType = type.elementType();
for (int e = 0; e < expected.numElements(); ++e) {
switch (childType.typeId()) {
@@ -481,10 +459,9 @@ public class TestHelpers {
case DECIMAL:
case DATE:
case TIMESTAMP:
- Assert.assertEquals(
- prefix + ".elem " + e + " - " + childType,
- getValue(expected, e, childType),
- actual.get(e));
+ assertThat(actual.get(e))
+ .as(prefix + ".elem " + e + " - " + childType)
+ .isEqualTo(getValue(expected, e, childType));
break;
case UUID:
case FIXED:
@@ -528,21 +505,20 @@ public class TestHelpers {
private static void assertEqualsMaps(
String prefix, Types.MapType type, MapData expected, Map<?, ?> actual) {
if (expected == null || actual == null) {
- Assert.assertEquals(prefix, expected, actual);
+ assertThat(actual).as(prefix).isEqualTo(expected);
} else {
Type keyType = type.keyType();
Type valueType = type.valueType();
ArrayData expectedKeyArray = expected.keyArray();
ArrayData expectedValueArray = expected.valueArray();
- Assert.assertEquals(prefix + " length", expected.numElements(), actual.size());
+ assertThat(actual.size()).as(prefix + " length").isEqualTo(expected.numElements());
for (int e = 0; e < expected.numElements(); ++e) {
Object expectedKey = getValue(expectedKeyArray, e, keyType);
Object actualValue = actual.get(expectedKey);
if (actualValue == null) {
- Assert.assertEquals(
- prefix + ".key=" + expectedKey + " has null",
- true,
- expected.valueArray().isNullAt(e));
+ assertThat(true)
+ .as(prefix + ".key=" + expectedKey + " has null")
+ .isEqualTo(expected.valueArray().isNullAt(e));
} else {
switch (valueType.typeId()) {
case BOOLEAN:
@@ -554,10 +530,9 @@ public class TestHelpers {
case DECIMAL:
case DATE:
case TIMESTAMP:
- Assert.assertEquals(
- prefix + ".key=" + expectedKey + " - " + valueType,
- getValue(expectedValueArray, e, valueType),
- actual.get(expectedKey));
+ assertThat(actual.get(expectedKey))
+ .as(prefix + ".key=" + expectedKey + " - " + valueType)
+ .isEqualTo(getValue(expectedValueArray, e, valueType));
break;
case UUID:
case FIXED:
@@ -687,11 +662,7 @@ public class TestHelpers {
}
private static void assertEqualBytes(String context, byte[] expected, byte[] actual) {
- if (expected == null || actual == null) {
- Assert.assertEquals(context, expected, actual);
- } else {
- Assert.assertArrayEquals(context, expected, actual);
- }
+ assertThat(actual).as(context).isEqualTo(expected);
}
static void assertEquals(Schema schema, Object expected, Object actual) {
@@ -704,42 +675,42 @@ public class TestHelpers {
}
if (type instanceof StructType) {
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Expected should be an InternalRow: " + context)
.isInstanceOf(InternalRow.class);
- Assertions.assertThat(actual)
+ assertThat(actual)
.as("Actual should be an InternalRow: " + context)
.isInstanceOf(InternalRow.class);
assertEquals(context, (StructType) type, (InternalRow) expected, (InternalRow) actual);
} else if (type instanceof ArrayType) {
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Expected should be an ArrayData: " + context)
.isInstanceOf(ArrayData.class);
- Assertions.assertThat(actual)
+ assertThat(actual)
.as("Actual should be an ArrayData: " + context)
.isInstanceOf(ArrayData.class);
assertEquals(context, (ArrayType) type, (ArrayData) expected, (ArrayData) actual);
} else if (type instanceof MapType) {
- Assertions.assertThat(expected)
+ assertThat(expected)
.as("Expected should be a MapData: " + context)
.isInstanceOf(MapData.class);
- Assertions.assertThat(actual)
- .as("Actual should be a MapData: " + context)
- .isInstanceOf(MapData.class);
+ assertThat(actual).as("Actual should be a MapData: " + context).isInstanceOf(MapData.class);
assertEquals(context, (MapType) type, (MapData) expected, (MapData) actual);
} else if (type instanceof BinaryType) {
assertEqualBytes(context, (byte[]) expected, (byte[]) actual);
} else {
- Assert.assertEquals("Value should match expected: " + context, expected, actual);
+ assertThat(actual).as("Value should match expected: " + context).isEqualTo(expected);
}
}
private static void assertEquals(
String context, StructType struct, InternalRow expected, InternalRow actual) {
- Assert.assertEquals("Should have correct number of fields", struct.size(), actual.numFields());
+ assertThat(actual.numFields())
+ .as("Should have correct number of fields")
+ .isEqualTo(struct.size());
for (int i = 0; i < actual.numFields(); i += 1) {
StructField field = struct.fields()[i];
DataType type = field.dataType();
@@ -753,8 +724,9 @@ public class TestHelpers {
private static void assertEquals(
String context, ArrayType array, ArrayData expected, ArrayData actual) {
- Assert.assertEquals(
- "Should have the same number of elements", expected.numElements(), actual.numElements());
+ assertThat(actual.numElements())
+ .as("Should have the same number of elements")
+ .isEqualTo(expected.numElements());
DataType type = array.elementType();
for (int i = 0; i < actual.numElements(); i += 1) {
assertEquals(
@@ -766,8 +738,9 @@ public class TestHelpers {
}
private static void assertEquals(String context, MapType map, MapData expected, MapData actual) {
- Assert.assertEquals(
- "Should have the same number of elements", expected.numElements(), actual.numElements());
+ assertThat(actual.numElements())
+ .as("Should have the same number of elements")
+ .isEqualTo(expected.numElements());
DataType keyType = map.keyType();
ArrayData expectedKeys = expected.keyArray();
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestOrcWrite.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestOrcWrite.java
index 1e51a08839..cbaad65430 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestOrcWrite.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestOrcWrite.java
@@ -19,22 +19,22 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import org.apache.iceberg.Files;
import org.apache.iceberg.Schema;
import org.apache.iceberg.io.FileAppender;
import org.apache.iceberg.orc.ORC;
import org.apache.iceberg.types.Types;
import org.apache.spark.sql.catalyst.InternalRow;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class TestOrcWrite {
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
private static final Schema SCHEMA =
new Schema(
@@ -42,8 +42,8 @@ public class TestOrcWrite {
@Test
public void splitOffsets() throws IOException {
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
Iterable<InternalRow> rows = RandomData.generateSpark(SCHEMA, 1, 0L);
FileAppender<InternalRow> writer =
@@ -54,6 +54,6 @@ public class TestOrcWrite {
writer.addAll(rows);
writer.close();
- Assert.assertNotNull("Split offsets not present", writer.splitOffsets());
+ assertThat(writer.splitOffsets()).as("Split offsets not present").isNotNull();
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroReader.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroReader.java
index 657eebe00a..3f9b4bb587 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroReader.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroReader.java
@@ -20,9 +20,11 @@ package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Iterator;
import org.apache.avro.generic.GenericData.Record;
import org.apache.iceberg.Files;
@@ -34,14 +36,12 @@ import org.apache.iceberg.parquet.ParquetAvroValueReaders;
import org.apache.iceberg.parquet.ParquetSchemaUtil;
import org.apache.iceberg.types.Types;
import org.apache.parquet.schema.MessageType;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class TestParquetAvroReader {
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
private static final Schema COMPLEX_SCHEMA =
new Schema(
@@ -87,7 +87,7 @@ public class TestParquetAvroReader {
optional(2, "slide", Types.StringType.get()),
required(25, "foo", Types.DecimalType.of(7, 5)));
- @Ignore
+ @Disabled
public void testStructSchema() throws IOException {
Schema structSchema =
new Schema(
@@ -145,7 +145,7 @@ public class TestParquetAvroReader {
double stddev = Math.sqrt((((double) sumSq) / trials) - (mean * mean));
}
- @Ignore
+ @Disabled
public void testWithOldReadPath() throws IOException {
File testFile = writeTestData(COMPLEX_SCHEMA, 500_000, 1985);
// RandomData uses the root record name "test", which must match for records to be equal
@@ -194,8 +194,8 @@ public class TestParquetAvroReader {
public void testCorrectness() throws IOException {
Iterable<Record> records = RandomData.generate(COMPLEX_SCHEMA, 50_000, 34139);
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<Record> writer =
Parquet.write(Files.localOutput(testFile)).schema(COMPLEX_SCHEMA).build()) {
@@ -217,15 +217,15 @@ public class TestParquetAvroReader {
Iterator<Record> iter = records.iterator();
for (Record actual : reader) {
Record expected = iter.next();
- Assert.assertEquals("Record " + recordNum + " should match expected", expected, actual);
+ assertThat(actual).as("Record " + recordNum + " should match expected").isEqualTo(expected);
recordNum += 1;
}
}
}
private File writeTestData(Schema schema, int numRecords, int seed) throws IOException {
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<Record> writer =
Parquet.write(Files.localOutput(testFile)).schema(schema).build()) {
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroWriter.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroWriter.java
index 15c6268da4..83f8f7f168 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroWriter.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestParquetAvroWriter.java
@@ -20,9 +20,11 @@ package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Iterator;
import org.apache.avro.generic.GenericData.Record;
import org.apache.iceberg.Files;
@@ -35,13 +37,11 @@ import org.apache.iceberg.parquet.ParquetAvroWriter;
import org.apache.iceberg.parquet.ParquetSchemaUtil;
import org.apache.iceberg.types.Types;
import org.apache.parquet.schema.MessageType;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class TestParquetAvroWriter {
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
private static final Schema COMPLEX_SCHEMA =
new Schema(
@@ -90,8 +90,8 @@ public class TestParquetAvroWriter {
public void testCorrectness() throws IOException {
Iterable<Record> records = RandomData.generate(COMPLEX_SCHEMA, 50_000, 34139);
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<Record> writer =
Parquet.write(Files.localOutput(testFile))
@@ -115,7 +115,7 @@ public class TestParquetAvroWriter {
Iterator<Record> iter = records.iterator();
for (Record actual : reader) {
Record expected = iter.next();
- Assert.assertEquals("Record " + recordNum + " should match expected", expected, actual);
+ assertThat(actual).as("Record " + recordNum + " should match expected").isEqualTo(expected);
recordNum += 1;
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroEnums.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroEnums.java
index 6f05a9ed7c..11e60187fd 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroEnums.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroEnums.java
@@ -18,8 +18,11 @@
*/
package org.apache.iceberg.spark.data;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.List;
import org.apache.avro.SchemaBuilder;
import org.apache.avro.file.DataFileWriter;
@@ -34,14 +37,12 @@ import org.apache.iceberg.avro.AvroSchemaUtil;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.spark.sql.catalyst.InternalRow;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class TestSparkAvroEnums {
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
@Test
public void writeAndValidateEnums() throws IOException {
@@ -64,8 +65,8 @@ public class TestSparkAvroEnums {
Record enumRecord3 = new GenericData.Record(avroSchema); // null enum
List<Record> expected = ImmutableList.of(enumRecord1, enumRecord2, enumRecord3);
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (DataFileWriter<Record> writer = new DataFileWriter<>(new GenericDatumWriter<>())) {
writer.create(avroSchema, testFile);
@@ -90,7 +91,7 @@ public class TestSparkAvroEnums {
expected.get(i).get("enumCol") == null ? null : expected.get(i).get("enumCol").toString();
String sparkString =
rows.get(i).getUTF8String(0) == null ? null : rows.get(i).getUTF8String(0).toString();
- Assert.assertEquals(expectedEnumString, sparkString);
+ assertThat(sparkString).isEqualTo(expectedEnumString);
}
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroReader.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroReader.java
index 6d1ef3db36..3e5088258a 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroReader.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkAvroReader.java
@@ -19,6 +19,7 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.spark.data.TestHelpers.assertEqualsUnsafe;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -31,15 +32,14 @@ import org.apache.iceberg.avro.AvroIterable;
import org.apache.iceberg.io.FileAppender;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.spark.sql.catalyst.InternalRow;
-import org.junit.Assert;
public class TestSparkAvroReader extends AvroDataTest {
@Override
protected void writeAndValidate(Schema schema) throws IOException {
List<Record> expected = RandomData.generateList(schema, 100, 0L);
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<Record> writer =
Avro.write(Files.localOutput(testFile)).schema(schema).named("test").build()) {
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkDateTimes.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkDateTimes.java
index b31ea8fd27..6a06f9d583 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkDateTimes.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkDateTimes.java
@@ -18,14 +18,15 @@
*/
package org.apache.iceberg.spark.data;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.time.ZoneId;
import java.util.TimeZone;
import org.apache.iceberg.expressions.Literal;
import org.apache.iceberg.types.Types;
import org.apache.spark.sql.catalyst.util.DateTimeUtils;
import org.apache.spark.sql.catalyst.util.TimestampFormatter;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestSparkDateTimes {
@Test
@@ -47,7 +48,9 @@ public class TestSparkDateTimes {
public void checkSparkDate(String dateString) {
Literal<Integer> date = Literal.of(dateString).to(Types.DateType.get());
String sparkDate = DateTimeUtils.toJavaDate(date.value()).toString();
- Assert.assertEquals("Should be the same date (" + date.value() + ")", dateString, sparkDate);
+ assertThat(sparkDate)
+ .as("Should be the same date (" + date.value() + ")")
+ .isEqualTo(dateString);
}
@Test
@@ -68,7 +71,8 @@ public class TestSparkDateTimes {
ZoneId zoneId = DateTimeUtils.getZoneId("UTC");
TimestampFormatter formatter = TimestampFormatter.getFractionFormatter(zoneId);
String sparkTimestamp = formatter.format(ts.value());
- Assert.assertEquals(
- "Should be the same timestamp (" + ts.value() + ")", sparkRepr, sparkTimestamp);
+ assertThat(sparkTimestamp)
+ .as("Should be the same timestamp (" + ts.value() + ")")
+ .isEqualTo(sparkRepr);
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReadMetadataColumns.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReadMetadataColumns.java
index 3c9037adc3..9d725250d3 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReadMetadataColumns.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReadMetadataColumns.java
@@ -19,9 +19,12 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@@ -29,6 +32,9 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.iceberg.Files;
import org.apache.iceberg.MetadataColumns;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.ParameterizedTestExtension;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.Schema;
import org.apache.iceberg.exceptions.RuntimeIOException;
import org.apache.iceberg.expressions.Expression;
@@ -50,15 +56,12 @@ import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.vectorized.ColumnarBatch;
import org.apache.spark.unsafe.types.UTF8String;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
+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;
+
+@ExtendWith(ParameterizedTestExtension.class)
public class TestSparkOrcReadMetadataColumns {
private static final Schema DATA_SCHEMA =
new Schema(
@@ -95,24 +98,20 @@ public class TestSparkOrcReadMetadataColumns {
}
}
- @Parameterized.Parameters(name = "vectorized = {0}")
- public static Object[] parameters() {
- return new Object[] {false, true};
+ @Parameters(name = "vectorized = {0}")
+ public static Collection<Boolean> parameters() {
+ return Arrays.asList(false, true);
}
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private java.nio.file.Path temp;
- private boolean vectorized;
+ @Parameter private boolean vectorized;
private File testFile;
- public TestSparkOrcReadMetadataColumns(boolean vectorized) {
- this.vectorized = vectorized;
- }
-
- @Before
+ @BeforeEach
public void writeFile() throws IOException {
- testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<InternalRow> writer =
ORC.write(Files.localOutput(testFile))
@@ -127,18 +126,18 @@ public class TestSparkOrcReadMetadataColumns {
}
}
- @Test
+ @TestTemplate
public void testReadRowNumbers() throws IOException {
readAndValidate(null, null, null, EXPECTED_ROWS);
}
- @Test
+ @TestTemplate
public void testReadRowNumbersWithFilter() throws IOException {
readAndValidate(
Expressions.greaterThanOrEqual("id", 500), null, null, EXPECTED_ROWS.subList(500, 1000));
}
- @Test
+ @TestTemplate
public void testReadRowNumbersWithSplits() throws IOException {
Reader reader;
try {
@@ -201,10 +200,10 @@ public class TestSparkOrcReadMetadataColumns {
final Iterator<InternalRow> actualRows = reader.iterator();
final Iterator<InternalRow> expectedRows = expected.iterator();
while (expectedRows.hasNext()) {
- Assert.assertTrue("Should have expected number of rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should have expected number of rows").hasNext();
TestHelpers.assertEquals(PROJECTION_SCHEMA, expectedRows.next(), actualRows.next());
}
- Assert.assertFalse("Should not have extra rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should not have extra rows").isExhausted();
} finally {
if (reader != null) {
reader.close();
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReader.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReader.java
index b23fe729a1..5338eaf085 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReader.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkOrcReader.java
@@ -20,6 +20,7 @@ package org.apache.iceberg.spark.data;
import static org.apache.iceberg.spark.data.TestHelpers.assertEquals;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -37,8 +38,7 @@ import org.apache.iceberg.spark.data.vectorized.VectorizedSparkOrcReaders;
import org.apache.iceberg.types.Types;
import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.vectorized.ColumnarBatch;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestSparkOrcReader extends AvroDataTest {
@Override
@@ -62,8 +62,8 @@ public class TestSparkOrcReader extends AvroDataTest {
private void writeAndValidateRecords(Schema schema, Iterable<InternalRow> expected)
throws IOException {
- final File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<InternalRow> writer =
ORC.write(Files.localOutput(testFile))
@@ -81,10 +81,10 @@ public class TestSparkOrcReader extends AvroDataTest {
final Iterator<InternalRow> actualRows = reader.iterator();
final Iterator<InternalRow> expectedRows = expected.iterator();
while (expectedRows.hasNext()) {
- Assert.assertTrue("Should have expected number of rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should have expected number of rows").hasNext();
assertEquals(schema, expectedRows.next(), actualRows.next());
}
- Assert.assertFalse("Should not have extra rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should not have extra rows").isExhausted();
}
try (CloseableIterable<ColumnarBatch> reader =
@@ -97,10 +97,10 @@ public class TestSparkOrcReader extends AvroDataTest {
final Iterator<InternalRow> actualRows = batchesToRows(reader.iterator());
final Iterator<InternalRow> expectedRows = expected.iterator();
while (expectedRows.hasNext()) {
- Assert.assertTrue("Should have expected number of rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should have expected number of rows").hasNext();
assertEquals(schema, expectedRows.next(), actualRows.next());
}
- Assert.assertFalse("Should not have extra rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should not have extra rows").isExhausted();
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReadMetadataColumns.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReadMetadataColumns.java
index 01b633da0f..044ea3d93c 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReadMetadataColumns.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReadMetadataColumns.java
@@ -19,6 +19,8 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -31,6 +33,9 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.iceberg.Files;
import org.apache.iceberg.MetadataColumns;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.ParameterizedTestExtension;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.Schema;
import org.apache.iceberg.data.DeleteFilter;
import org.apache.iceberg.deletes.PositionDeleteIndex;
@@ -57,16 +62,12 @@ import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.types.StructType;
import org.apache.spark.sql.vectorized.ColumnarBatch;
import org.apache.spark.unsafe.types.UTF8String;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
+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;
+
+@ExtendWith(ParameterizedTestExtension.class)
public class TestSparkParquetReadMetadataColumns {
private static final Schema DATA_SCHEMA =
new Schema(
@@ -114,28 +115,24 @@ public class TestSparkParquetReadMetadataColumns {
}
}
- @Parameterized.Parameters(name = "vectorized = {0}")
+ @Parameters(name = "vectorized = {0}")
public static Object[][] parameters() {
return new Object[][] {new Object[] {false}, new Object[] {true}};
}
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir protected java.nio.file.Path temp;
- private final boolean vectorized;
+ @Parameter private boolean vectorized;
private File testFile;
- public TestSparkParquetReadMetadataColumns(boolean vectorized) {
- this.vectorized = vectorized;
- }
-
- @Before
+ @BeforeEach
public void writeFile() throws IOException {
List<Path> fileSplits = Lists.newArrayList();
StructType struct = SparkSchemaUtil.convert(DATA_SCHEMA);
Configuration conf = new Configuration();
- testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
ParquetFileWriter parquetFileWriter =
new ParquetFileWriter(
conf,
@@ -144,8 +141,8 @@ public class TestSparkParquetReadMetadataColumns {
parquetFileWriter.start();
for (int i = 0; i < NUM_ROW_GROUPS; i += 1) {
- File split = temp.newFile();
- Assert.assertTrue("Delete should succeed", split.delete());
+ File split = File.createTempFile("junit", null, temp.toFile());
+ assertThat(split.delete()).as("Delete should succeed").isTrue();
fileSplits.add(new Path(split.getAbsolutePath()));
try (FileAppender<InternalRow> writer =
Parquet.write(Files.localOutput(split))
@@ -164,14 +161,14 @@ public class TestSparkParquetReadMetadataColumns {
.getKeyValueMetaData());
}
- @Test
+ @TestTemplate
public void testReadRowNumbers() throws IOException {
readAndValidate(null, null, null, EXPECTED_ROWS);
}
- @Test
+ @TestTemplate
public void testReadRowNumbersWithDelete() throws IOException {
- Assume.assumeTrue(vectorized);
+ assumeThat(vectorized).isTrue();
List<InternalRow> expectedRowsAfterDelete = Lists.newArrayList();
EXPECTED_ROWS.forEach(row -> expectedRowsAfterDelete.add(row.copy()));
@@ -229,7 +226,7 @@ public class TestSparkParquetReadMetadataColumns {
}
}
- @Test
+ @TestTemplate
public void testReadRowNumbersWithFilter() throws IOException {
// current iceberg supports row group filter.
for (int i = 1; i < 5; i += 1) {
@@ -243,7 +240,7 @@ public class TestSparkParquetReadMetadataColumns {
}
}
- @Test
+ @TestTemplate
public void testReadRowNumbersWithSplits() throws IOException {
ParquetFileReader fileReader =
new ParquetFileReader(
@@ -295,11 +292,11 @@ public class TestSparkParquetReadMetadataColumns {
final Iterator<InternalRow> actualRows = reader.iterator();
for (InternalRow internalRow : expected) {
- Assert.assertTrue("Should have expected number of rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should have expected number of rows").hasNext();
TestHelpers.assertEquals(PROJECTION_SCHEMA, internalRow, actualRows.next());
}
- Assert.assertFalse("Should not have extra rows", actualRows.hasNext());
+ assertThat(actualRows).as("Should not have extra rows").isExhausted();
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReader.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReader.java
index 024ce3a60c..ab0d45c3b7 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReader.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetReader.java
@@ -20,6 +20,8 @@ package org.apache.iceberg.spark.data;
import static org.apache.iceberg.spark.data.TestHelpers.assertEqualsUnsafe;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
import java.io.File;
import java.io.IOException;
@@ -56,25 +58,22 @@ import org.apache.spark.sql.types.DataTypes;
import org.apache.spark.sql.types.Metadata;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
-import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestSparkParquetReader extends AvroDataTest {
@Override
protected void writeAndValidate(Schema schema) throws IOException {
- Assume.assumeTrue(
- "Parquet Avro cannot write non-string map keys",
- null
- == TypeUtil.find(
+ assumeThat(
+ TypeUtil.find(
schema,
- type -> type.isMapType() && type.asMapType().keyType() != Types.StringType.get()));
+ type -> type.isMapType() && type.asMapType().keyType() != Types.StringType.get()))
+ .as("Parquet Avro cannot write non-string map keys")
+ .isNull();
List<GenericData.Record> expected = RandomData.generateList(schema, 100, 0L);
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<GenericData.Record> writer =
Parquet.write(Files.localOutput(testFile)).schema(schema).named("test").build()) {
@@ -88,10 +87,10 @@ public class TestSparkParquetReader extends AvroDataTest {
.build()) {
Iterator<InternalRow> rows = reader.iterator();
for (GenericData.Record record : expected) {
- Assert.assertTrue("Should have expected number of rows", rows.hasNext());
+ assertThat(rows).as("Should have expected number of rows").hasNext();
assertEqualsUnsafe(schema.asStruct(), record, rows.next());
}
- Assert.assertFalse("Should not have extra rows", rows.hasNext());
+ assertThat(rows).as("Should not have extra rows").isExhausted();
}
}
@@ -112,7 +111,7 @@ public class TestSparkParquetReader extends AvroDataTest {
schema,
PartitionSpec.unpartitioned(),
ImmutableMap.of(),
- temp.newFolder().getCanonicalPath());
+ java.nio.file.Files.createTempDirectory(temp, null).toFile().getCanonicalPath());
table
.newAppend()
@@ -130,8 +129,7 @@ public class TestSparkParquetReader extends AvroDataTest {
@Test
public void testInt96TimestampProducedBySparkIsReadCorrectly() throws IOException {
- String outputFilePath =
- String.format("%s/%s", temp.getRoot().getAbsolutePath(), "parquet_int96.parquet");
+ String outputFilePath = String.format("%s/%s", temp.toAbsolutePath(), "parquet_int96.parquet");
HadoopOutputFile outputFile =
HadoopOutputFile.fromPath(
new org.apache.hadoop.fs.Path(outputFilePath), new Configuration());
@@ -157,15 +155,16 @@ public class TestSparkParquetReader extends AvroDataTest {
InputFile parquetInputFile = Files.localInput(outputFilePath);
List<InternalRow> readRows = rowsFromFile(parquetInputFile, schema);
- Assert.assertEquals(rows.size(), readRows.size());
- Assertions.assertThat(readRows).isEqualTo(rows);
+
+ assertThat(readRows).hasSameSizeAs(rows);
+ assertThat(readRows).isEqualTo(rows);
// Now we try to import that file as an Iceberg table to make sure Iceberg can read
// Int96 end to end.
Table int96Table = tableFromInputFile(parquetInputFile, schema);
List<Record> tableRecords = Lists.newArrayList(IcebergGenerics.read(int96Table).build());
- Assert.assertEquals(rows.size(), tableRecords.size());
+ assertThat(tableRecords).hasSameSizeAs(rows);
for (int i = 0; i < tableRecords.size(); i++) {
GenericsHelpers.assertEqualsUnsafe(schema.asStruct(), tableRecords.get(i), rows.get(i));
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetWriter.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetWriter.java
index 467d8a27a2..fa62d62281 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetWriter.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkParquetWriter.java
@@ -20,9 +20,11 @@ package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Iterator;
import org.apache.iceberg.Files;
import org.apache.iceberg.Schema;
@@ -32,13 +34,11 @@ import org.apache.iceberg.parquet.Parquet;
import org.apache.iceberg.spark.SparkSchemaUtil;
import org.apache.iceberg.types.Types;
import org.apache.spark.sql.catalyst.InternalRow;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
public class TestSparkParquetWriter {
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
private static final Schema COMPLEX_SCHEMA =
new Schema(
@@ -88,8 +88,8 @@ public class TestSparkParquetWriter {
int numRows = 50_000;
Iterable<InternalRow> records = RandomData.generateSpark(COMPLEX_SCHEMA, numRows, 19981);
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<InternalRow> writer =
Parquet.write(Files.localOutput(testFile))
@@ -110,10 +110,10 @@ public class TestSparkParquetWriter {
Iterator<InternalRow> expected = records.iterator();
Iterator<InternalRow> rows = reader.iterator();
for (int i = 0; i < numRows; i += 1) {
- Assert.assertTrue("Should have expected number of rows", rows.hasNext());
+ assertThat(rows).as("Should have expected number of rows").hasNext();
TestHelpers.assertEquals(COMPLEX_SCHEMA, expected.next(), rows.next());
}
- Assert.assertFalse("Should not have extra rows", rows.hasNext());
+ assertThat(rows).as("Should not have extra rows").isExhausted();
}
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkRecordOrcReaderWriter.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkRecordOrcReaderWriter.java
index d10e7f5a19..e9a7c1c07a 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkRecordOrcReaderWriter.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/TestSparkRecordOrcReaderWriter.java
@@ -19,6 +19,7 @@
package org.apache.iceberg.spark.data;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -38,15 +39,14 @@ import org.apache.iceberg.orc.ORC;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Types;
import org.apache.spark.sql.catalyst.InternalRow;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestSparkRecordOrcReaderWriter extends AvroDataTest {
private static final int NUM_RECORDS = 200;
private void writeAndValidate(Schema schema, List<Record> expectedRecords) throws IOException {
- final File originalFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", originalFile.delete());
+ final File originalFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(originalFile.delete()).as("Delete should succeed").isTrue();
// Write few generic records into the original test file.
try (FileAppender<Record> writer =
@@ -68,8 +68,8 @@ public class TestSparkRecordOrcReaderWriter extends AvroDataTest {
assertEqualsUnsafe(schema.asStruct(), expectedRecords, reader, expectedRecords.size());
}
- final File anotherFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", anotherFile.delete());
+ final File anotherFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(anotherFile.delete()).as("Delete should succeed").isTrue();
// Write those spark InternalRows into a new file again.
try (FileAppender<InternalRow> writer =
@@ -130,12 +130,12 @@ public class TestSparkRecordOrcReaderWriter extends AvroDataTest {
Iterator<Record> expectedIter = expected.iterator();
Iterator<Record> actualIter = actual.iterator();
for (int i = 0; i < size; i += 1) {
- Assert.assertTrue("Expected iterator should have more rows", expectedIter.hasNext());
- Assert.assertTrue("Actual iterator should have more rows", actualIter.hasNext());
- Assert.assertEquals("Should have same rows.", expectedIter.next(), actualIter.next());
+ assertThat(expectedIter).as("Expected iterator should have more rows").hasNext();
+ assertThat(actualIter).as("Actual iterator should have more rows").hasNext();
+ assertThat(actualIter.next()).as("Should have same rows.").isEqualTo(expectedIter.next());
}
- Assert.assertFalse("Expected iterator should not have any extra rows.", expectedIter.hasNext());
- Assert.assertFalse("Actual iterator should not have any extra rows.", actualIter.hasNext());
+ assertThat(expectedIter).as("Expected iterator should not have any extra rows.").isExhausted();
+ assertThat(actualIter).as("Actual iterator should not have any extra rows.").isExhausted();
}
private static void assertEqualsUnsafe(
@@ -143,11 +143,11 @@ public class TestSparkRecordOrcReaderWriter extends AvroDataTest {
Iterator<Record> expectedIter = expected.iterator();
Iterator<InternalRow> actualIter = actual.iterator();
for (int i = 0; i < size; i += 1) {
- Assert.assertTrue("Expected iterator should have more rows", expectedIter.hasNext());
- Assert.assertTrue("Actual iterator should have more rows", actualIter.hasNext());
+ assertThat(expectedIter).as("Expected iterator should have more rows").hasNext();
+ assertThat(actualIter).as("Actual iterator should have more rows").hasNext();
GenericsHelpers.assertEqualsUnsafe(struct, expectedIter.next(), actualIter.next());
}
- Assert.assertFalse("Expected iterator should not have any extra rows.", expectedIter.hasNext());
- Assert.assertFalse("Actual iterator should not have any extra rows.", actualIter.hasNext());
+ assertThat(expectedIter).as("Expected iterator should not have any extra rows.").isExhausted();
+ assertThat(actualIter).as("Actual iterator should not have any extra rows.").isExhausted();
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryEncodedVectorizedReads.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryEncodedVectorizedReads.java
index aeb18d43fd..eeed9d1a03 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryEncodedVectorizedReads.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryEncodedVectorizedReads.java
@@ -19,6 +19,7 @@
package org.apache.iceberg.spark.data.parquet.vectorized;
import static org.apache.iceberg.TableProperties.PARQUET_ROW_GROUP_SIZE_BYTES_DEFAULT;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
@@ -32,9 +33,8 @@ import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.spark.data.RandomData;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestParquetDictionaryEncodedVectorizedReads extends TestParquetVectorizedReads {
@@ -52,14 +52,14 @@ public class TestParquetDictionaryEncodedVectorizedReads extends TestParquetVect
@Test
@Override
- @Ignore // Ignored since this code path is already tested in TestParquetVectorizedReads
+ @Disabled // Ignored since this code path is already tested in TestParquetVectorizedReads
public void testVectorizedReadsWithNewContainers() throws IOException {}
@Test
public void testMixedDictionaryNonDictionaryReads() throws IOException {
Schema schema = new Schema(SUPPORTED_PRIMITIVES.fields());
- File dictionaryEncodedFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", dictionaryEncodedFile.delete());
+ File dictionaryEncodedFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(dictionaryEncodedFile.delete()).as("Delete should succeed").isTrue();
Iterable<GenericData.Record> dictionaryEncodableData =
RandomData.generateDictionaryEncodableData(
schema, 10000, 0L, RandomData.DEFAULT_NULL_PERCENTAGE);
@@ -68,8 +68,8 @@ public class TestParquetDictionaryEncodedVectorizedReads extends TestParquetVect
writer.addAll(dictionaryEncodableData);
}
- File plainEncodingFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", plainEncodingFile.delete());
+ File plainEncodingFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(plainEncodingFile.delete()).as("Delete should succeed").isTrue();
Iterable<GenericData.Record> nonDictionaryData =
RandomData.generate(schema, 10000, 0L, RandomData.DEFAULT_NULL_PERCENTAGE);
try (FileAppender<GenericData.Record> writer = getParquetWriter(schema, plainEncodingFile)) {
@@ -77,8 +77,8 @@ public class TestParquetDictionaryEncodedVectorizedReads extends TestParquetVect
}
int rowGroupSize = PARQUET_ROW_GROUP_SIZE_BYTES_DEFAULT;
- File mixedFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", mixedFile.delete());
+ File mixedFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(mixedFile.delete()).as("Delete should succeed").isTrue();
Parquet.concat(
ImmutableList.of(dictionaryEncodedFile, plainEncodingFile, dictionaryEncodedFile),
mixedFile,
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryFallbackToPlainEncodingVectorizedReads.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryFallbackToPlainEncodingVectorizedReads.java
index 42ea34936b..e6887c6f47 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryFallbackToPlainEncodingVectorizedReads.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetDictionaryFallbackToPlainEncodingVectorizedReads.java
@@ -29,8 +29,8 @@ import org.apache.iceberg.parquet.Parquet;
import org.apache.iceberg.relocated.com.google.common.base.Function;
import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
import org.apache.iceberg.spark.data.RandomData;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestParquetDictionaryFallbackToPlainEncodingVectorizedReads
extends TestParquetVectorizedReads {
@@ -65,11 +65,11 @@ public class TestParquetDictionaryFallbackToPlainEncodingVectorizedReads
@Test
@Override
- @Ignore // Fallback encoding not triggered when data is mostly null
+ @Disabled // Fallback encoding not triggered when data is mostly null
public void testMostlyNullsForOptionalFields() {}
@Test
@Override
- @Ignore // Ignored since this code path is already tested in TestParquetVectorizedReads
+ @Disabled // Ignored since this code path is already tested in TestParquetVectorizedReads
public void testVectorizedReadsWithNewContainers() throws IOException {}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetVectorizedReads.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetVectorizedReads.java
index c763b7b7cc..5c4b216aff 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetVectorizedReads.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/data/parquet/vectorized/TestParquetVectorizedReads.java
@@ -20,6 +20,9 @@ package org.apache.iceberg.spark.data.parquet.vectorized;
import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assumptions.assumeThat;
import java.io.File;
import java.io.IOException;
@@ -46,11 +49,8 @@ import org.apache.parquet.schema.GroupType;
import org.apache.parquet.schema.MessageType;
import org.apache.parquet.schema.Type;
import org.apache.spark.sql.vectorized.ColumnarBatch;
-import org.assertj.core.api.Assertions;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
public class TestParquetVectorizedReads extends AvroDataTest {
private static final int NUM_ROWS = 200_000;
@@ -80,19 +80,19 @@ public class TestParquetVectorizedReads extends AvroDataTest {
Function<GenericData.Record, GenericData.Record> transform)
throws IOException {
// Write test data
- Assume.assumeTrue(
- "Parquet Avro cannot write non-string map keys",
- null
- == TypeUtil.find(
+ assumeThat(
+ TypeUtil.find(
schema,
- type -> type.isMapType() && type.asMapType().keyType() != Types.StringType.get()));
+ type -> type.isMapType() && type.asMapType().keyType() != Types.StringType.get()))
+ .as("Parquet Avro cannot write non-string map keys")
+ .isNull();
Iterable<GenericData.Record> expected =
generateData(schema, numRecords, seed, nullPercentage, transform);
// write a test parquet file using iceberg writer
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<GenericData.Record> writer = getParquetWriter(schema, testFile)) {
writer.addAll(expected);
@@ -157,49 +157,49 @@ public class TestParquetVectorizedReads extends AvroDataTest {
numRowsRead += batch.numRows();
TestHelpers.assertEqualsBatch(schema.asStruct(), expectedIter, batch);
}
- Assert.assertEquals(expectedSize, numRowsRead);
+ assertThat(numRowsRead).isEqualTo(expectedSize);
}
}
@Override
@Test
- @Ignore
+ @Disabled
public void testArray() {}
@Override
@Test
- @Ignore
+ @Disabled
public void testArrayOfStructs() {}
@Override
@Test
- @Ignore
+ @Disabled
public void testMap() {}
@Override
@Test
- @Ignore
+ @Disabled
public void testNumericMapKey() {}
@Override
@Test
- @Ignore
+ @Disabled
public void testComplexMapKey() {}
@Override
@Test
- @Ignore
+ @Disabled
public void testMapOfStructs() {}
@Override
@Test
- @Ignore
+ @Disabled
public void testMixedTypes() {}
@Test
@Override
public void testNestedStruct() {
- Assertions.assertThatThrownBy(
+ assertThatThrownBy(
() ->
VectorizedSparkParquetReaders.buildReader(
TypeUtil.assignIncreasingFreshIds(
@@ -274,8 +274,8 @@ public class TestParquetVectorizedReads extends AvroDataTest {
optional(102, "float_data", Types.FloatType.get()),
optional(103, "decimal_data", Types.DecimalType.of(10, 5)));
- File dataFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", dataFile.delete());
+ File dataFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(dataFile.delete()).as("Delete should succeed").isTrue();
Iterable<GenericData.Record> data =
generateData(writeSchema, 30000, 0L, RandomData.DEFAULT_NULL_PERCENTAGE, IDENTITY);
try (FileAppender<GenericData.Record> writer = getParquetWriter(writeSchema, dataFile)) {
@@ -303,8 +303,8 @@ public class TestParquetVectorizedReads extends AvroDataTest {
optional(103, "double_data", Types.DoubleType.get()),
optional(104, "decimal_data", Types.DecimalType.of(25, 5)));
- File dataFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", dataFile.delete());
+ File dataFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(dataFile.delete()).as("Delete should succeed").isTrue();
Iterable<GenericData.Record> data =
generateData(schema, 30000, 0L, RandomData.DEFAULT_NULL_PERCENTAGE, IDENTITY);
try (FileAppender<GenericData.Record> writer = getParquetV2Writer(schema, dataFile)) {
@@ -318,15 +318,14 @@ public class TestParquetVectorizedReads extends AvroDataTest {
// Longs, ints, string types etc use delta encoding and which are not supported for vectorized
// reads
Schema schema = new Schema(SUPPORTED_PRIMITIVES.fields());
- File dataFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", dataFile.delete());
+ File dataFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(dataFile.delete()).as("Delete should succeed").isTrue();
Iterable<GenericData.Record> data =
generateData(schema, 30000, 0L, RandomData.DEFAULT_NULL_PERCENTAGE, IDENTITY);
try (FileAppender<GenericData.Record> writer = getParquetV2Writer(schema, dataFile)) {
writer.addAll(data);
}
- Assertions.assertThatThrownBy(
- () -> assertRecordsMatch(schema, 30000, data, dataFile, false, BATCH_SIZE))
+ assertThatThrownBy(() -> assertRecordsMatch(schema, 30000, data, dataFile, false, BATCH_SIZE))
.isInstanceOf(UnsupportedOperationException.class)
.hasMessageStartingWith("Cannot support vectorized reads for column")
.hasMessageEndingWith("Disable vectorized reads to read this table/file");
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestAvroScan.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestAvroScan.java
index 9491adde46..8345a4e0a6 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestAvroScan.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestAvroScan.java
@@ -19,9 +19,11 @@
package org.apache.iceberg.spark.source;
import static org.apache.iceberg.Files.localOutput;
+import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.List;
import java.util.UUID;
import org.apache.avro.generic.GenericData.Record;
@@ -41,25 +43,23 @@ import org.apache.iceberg.spark.data.TestHelpers;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.io.TempDir;
public class TestAvroScan extends AvroDataTest {
private static final Configuration CONF = new Configuration();
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
private static SparkSession spark = null;
- @BeforeClass
+ @BeforeAll
public static void startSpark() {
TestAvroScan.spark = SparkSession.builder().master("local[2]").getOrCreate();
}
- @AfterClass
+ @AfterAll
public static void stopSpark() {
SparkSession currentSpark = TestAvroScan.spark;
TestAvroScan.spark = null;
@@ -68,7 +68,7 @@ public class TestAvroScan extends AvroDataTest {
@Override
protected void writeAndValidate(Schema schema) throws IOException {
- File parent = temp.newFolder("avro");
+ File parent = temp.resolve("avro").toFile();
File location = new File(parent, "test");
File dataFolder = new File(location, "data");
dataFolder.mkdirs();
@@ -102,7 +102,7 @@ public class TestAvroScan extends AvroDataTest {
Dataset<Row> df = spark.read().format("iceberg").load(location.toString());
List<Row> rows = df.collectAsList();
- Assert.assertEquals("Should contain 100 rows", 100, rows.size());
+ assertThat(rows).as("Should contain 100 rows").hasSize(100);
for (int i = 0; i < expected.size(); i += 1) {
TestHelpers.assertEqualsSafe(tableSchema.asStruct(), expected.get(i), rows.get(i));
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestDataFrameWrites.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestDataFrameWrites.java
index d0f181177f..e702f1f01e 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestDataFrameWrites.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestDataFrameWrites.java
@@ -21,11 +21,15 @@ package org.apache.iceberg.spark.source;
import static org.apache.iceberg.spark.SparkSchemaUtil.convert;
import static org.apache.iceberg.spark.data.TestHelpers.assertEqualsSafe;
import static org.apache.iceberg.spark.data.TestHelpers.assertEqualsUnsafe;
+import static org.assertj.core.api.Assertions.assertThat;
+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.net.URI;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -33,6 +37,9 @@ import java.util.Random;
import org.apache.avro.generic.GenericData.Record;
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.Files;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.ParameterizedTestExtension;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Snapshot;
@@ -47,7 +54,7 @@ import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.spark.SparkSQLProperties;
import org.apache.iceberg.spark.SparkSchemaUtil;
import org.apache.iceberg.spark.SparkWriteOptions;
-import org.apache.iceberg.spark.data.AvroDataTest;
+import org.apache.iceberg.spark.data.ParameterizedAvroDataTest;
import org.apache.iceberg.spark.data.RandomData;
import org.apache.iceberg.spark.data.SparkAvroReader;
import org.apache.iceberg.types.Types;
@@ -63,29 +70,21 @@ import org.apache.spark.sql.Row;
import org.apache.spark.sql.SaveMode;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.catalyst.InternalRow;
-import org.assertj.core.api.Assertions;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class TestDataFrameWrites extends AvroDataTest {
- private static final Configuration CONF = new Configuration();
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
- private final String format;
+@ExtendWith(ParameterizedTestExtension.class)
+public class TestDataFrameWrites extends ParameterizedAvroDataTest {
+ private static final Configuration CONF = new Configuration();
- @Parameterized.Parameters(name = "format = {0}")
- public static Object[] parameters() {
- return new Object[] {"parquet", "avro", "orc"};
+ @Parameters(name = "format = {0}")
+ public static Collection<String> parameters() {
+ return Arrays.asList("parquet", "avro", "orc");
}
- public TestDataFrameWrites(String format) {
- this.format = format;
- }
+ @Parameter private String format;
private static SparkSession spark = null;
private static JavaSparkContext sc = null;
@@ -123,13 +122,13 @@ public class TestDataFrameWrites extends AvroDataTest {
"{\"optionalField\": \"d3\", \"requiredField\": \"bid_103\"}",
"{\"optionalField\": \"d4\", \"requiredField\": \"bid_104\"}");
- @BeforeClass
+ @BeforeAll
public static void startSpark() {
TestDataFrameWrites.spark = SparkSession.builder().master("local[2]").getOrCreate();
TestDataFrameWrites.sc = JavaSparkContext.fromSparkContext(spark.sparkContext());
}
- @AfterClass
+ @AfterAll
public static void stopSpark() {
SparkSession currentSpark = TestDataFrameWrites.spark;
TestDataFrameWrites.spark = null;
@@ -144,10 +143,10 @@ public class TestDataFrameWrites extends AvroDataTest {
writeAndValidateWithLocations(table, location, new File(location, "data"));
}
- @Test
+ @TestTemplate
public void testWriteWithCustomDataLocation() throws IOException {
File location = createTableFolder();
- File tablePropertyDataLocation = temp.newFolder("test-table-property-data-dir");
+ File tablePropertyDataLocation = temp.resolve("test-table-property-data-dir").toFile();
Table table = createTable(new Schema(SUPPORTED_PRIMITIVES.fields()), location);
table
.updateProperties()
@@ -157,9 +156,9 @@ public class TestDataFrameWrites extends AvroDataTest {
}
private File createTableFolder() throws IOException {
- File parent = temp.newFolder("parquet");
+ File parent = temp.resolve("parquet").toFile();
File location = new File(parent, "test");
- Assert.assertTrue("Mkdir should succeed", location.mkdirs());
+ assertThat(location.mkdirs()).as("Mkdir should succeed").isTrue();
return location;
}
@@ -186,21 +185,21 @@ public class TestDataFrameWrites extends AvroDataTest {
while (expectedIter.hasNext() && actualIter.hasNext()) {
assertEqualsSafe(tableSchema.asStruct(), expectedIter.next(), actualIter.next());
}
- Assert.assertEquals(
- "Both iterators should be exhausted", expectedIter.hasNext(), actualIter.hasNext());
+ assertThat(actualIter.hasNext())
+ .as("Both iterators should be exhausted")
+ .isEqualTo(expectedIter.hasNext());
table
.currentSnapshot()
.addedDataFiles(table.io())
.forEach(
dataFile ->
- Assert.assertTrue(
- String.format(
- "File should have the parent directory %s, but has: %s.",
- expectedDataDir.getAbsolutePath(), dataFile.path()),
- URI.create(dataFile.path().toString())
- .getPath()
- .startsWith(expectedDataDir.getAbsolutePath())));
+ assertThat(URI.create(dataFile.path().toString()).getPath())
+ .as(
+ String.format(
+ "File should have the parent directory %s, but has: %s.",
+ expectedDataDir.getAbsolutePath(), dataFile.path()))
+ .startsWith(expectedDataDir.getAbsolutePath()));
}
private List<Row> readTable(String location) {
@@ -247,8 +246,8 @@ public class TestDataFrameWrites extends AvroDataTest {
private Dataset<Row> createDataset(Iterable<Record> records, Schema schema) throws IOException {
// this uses the SparkAvroReader to create a DataFrame from the list of records
// it assumes that SparkAvroReader is correct
- File testFile = temp.newFile();
- Assert.assertTrue("Delete should succeed", testFile.delete());
+ File testFile = File.createTempFile("junit", null, temp.toFile());
+ assertThat(testFile.delete()).as("Delete should succeed").isTrue();
try (FileAppender<Record> writer =
Avro.write(Files.localOutput(testFile)).schema(schema).named("test").build()) {
@@ -272,20 +271,22 @@ public class TestDataFrameWrites extends AvroDataTest {
assertEqualsUnsafe(schema.asStruct(), recordIter.next(), row);
rows.add(row);
}
- Assert.assertEquals(
- "Both iterators should be exhausted", recordIter.hasNext(), readIter.hasNext());
+ assertThat(readIter.hasNext())
+ .as("Both iterators should be exhausted")
+ .isEqualTo(recordIter.hasNext());
}
JavaRDD<InternalRow> rdd = sc.parallelize(rows);
return spark.internalCreateDataFrame(JavaRDD.toRDD(rdd), convert(schema), false);
}
- @Test
+ @TestTemplate
public void testNullableWithWriteOption() throws IOException {
- Assume.assumeTrue(
- "Spark 3 rejects writing nulls to a required column", spark.version().startsWith("2"));
+ assumeThat(spark.version())
+ .as("Spark 3 rejects writing nulls to a required column")
+ .startsWith("2");
- File location = new File(temp.newFolder("parquet"), "test");
+ File location = temp.resolve("parquet").resolve("test").toFile();
String sourcePath = String.format("%s/nullable_poc/sourceFolder/", location.toString());
String targetPath = String.format("%s/nullable_poc/targetFolder/", location.toString());
@@ -330,15 +331,16 @@ public class TestDataFrameWrites extends AvroDataTest {
// read all data
List<Row> rows = spark.read().format("iceberg").load(targetPath).collectAsList();
- Assert.assertEquals("Should contain 6 rows", 6, rows.size());
+ assumeThat(rows).as("Should contain 6 rows").hasSize(6);
}
- @Test
+ @TestTemplate
public void testNullableWithSparkSqlOption() throws IOException {
- Assume.assumeTrue(
- "Spark 3 rejects writing nulls to a required column", spark.version().startsWith("2"));
+ assumeThat(spark.version())
+ .as("Spark 3 rejects writing nulls to a required column")
+ .startsWith("2");
- File location = new File(temp.newFolder("parquet"), "test");
+ File location = temp.resolve("parquet").resolve("test").toFile();
String sourcePath = String.format("%s/nullable_poc/sourceFolder/", location.toString());
String targetPath = String.format("%s/nullable_poc/targetFolder/", location.toString());
@@ -389,10 +391,10 @@ public class TestDataFrameWrites extends AvroDataTest {
// read all data
List<Row> rows = newSparkSession.read().format("iceberg").load(targetPath).collectAsList();
- Assert.assertEquals("Should contain 6 rows", 6, rows.size());
+ assumeThat(rows).as("Should contain 6 rows").hasSize(6);
}
- @Test
+ @TestTemplate
public void testFaultToleranceOnWrite() throws IOException {
File location = createTableFolder();
Schema schema = new Schema(SUPPORTED_PRIMITIVES.fields());
@@ -408,8 +410,7 @@ public class TestDataFrameWrites extends AvroDataTest {
Iterable<Record> records2 = RandomData.generate(schema, 100, 0L);
- Assertions.assertThatThrownBy(
- () -> writeDataWithFailOnPartition(records2, schema, location.toString()))
+ assertThatThrownBy(() -> writeDataWithFailOnPartition(records2, schema, location.toString()))
.isInstanceOf(SparkException.class);
table.refresh();
@@ -417,7 +418,7 @@ public class TestDataFrameWrites extends AvroDataTest {
Snapshot snapshotAfterFailingWrite = table.currentSnapshot();
List<Row> resultAfterFailingWrite = readTable(location.toString());
- Assert.assertEquals(snapshotAfterFailingWrite, snapshotBeforeFailingWrite);
- Assert.assertEquals(resultAfterFailingWrite, resultBeforeFailingWrite);
+ assertThat(snapshotBeforeFailingWrite).isEqualTo(snapshotAfterFailingWrite);
+ assertThat(resultBeforeFailingWrite).isEqualTo(resultAfterFailingWrite);
}
}
diff --git a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestParquetScan.java b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestParquetScan.java
index a9daa0df45..ebeed62acc 100644
--- a/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestParquetScan.java
+++ b/spark/v3.5/spark/src/test/java/org/apache/iceberg/spark/source/TestParquetScan.java
@@ -23,9 +23,13 @@ import static org.apache.iceberg.types.Types.NestedField.optional;
import static org.apache.iceberg.types.Types.NestedField.required;
import static org.apache.spark.sql.functions.monotonically_increasing_id;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.UUID;
import org.apache.avro.generic.GenericData;
@@ -33,6 +37,9 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.DataFiles;
import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Parameter;
+import org.apache.iceberg.ParameterizedTestExtension;
+import org.apache.iceberg.Parameters;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Table;
@@ -40,7 +47,7 @@ import org.apache.iceberg.TableProperties;
import org.apache.iceberg.hadoop.HadoopTables;
import org.apache.iceberg.io.FileAppender;
import org.apache.iceberg.parquet.Parquet;
-import org.apache.iceberg.spark.data.AvroDataTest;
+import org.apache.iceberg.spark.data.ParameterizedAvroDataTest;
import org.apache.iceberg.spark.data.RandomData;
import org.apache.iceberg.spark.data.TestHelpers;
import org.apache.iceberg.types.TypeUtil;
@@ -48,56 +55,49 @@ import org.apache.iceberg.types.Types;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@RunWith(Parameterized.class)
-public class TestParquetScan extends AvroDataTest {
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+
+@ExtendWith(ParameterizedTestExtension.class)
+public class TestParquetScan extends ParameterizedAvroDataTest {
private static final Configuration CONF = new Configuration();
private static SparkSession spark = null;
- @BeforeClass
+ @BeforeAll
public static void startSpark() {
TestParquetScan.spark = SparkSession.builder().master("local[2]").getOrCreate();
}
- @AfterClass
+ @AfterAll
public static void stopSpark() {
SparkSession currentSpark = TestParquetScan.spark;
TestParquetScan.spark = null;
currentSpark.stop();
}
- @Rule public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir private Path temp;
- @Parameterized.Parameters(name = "vectorized = {0}")
- public static Object[] parameters() {
- return new Object[] {false, true};
- }
-
- private final boolean vectorized;
+ @Parameter private boolean vectorized;
- public TestParquetScan(boolean vectorized) {
- this.vectorized = vectorized;
+ @Parameters(name = "vectorized = {0}")
+ public static Collection<Boolean> parameters() {
+ return Arrays.asList(false, true);
}
@Override
protected void writeAndValidate(Schema schema) throws IOException {
- Assume.assumeTrue(
- "Cannot handle non-string map keys in parquet-avro",
- null
- == TypeUtil.find(
+ assumeThat(
+ TypeUtil.find(
schema,
- type -> type.isMapType() && type.asMapType().keyType() != Types.StringType.get()));
+ type -> type.isMapType() && type.asMapType().keyType() != Types.StringType.get()))
+ .as("Cannot handle non-string map keys in parquet-avro")
+ .isNull();
+ assertThat(vectorized).as("should not be null").isNotNull();
Table table = createTable(schema);
// Important: use the table's schema for the rest of the test
@@ -110,14 +110,14 @@ public class TestParquetScan extends AvroDataTest {
Dataset<Row> df = spark.read().format("iceberg").load(table.location());
List<Row> rows = df.collectAsList();
- Assert.assertEquals("Should contain 100 rows", 100, rows.size());
+ assertThat(rows).as("Should contain 100 rows").hasSize(100);
for (int i = 0; i < expected.size(); i += 1) {
TestHelpers.assertEqualsSafe(table.schema().asStruct(), expected.get(i), rows.get(i));
}
}
- @Test
+ @TestTemplate
public void testEmptyTableProjection() throws IOException {
Types.StructType structType =
Types.StructType.of(
@@ -143,7 +143,7 @@ public class TestParquetScan extends AvroDataTest {
}
private Table createTable(Schema schema) throws IOException {
- File parent = temp.newFolder("parquet");
+ File parent = temp.resolve("parquet").toFile();
File location = new File(parent, "test");
HadoopTables tables = new HadoopTables(CONF);
return tables.create(schema, PartitionSpec.unpartitioned(), location.toString());