You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ji...@apache.org on 2024/02/26 10:45:25 UTC
(flink) branch master updated: [FLINK-25537] [JUnit5 Migration] Module: flink-core package api-common (#23960)
This is an automated email from the ASF dual-hosted git repository.
jiabaosun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 922cc2ad522 [FLINK-25537] [JUnit5 Migration] Module: flink-core package api-common (#23960)
922cc2ad522 is described below
commit 922cc2ad52203e4c474f3837fcc9a219dd293fa5
Author: gongzhongqiang <76...@qq.com>
AuthorDate: Mon Feb 26 18:45:17 2024 +0800
[FLINK-25537] [JUnit5 Migration] Module: flink-core package api-common (#23960)
---
.../ExecutionConfigFromConfigurationTest.java | 33 +-
.../flink/api/common/ExecutionConfigTest.java | 17 +-
.../accumulators/AverageAccumulatorTest.java | 56 +-
.../api/common/accumulators/DoubleMaximumTest.java | 31 +-
.../api/common/accumulators/DoubleMinimumTest.java | 31 +-
.../api/common/accumulators/IntMaximumTest.java | 30 +-
.../api/common/accumulators/IntMinimumTest.java | 30 +-
.../api/common/accumulators/LongMaximumTest.java | 30 +-
.../api/common/accumulators/LongMinimumTest.java | 30 +-
.../AscendingTimestampsWatermarksTest.java | 18 +-
.../BoundedOutOfOrdernessWatermarksTest.java | 25 +-
.../api/common/eventtime/WatermarkMatchers.java | 41 -
.../eventtime/WatermarkOutputMultiplexerTest.java | 136 ++-
.../common/eventtime/WatermarkStrategyTest.java | 105 +--
.../eventtime/WatermarksWithIdlenessTest.java | 55 +-
.../functions/util/RuntimeUDFContextTest.java | 296 +++---
.../flink/api/common/io/BinaryInputFormatTest.java | 25 +-
.../flink/api/common/io/DefaultFilterTest.java | 25 +-
.../io/DelimitedInputFormatSamplingTest.java | 408 ++++-----
.../api/common/io/DelimitedInputFormatTest.java | 228 +++--
.../api/common/io/EnumerateNestedFilesTest.java | 448 +++++-----
.../flink/api/common/io/FileInputFormatTest.java | 886 +++++++++---------
.../flink/api/common/io/FileOutputFormatTest.java | 594 ++++++-------
.../api/common/io/GenericCsvInputFormatTest.java | 990 ++++++++++-----------
.../api/common/io/GlobFilePathFilterTest.java | 61 +-
.../common/io/InputStreamFSInputWrapperTest.java | 6 +-
.../flink/api/common/io/OutputFormatBaseTest.java | 50 +-
.../flink/api/common/io/RichInputFormatTest.java | 23 +-
.../flink/api/common/io/RichOutputFormatTest.java | 23 +-
.../operators/DualInputSemanticPropertiesTest.java | 243 ++---
.../api/common/operators/ExpressionKeysTest.java | 261 +++---
.../common/operators/GenericDataSinkBaseTest.java | 165 ++--
.../operators/GenericDataSourceBaseTest.java | 157 ++--
.../flink/api/common/operators/OrderingTest.java | 19 +-
.../api/common/operators/ResourceSpecTest.java | 147 +--
.../common/operators/SelectorFunctionKeysTest.java | 51 +-
.../SingleInputSemanticPropertiesTest.java | 178 ++--
.../api/common/operators/SlotSharingGroupTest.java | 69 +-
.../base/FlatMapOperatorCollectionTest.java | 75 +-
.../operators/base/InnerJoinOperatorBaseTest.java | 170 ++--
.../api/common/operators/base/MapOperatorTest.java | 208 ++---
.../operators/base/OuterJoinOperatorBaseTest.java | 57 +-
.../operators/base/PartitionMapOperatorTest.java | 162 ++--
.../api/common/operators/util/FieldListTest.java | 35 +-
.../api/common/operators/util/FieldSetTest.java | 34 +-
.../operators/util/NonRichGenericInputFormat.java | 10 +-
.../operators/util/SlotSharingGroupUtilsTest.java | 15 +-
.../operators/util/TestNonRichInputFormat.java | 6 +-
.../operators/util/TestNonRichOutputFormat.java | 2 +-
.../common/operators/util/TestRichInputFormat.java | 7 +-
.../operators/util/TestRichOutputFormat.java | 3 +-
.../api/common/resources/CPUResourceTest.java | 34 +-
.../flink/api/common/resources/ResourceTest.java | 142 +--
.../AbstractDeserializationSchemaTest.java | 63 +-
.../serialization/SerializerConfigImplTest.java | 2 +-
.../serialization/SimpleStringSchemaTest.java | 17 +-
.../TypeInformationSerializationSchemaTest.java | 66 +-
.../api/common/state/ListStateDescriptorTest.java | 53 +-
.../api/common/state/MapStateDescriptorTest.java | 63 +-
.../common/state/ReducingStateDescriptorTest.java | 40 +-
.../api/common/state/StateDescriptorTest.java | 147 ++-
.../flink/api/common/state/StateTtlConfigTest.java | 59 +-
.../api/common/state/ValueStateDescriptorTest.java | 42 +-
.../flink/api/common/typeinfo/TypeHintTest.java | 29 +-
.../api/common/typeinfo/TypeInformationTest.java | 40 +-
.../api/common/typeutils/ComparatorTestBase.java | 387 ++++----
.../common/typeutils/CompositeSerializerTest.java | 4 +-
.../CompositeTypeSerializerSnapshotTest.java | 63 +-
.../CompositeTypeSerializerUpgradeTest.java | 5 +-
.../typeutils/CompositeTypeSerializerUtilTest.java | 60 +-
.../api/common/typeutils/SerializerTestBase.java | 398 ++++-----
.../common/typeutils/ThreadContextClassLoader.java | 3 +-
.../common/typeutils/TypeInformationTestBase.java | 9 +-
.../typeutils/TypeSerializerSnapshotTest.java | 8 +-
.../typeutils/TypeSerializerUpgradeTestBase.java | 19 +-
.../typeutils/base/BigDecSerializerTest.java | 2 +-
.../common/typeutils/base/ByteSerializerTest.java | 2 +-
.../typeutils/base/ByteValueSerializerTest.java | 2 +-
.../common/typeutils/base/CharSerializerTest.java | 2 +-
.../typeutils/base/CharValueSerializerTest.java | 2 +-
.../base/EnumSerializerCompatibilityTest.java | 42 +-
.../common/typeutils/base/EnumSerializerTest.java | 205 ++---
.../typeutils/base/EnumSerializerUpgradeTest.java | 8 +-
.../common/typeutils/base/ListSerializerTest.java | 2 +-
.../common/typeutils/base/MapSerializerTest.java | 2 +-
.../array/BytePrimitiveArraySerializerTest.java | 2 +-
.../array/PrimitiveArrayComparatorTestBase.java | 2 +-
.../api/java/typeutils/MissingTypeInfoTest.java | 4 +-
.../runtime/AbstractGenericTypeComparatorTest.java | 13 +-
.../flink/configuration/ConfigurationTest.java | 22 +-
.../flink/testutils/CustomEqualityMatcher.java | 13 +-
.../runtime/arrow/ArrowReaderWriterTestBase.java | 8 +-
.../arrow/sources/ArrowSourceFunctionTestBase.java | 8 +-
93 files changed, 4088 insertions(+), 4811 deletions(-)
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigFromConfigurationTest.java b/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigFromConfigurationTest.java
index 18f208ba3c9..832652433f6 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigFromConfigurationTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigFromConfigurationTest.java
@@ -19,10 +19,12 @@
package org.apache.flink.api.common;
import org.apache.flink.configuration.Configuration;
+import org.apache.flink.testutils.junit.extensions.parameterized.Parameter;
+import org.apache.flink.testutils.junit.extensions.parameterized.ParameterizedTestExtension;
+import org.apache.flink.testutils.junit.extensions.parameterized.Parameters;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Arrays;
import java.util.Collection;
@@ -30,14 +32,13 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
-@RunWith(Parameterized.class)
-public class ExecutionConfigFromConfigurationTest {
+@ExtendWith(ParameterizedTestExtension.class)
+class ExecutionConfigFromConfigurationTest {
- @Parameterized.Parameters(name = "{0}")
- public static Collection<TestSpec> specs() {
+ @Parameters(name = "{0}")
+ private static Collection<TestSpec> specs() {
return Arrays.asList(
TestSpec.testValue(false)
.whenSetFromFile("pipeline.auto-generate-uids", "false")
@@ -140,10 +141,10 @@ public class ExecutionConfigFromConfigurationTest {
.nonDefaultValue(21L));
}
- @Parameterized.Parameter public TestSpec spec;
+ @Parameter private TestSpec spec;
- @Test
- public void testLoadingFromConfiguration() {
+ @TestTemplate
+ void testLoadingFromConfiguration() {
ExecutionConfig configFromSetters = new ExecutionConfig();
ExecutionConfig configFromFile = new ExecutionConfig();
@@ -155,8 +156,8 @@ public class ExecutionConfigFromConfigurationTest {
spec.assertEqual(configFromFile, configFromSetters);
}
- @Test
- public void testNotOverridingIfNotSet() {
+ @TestTemplate
+ void testNotOverridingIfNotSet() {
ExecutionConfig executionConfig = new ExecutionConfig();
spec.setNonDefaultValue(executionConfig);
@@ -227,11 +228,11 @@ public class ExecutionConfigFromConfigurationTest {
}
public void assertEqual(ExecutionConfig configFromFile, ExecutionConfig configFromSetters) {
- assertThat(getter.apply(configFromFile), equalTo(getter.apply(configFromSetters)));
+ assertThat(getter.apply(configFromSetters)).isEqualTo(getter.apply(configFromFile));
}
public void assertEqualNonDefault(ExecutionConfig configFromFile) {
- assertThat(getter.apply(configFromFile), equalTo(nonDefaultValue));
+ assertThat(getter.apply(configFromFile)).isEqualTo(nonDefaultValue);
}
@Override
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigTest.java b/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigTest.java
index b5df84346a2..492c911ba52 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/ExecutionConfigTest.java
@@ -36,7 +36,6 @@ import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import org.junit.jupiter.api.Test;
-import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.LinkedHashMap;
@@ -52,8 +51,8 @@ public class ExecutionConfigTest {
@Test
void testDoubleTypeRegistration() {
ExecutionConfig config = new ExecutionConfig();
- List<Class<?>> types = Arrays.<Class<?>>asList(Double.class, Integer.class, Double.class);
- List<Class<?>> expectedTypes = Arrays.<Class<?>>asList(Double.class, Integer.class);
+ List<Class<?>> types = Arrays.asList(Double.class, Integer.class, Double.class);
+ List<Class<?>> expectedTypes = Arrays.asList(Double.class, Integer.class);
for (Class<?> tpe : types) {
config.getSerializerConfig().registerKryoType(tpe);
@@ -65,7 +64,7 @@ public class ExecutionConfigTest {
assertThat(tpe).isEqualTo(expectedTypes.get(counter++));
}
- assertThat(expectedTypes.size()).isEqualTo(counter);
+ assertThat(expectedTypes).hasSize(counter);
}
@Test
@@ -88,11 +87,11 @@ public class ExecutionConfigTest {
@Test
void testDisableGenericTypes() {
SerializerConfigImpl conf = new SerializerConfigImpl();
- TypeInformation<Object> typeInfo = new GenericTypeInfo<Object>(Object.class);
+ TypeInformation<Object> typeInfo = new GenericTypeInfo<>(Object.class);
// by default, generic types are supported
TypeSerializer<Object> serializer = typeInfo.createSerializer(conf);
- assertThat(serializer instanceof KryoSerializer).isTrue();
+ assertThat(serializer).isInstanceOf(KryoSerializer.class);
// expect an exception when generic types are disabled
conf.setGenericTypes(false);
@@ -103,7 +102,7 @@ public class ExecutionConfigTest {
}
@Test
- void testExecutionConfigSerialization() throws IOException, ClassNotFoundException {
+ void testExecutionConfigSerialization() throws Exception {
final Random r = new Random();
final int parallelism = 1 + r.nextInt(10);
@@ -249,7 +248,7 @@ public class ExecutionConfigTest {
}
@Test
- public void testLoadingSchedulerTypeFromConfiguration() {
+ void testLoadingSchedulerTypeFromConfiguration() {
testLoadingSchedulerTypeFromConfiguration(JobManagerOptions.SchedulerType.AdaptiveBatch);
testLoadingSchedulerTypeFromConfiguration(JobManagerOptions.SchedulerType.Default);
testLoadingSchedulerTypeFromConfiguration(JobManagerOptions.SchedulerType.Adaptive);
@@ -264,7 +263,7 @@ public class ExecutionConfigTest {
configFromConfiguration.configure(
configuration, Thread.currentThread().getContextClassLoader());
- assertThat(configFromConfiguration.getSchedulerType().get()).isEqualTo(schedulerType);
+ assertThat(configFromConfiguration.getSchedulerType()).contains(schedulerType);
}
@Test
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/AverageAccumulatorTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/AverageAccumulatorTest.java
index 7385d8ca680..800d6639c0e 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/AverageAccumulatorTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/AverageAccumulatorTest.java
@@ -18,71 +18,70 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.within;
-public class AverageAccumulatorTest {
+class AverageAccumulatorTest {
@Test
- public void testGet() {
+ void testGet() {
AverageAccumulator average = new AverageAccumulator();
- assertEquals(0.0, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(0.0, within(0.0));
}
@Test
- public void testAdd() {
+ void testAdd() {
AverageAccumulator average = new AverageAccumulator();
int i1;
for (i1 = 0; i1 < 10; i1++) {
average.add(i1);
}
- assertEquals(4.5, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(4.5, within(0.0));
average.resetLocal();
Integer i2;
for (i2 = 0; i2 < 10; i2++) {
average.add(i2);
}
- assertEquals(4.5, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(4.5, within(0.0));
average.resetLocal();
long i3;
for (i3 = 0; i3 < 10; i3++) {
average.add(i3);
}
- assertEquals(4.5, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(4.5, within(0.0));
average.resetLocal();
Long i4;
for (i4 = 0L; i4 < 10; i4++) {
average.add(i4);
}
- assertEquals(4.5, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(4.5, within(0.0));
average.resetLocal();
double i5;
for (i5 = 0; i5 < 10; i5++) {
average.add(i5);
}
- assertEquals(4.5, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(4.5, within(0.0));
average.resetLocal();
Double i6;
for (i6 = 0.0; i6 < 10; i6++) {
average.add(i6);
}
- assertEquals(4.5, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(4.5, within(0.0));
average.resetLocal();
- assertEquals(0.0, average.getLocalValue(), 0.0);
+ assertThat(average.getLocalValue()).isCloseTo(0.0, within(0.0));
}
@Test
- public void testMergeSuccess() {
+ void testMergeSuccess() {
AverageAccumulator avg1 = new AverageAccumulator();
for (int i = 0; i < 5; i++) {
avg1.add(i);
@@ -94,33 +93,24 @@ public class AverageAccumulatorTest {
}
avg1.merge(avg2);
- assertEquals(4.5, avg1.getLocalValue(), 0.0);
+ assertThat(avg1.getLocalValue()).isCloseTo(4.5, within(0.0));
}
@Test
- public void testMergeFailed() {
+ void testMergeFailed() {
AverageAccumulator average = new AverageAccumulator();
Accumulator<Double, Double> averageNew = null;
average.add(1);
- try {
- average.merge(averageNew);
- fail("should fail with an exception");
- } catch (IllegalArgumentException e) {
- assertNotNull(e.getMessage());
- assertTrue(
- e.getMessage().contains("The merged accumulator must be AverageAccumulator."));
- } catch (Throwable t) {
- fail(
- "wrong exception; expected IllegalArgumentException but found "
- + t.getClass().getName());
- }
+ assertThatThrownBy(() -> average.merge(averageNew))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("The merged accumulator must be AverageAccumulator.");
}
@Test
- public void testClone() {
+ void testClone() {
AverageAccumulator average = new AverageAccumulator();
average.add(1);
AverageAccumulator averageNew = average.clone();
- assertEquals(1, averageNew.getLocalValue(), 0.0);
+ assertThat(averageNew.getLocalValue()).isCloseTo(1, within(0.0));
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMaximumTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMaximumTest.java
index 338074d2bcc..b61d85bc662 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMaximumTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMaximumTest.java
@@ -18,32 +18,33 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.within;
-public class DoubleMaximumTest {
+class DoubleMaximumTest {
@Test
- public void testGet() {
+ void testGet() {
DoubleMaximum max = new DoubleMaximum();
- assertEquals(Double.NEGATIVE_INFINITY, max.getLocalValue(), 0.0);
+ assertThat(max.getLocalValue()).isCloseTo(Double.NEGATIVE_INFINITY, within(0.0));
}
@Test
- public void testResetLocal() {
+ void testResetLocal() {
DoubleMaximum max = new DoubleMaximum();
double value = 13.57902468;
max.add(value);
- assertEquals(value, max.getLocalValue(), 0.0);
+ assertThat(max.getLocalValue()).isCloseTo(value, within(0.0));
max.resetLocal();
- assertEquals(Double.NEGATIVE_INFINITY, max.getLocalValue(), 0.0);
+ assertThat(max.getLocalValue()).isCloseTo(Double.NEGATIVE_INFINITY, within(0.0));
}
@Test
- public void testAdd() {
+ void testAdd() {
DoubleMaximum max = new DoubleMaximum();
max.add(1234.5768);
@@ -51,11 +52,11 @@ public class DoubleMaximumTest {
max.add(-987.6543);
max.add(-123.4567);
- assertEquals(9876.5432, max.getLocalValue(), 0.0);
+ assertThat(max.getLocalValue()).isCloseTo(9876.5432, within(0.0));
}
@Test
- public void testMerge() {
+ void testMerge() {
DoubleMaximum max1 = new DoubleMaximum();
max1.add(1234.5768);
@@ -63,20 +64,20 @@ public class DoubleMaximumTest {
max2.add(5678.9012);
max2.merge(max1);
- assertEquals(5678.9012, max2.getLocalValue(), 0.0);
+ assertThat(max2.getLocalValue()).isCloseTo(5678.9012, within(0.0));
max1.merge(max2);
- assertEquals(5678.9012, max1.getLocalValue(), 0.0);
+ assertThat(max1.getLocalValue()).isCloseTo(5678.9012, within(0.0));
}
@Test
- public void testClone() {
+ void testClone() {
DoubleMaximum max = new DoubleMaximum();
double value = 3.14159265359;
max.add(value);
DoubleMaximum clone = max.clone();
- assertEquals(value, clone.getLocalValue(), 0.0);
+ assertThat(clone.getLocalValue()).isCloseTo(value, within(0.0));
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMinimumTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMinimumTest.java
index 2b988f1d13a..545dc70c50f 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMinimumTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/DoubleMinimumTest.java
@@ -18,32 +18,33 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.within;
-public class DoubleMinimumTest {
+class DoubleMinimumTest {
@Test
- public void testGet() {
+ void testGet() {
DoubleMinimum min = new DoubleMinimum();
- assertEquals(Double.POSITIVE_INFINITY, min.getLocalValue(), 0.0);
+ assertThat(min.getLocalValue()).isCloseTo(Double.POSITIVE_INFINITY, within(0.0));
}
@Test
- public void testResetLocal() {
+ void testResetLocal() {
DoubleMinimum min = new DoubleMinimum();
double value = 13.57902468;
min.add(value);
- assertEquals(value, min.getLocalValue(), 0.0);
+ assertThat(min.getLocalValue()).isCloseTo(value, within(0.0));
min.resetLocal();
- assertEquals(Double.POSITIVE_INFINITY, min.getLocalValue(), 0.0);
+ assertThat(min.getLocalValue()).isCloseTo(Double.POSITIVE_INFINITY, within(0.0));
}
@Test
- public void testAdd() {
+ void testAdd() {
DoubleMinimum min = new DoubleMinimum();
min.add(1234.5768);
@@ -51,11 +52,11 @@ public class DoubleMinimumTest {
min.add(-987.6543);
min.add(-123.4567);
- assertEquals(-987.6543, min.getLocalValue(), 0.0);
+ assertThat(min.getLocalValue()).isCloseTo(-987.6543, within(0.0));
}
@Test
- public void testMerge() {
+ void testMerge() {
DoubleMinimum min1 = new DoubleMinimum();
min1.add(1234.5768);
@@ -63,20 +64,20 @@ public class DoubleMinimumTest {
min2.add(5678.9012);
min2.merge(min1);
- assertEquals(1234.5768, min2.getLocalValue(), 0.0);
+ assertThat(min2.getLocalValue()).isCloseTo(1234.5768, within(0.0));
min1.merge(min2);
- assertEquals(1234.5768, min1.getLocalValue(), 0.0);
+ assertThat(min1.getLocalValue()).isCloseTo(1234.5768, within(0.0));
}
@Test
- public void testClone() {
+ void testClone() {
DoubleMinimum min = new DoubleMinimum();
double value = 3.14159265359;
min.add(value);
DoubleMinimum clone = min.clone();
- assertEquals(value, clone.getLocalValue(), 0.0);
+ assertThat(clone.getLocalValue()).isCloseTo(value, within(0.0));
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMaximumTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMaximumTest.java
index d4d5892a94c..c299719596f 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMaximumTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMaximumTest.java
@@ -18,32 +18,32 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
-public class IntMaximumTest {
+class IntMaximumTest {
@Test
- public void testGet() {
+ void testGet() {
IntMaximum max = new IntMaximum();
- assertEquals(Integer.MIN_VALUE, max.getLocalValue().intValue());
+ assertThat(max.getLocalValue().intValue()).isEqualTo(Integer.MIN_VALUE);
}
@Test
- public void testResetLocal() {
+ void testResetLocal() {
IntMaximum max = new IntMaximum();
int value = 13;
max.add(value);
- assertEquals(value, max.getLocalValue().intValue());
+ assertThat(max.getLocalValue().intValue()).isEqualTo(value);
max.resetLocal();
- assertEquals(Integer.MIN_VALUE, max.getLocalValue().intValue());
+ assertThat(max.getLocalValue().intValue()).isEqualTo(Integer.MIN_VALUE);
}
@Test
- public void testAdd() {
+ void testAdd() {
IntMaximum max = new IntMaximum();
max.add(1234);
@@ -51,11 +51,11 @@ public class IntMaximumTest {
max.add(-987);
max.add(-123);
- assertEquals(9876, max.getLocalValue().intValue());
+ assertThat(max.getLocalValue().intValue()).isEqualTo(9876);
}
@Test
- public void testMerge() {
+ void testMerge() {
IntMaximum max1 = new IntMaximum();
max1.add(1234);
@@ -63,20 +63,20 @@ public class IntMaximumTest {
max2.add(5678);
max2.merge(max1);
- assertEquals(5678, max2.getLocalValue().intValue());
+ assertThat(max2.getLocalValue().intValue()).isEqualTo(5678);
max1.merge(max2);
- assertEquals(5678, max1.getLocalValue().intValue());
+ assertThat(max1.getLocalValue().intValue()).isEqualTo(5678);
}
@Test
- public void testClone() {
+ void testClone() {
IntMaximum max = new IntMaximum();
int value = 42;
max.add(value);
IntMaximum clone = max.clone();
- assertEquals(value, clone.getLocalValue().intValue());
+ assertThat(clone.getLocalValue().intValue()).isEqualTo(value);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMinimumTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMinimumTest.java
index 1a282aba07e..9ad8dcbabf0 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMinimumTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/IntMinimumTest.java
@@ -18,32 +18,32 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
-public class IntMinimumTest {
+class IntMinimumTest {
@Test
- public void testGet() {
+ void testGet() {
IntMinimum min = new IntMinimum();
- assertEquals(Integer.MAX_VALUE, min.getLocalValue().intValue());
+ assertThat(min.getLocalValue().intValue()).isEqualTo(Integer.MAX_VALUE);
}
@Test
- public void testResetLocal() {
+ void testResetLocal() {
IntMinimum min = new IntMinimum();
int value = 13;
min.add(value);
- assertEquals(value, min.getLocalValue().intValue());
+ assertThat(min.getLocalValue().intValue()).isEqualTo(value);
min.resetLocal();
- assertEquals(Integer.MAX_VALUE, min.getLocalValue().intValue());
+ assertThat(min.getLocalValue().intValue()).isEqualTo(Integer.MAX_VALUE);
}
@Test
- public void testAdd() {
+ void testAdd() {
IntMinimum min = new IntMinimum();
min.add(1234);
@@ -51,11 +51,11 @@ public class IntMinimumTest {
min.add(-987);
min.add(-123);
- assertEquals(-987, min.getLocalValue().intValue());
+ assertThat(min.getLocalValue().intValue()).isEqualTo(-987);
}
@Test
- public void testMerge() {
+ void testMerge() {
IntMinimum min1 = new IntMinimum();
min1.add(1234);
@@ -63,20 +63,20 @@ public class IntMinimumTest {
min2.add(5678);
min2.merge(min1);
- assertEquals(1234, min2.getLocalValue().intValue());
+ assertThat(min2.getLocalValue().intValue()).isEqualTo(1234);
min1.merge(min2);
- assertEquals(1234, min1.getLocalValue().intValue());
+ assertThat(min1.getLocalValue().intValue()).isEqualTo(1234);
}
@Test
- public void testClone() {
+ void testClone() {
IntMinimum min = new IntMinimum();
int value = 42;
min.add(value);
IntMinimum clone = min.clone();
- assertEquals(value, clone.getLocalValue().intValue());
+ assertThat(clone.getLocalValue().intValue()).isEqualTo(value);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMaximumTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMaximumTest.java
index 77c9767de3c..c9a179b1c4a 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMaximumTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMaximumTest.java
@@ -18,32 +18,32 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
-public class LongMaximumTest {
+class LongMaximumTest {
@Test
- public void testGet() {
+ void testGet() {
LongMaximum max = new LongMaximum();
- assertEquals(Long.MIN_VALUE, max.getLocalValue().longValue());
+ assertThat(max.getLocalValue().longValue()).isEqualTo(Long.MIN_VALUE);
}
@Test
- public void testResetLocal() {
+ void testResetLocal() {
LongMaximum max = new LongMaximum();
long value = 9876543210L;
max.add(value);
- assertEquals(value, max.getLocalValue().longValue());
+ assertThat(max.getLocalValue().longValue()).isEqualTo(value);
max.resetLocal();
- assertEquals(Long.MIN_VALUE, max.getLocalValue().longValue());
+ assertThat(max.getLocalValue().longValue()).isEqualTo(Long.MIN_VALUE);
}
@Test
- public void testAdd() {
+ void testAdd() {
LongMaximum max = new LongMaximum();
max.add(1234567890);
@@ -51,11 +51,11 @@ public class LongMaximumTest {
max.add(-9876543210L);
max.add(-1234567890);
- assertEquals(9876543210L, max.getLocalValue().longValue());
+ assertThat(max.getLocalValue().longValue()).isEqualTo(9876543210L);
}
@Test
- public void testMerge() {
+ void testMerge() {
LongMaximum max1 = new LongMaximum();
max1.add(1234567890987654321L);
@@ -63,20 +63,20 @@ public class LongMaximumTest {
max2.add(5678909876543210123L);
max2.merge(max1);
- assertEquals(5678909876543210123L, max2.getLocalValue().longValue());
+ assertThat(max2.getLocalValue().longValue()).isEqualTo(5678909876543210123L);
max1.merge(max2);
- assertEquals(5678909876543210123L, max1.getLocalValue().longValue());
+ assertThat(max1.getLocalValue().longValue()).isEqualTo(5678909876543210123L);
}
@Test
- public void testClone() {
+ void testClone() {
LongMaximum max = new LongMaximum();
long value = 4242424242424242L;
max.add(value);
LongMaximum clone = max.clone();
- assertEquals(value, clone.getLocalValue().longValue());
+ assertThat(clone.getLocalValue().longValue()).isEqualTo(value);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMinimumTest.java b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMinimumTest.java
index 02c29f603fb..ad9fda8e58a 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMinimumTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/accumulators/LongMinimumTest.java
@@ -18,32 +18,32 @@
package org.apache.flink.api.common.accumulators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
-public class LongMinimumTest {
+class LongMinimumTest {
@Test
- public void testGet() {
+ void testGet() {
LongMinimum min = new LongMinimum();
- assertEquals(Long.MAX_VALUE, min.getLocalValue().longValue());
+ assertThat(min.getLocalValue().longValue()).isEqualTo(Long.MAX_VALUE);
}
@Test
- public void testResetLocal() {
+ void testResetLocal() {
LongMinimum min = new LongMinimum();
long value = 9876543210L;
min.add(value);
- assertEquals(value, min.getLocalValue().longValue());
+ assertThat(min.getLocalValue().longValue()).isEqualTo(value);
min.resetLocal();
- assertEquals(Long.MAX_VALUE, min.getLocalValue().longValue());
+ assertThat(min.getLocalValue().longValue()).isEqualTo(Long.MAX_VALUE);
}
@Test
- public void testAdd() {
+ void testAdd() {
LongMinimum min = new LongMinimum();
min.add(1234567890);
@@ -51,11 +51,11 @@ public class LongMinimumTest {
min.add(-9876543210L);
min.add(-1234567890);
- assertEquals(-9876543210L, min.getLocalValue().longValue());
+ assertThat(min.getLocalValue().longValue()).isEqualTo(-9876543210L);
}
@Test
- public void testMerge() {
+ void testMerge() {
LongMinimum min1 = new LongMinimum();
min1.add(1234567890987654321L);
@@ -63,20 +63,20 @@ public class LongMinimumTest {
min2.add(5678909876543210123L);
min2.merge(min1);
- assertEquals(1234567890987654321L, min2.getLocalValue().longValue());
+ assertThat(min2.getLocalValue().longValue()).isEqualTo(1234567890987654321L);
min1.merge(min2);
- assertEquals(1234567890987654321L, min1.getLocalValue().longValue());
+ assertThat(min1.getLocalValue().longValue()).isEqualTo(1234567890987654321L);
}
@Test
- public void testClone() {
+ void testClone() {
LongMinimum min = new LongMinimum();
long value = 4242424242424242L;
min.add(value);
LongMinimum clone = min.clone();
- assertEquals(value, clone.getLocalValue().longValue());
+ assertThat(clone.getLocalValue().longValue()).isEqualTo(value);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/AscendingTimestampsWatermarksTest.java b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/AscendingTimestampsWatermarksTest.java
index 327f3cc1846..f59e172810b 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/AscendingTimestampsWatermarksTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/AscendingTimestampsWatermarksTest.java
@@ -18,26 +18,26 @@
package org.apache.flink.api.common.eventtime;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the {@link AscendingTimestampsWatermarks} class. */
-public class AscendingTimestampsWatermarksTest {
+class AscendingTimestampsWatermarksTest {
@Test
- public void testWatermarkBeforeRecords() {
+ void testWatermarkBeforeRecords() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final AscendingTimestampsWatermarks<Object> watermarks =
new AscendingTimestampsWatermarks<>();
watermarks.onPeriodicEmit(output);
- assertEquals(Long.MIN_VALUE, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(Long.MIN_VALUE);
}
@Test
- public void testWatermarkAfterEvent() {
+ void testWatermarkAfterEvent() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final AscendingTimestampsWatermarks<Object> watermarks =
new AscendingTimestampsWatermarks<>();
@@ -45,11 +45,11 @@ public class AscendingTimestampsWatermarksTest {
watermarks.onEvent(new Object(), 1337L, output);
watermarks.onPeriodicEmit(output);
- assertEquals(1336L, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(1336L);
}
@Test
- public void testWatermarkAfterEventWithLowerTimestamp() {
+ void testWatermarkAfterEventWithLowerTimestamp() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final AscendingTimestampsWatermarks<Object> watermarks =
new AscendingTimestampsWatermarks<>();
@@ -58,6 +58,6 @@ public class AscendingTimestampsWatermarksTest {
watermarks.onEvent(new Object(), 12340L, output);
watermarks.onPeriodicEmit(output);
- assertEquals(12344L, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(12344L);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/BoundedOutOfOrdernessWatermarksTest.java b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/BoundedOutOfOrdernessWatermarksTest.java
index a3a32924de6..5e1a19d8390 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/BoundedOutOfOrdernessWatermarksTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/BoundedOutOfOrdernessWatermarksTest.java
@@ -18,30 +18,29 @@
package org.apache.flink.api.common.eventtime;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Duration;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the {@link AscendingTimestampsWatermarks} class. */
-public class BoundedOutOfOrdernessWatermarksTest {
+class BoundedOutOfOrdernessWatermarksTest {
@Test
- public void testWatermarkBeforeRecords() {
+ void testWatermarkBeforeRecords() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final BoundedOutOfOrdernessWatermarks<Object> watermarks =
new BoundedOutOfOrdernessWatermarks<>(Duration.ofMillis(10));
watermarks.onPeriodicEmit(output);
- assertNotNull(output.lastWatermark());
- assertEquals(Long.MIN_VALUE, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark()).isNotNull();
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(Long.MIN_VALUE);
}
@Test
- public void testWatermarkAfterEvent() {
+ void testWatermarkAfterEvent() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final BoundedOutOfOrdernessWatermarks<Object> watermarks =
new BoundedOutOfOrdernessWatermarks<>(Duration.ofMillis(10));
@@ -49,11 +48,11 @@ public class BoundedOutOfOrdernessWatermarksTest {
watermarks.onEvent(new Object(), 1337L, output);
watermarks.onPeriodicEmit(output);
- assertEquals(1326L, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(1326L);
}
@Test
- public void testWatermarkAfterNonMonotonousEvents() {
+ void testWatermarkAfterNonMonotonousEvents() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final BoundedOutOfOrdernessWatermarks<Object> watermarks =
new BoundedOutOfOrdernessWatermarks<>(Duration.ofMillis(10));
@@ -64,11 +63,11 @@ public class BoundedOutOfOrdernessWatermarksTest {
watermarks.onEvent(new Object(), 12280L, output);
watermarks.onPeriodicEmit(output);
- assertEquals(12334L, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(12334L);
}
@Test
- public void testRepeatedProbe() {
+ void testRepeatedProbe() {
final TestingWatermarkOutput output = new TestingWatermarkOutput();
final BoundedOutOfOrdernessWatermarks<Object> watermarks =
new BoundedOutOfOrdernessWatermarks<>(Duration.ofMillis(10));
@@ -78,6 +77,6 @@ public class BoundedOutOfOrdernessWatermarksTest {
watermarks.onPeriodicEmit(output);
- assertEquals(723445L, output.lastWatermark().getTimestamp());
+ assertThat(output.lastWatermark().getTimestamp()).isEqualTo(723445L);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkMatchers.java b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkMatchers.java
deleted file mode 100644
index 576ee4d22ec..00000000000
--- a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkMatchers.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.flink.api.common.eventtime;
-
-import org.hamcrest.FeatureMatcher;
-import org.hamcrest.Matcher;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-
-/** Matchers for {@link Watermark}. */
-public class WatermarkMatchers {
-
- /** Creates a matcher that matches when the examined watermark has the given timestamp. */
- public static Matcher<Watermark> watermark(long timestamp) {
- return new FeatureMatcher<Watermark, Long>(
- equalTo(timestamp), "a watermark with value", "value of watermark") {
- @Override
- protected Long featureValueOf(Watermark actual) {
- return actual.getTimestamp();
- }
- };
- }
-
- private WatermarkMatchers() {}
-}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkOutputMultiplexerTest.java b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkOutputMultiplexerTest.java
index c6bd29a0e16..a5dae3d5e79 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkOutputMultiplexerTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkOutputMultiplexerTest.java
@@ -18,24 +18,17 @@
package org.apache.flink.api.common.eventtime;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.UUID;
-import static org.apache.flink.api.common.eventtime.WatermarkMatchers.watermark;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the {@link WatermarkOutputMultiplexer}. */
-public class WatermarkOutputMultiplexerTest {
+class WatermarkOutputMultiplexerTest {
@Test
- public void singleImmediateWatermark() {
+ void singleImmediateWatermark() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -44,12 +37,12 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput.emitWatermark(new Watermark(0));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(0)));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(0));
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void singleImmediateIdleness() {
+ void singleImmediateIdleness() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -58,12 +51,12 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput.markIdle();
- assertThat(underlyingWatermarkOutput.lastWatermark(), nullValue());
- assertThat(underlyingWatermarkOutput.isIdle(), is(true));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isNull();
+ assertThat(underlyingWatermarkOutput.isIdle()).isTrue();
}
@Test
- public void singleImmediateWatermarkAfterIdleness() {
+ void singleImmediateWatermarkAfterIdleness() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -71,16 +64,16 @@ public class WatermarkOutputMultiplexerTest {
WatermarkOutput watermarkOutput = createImmediateOutput(multiplexer);
watermarkOutput.markIdle();
- assertThat(underlyingWatermarkOutput.isIdle(), is(true));
+ assertThat(underlyingWatermarkOutput.isIdle()).isTrue();
watermarkOutput.emitWatermark(new Watermark(0));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(0)));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(0));
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void multipleImmediateWatermark() {
+ void multipleImmediateWatermark() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -93,12 +86,12 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput2.emitWatermark(new Watermark(5));
watermarkOutput3.markIdle();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(2)));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(2));
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void whenImmediateOutputBecomesIdleWatermarkAdvances() {
+ void whenImmediateOutputBecomesIdleWatermarkAdvances() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -109,15 +102,15 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput1.emitWatermark(new Watermark(2));
watermarkOutput2.emitWatermark(new Watermark(5));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(2)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(2));
watermarkOutput1.markIdle();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(5)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(5));
}
@Test
- public void combinedWatermarkDoesNotRegressWhenIdleOutputRegresses() {
+ void combinedWatermarkDoesNotRegressWhenIdleOutputRegresses() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -129,11 +122,11 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput2.emitWatermark(new Watermark(5));
watermarkOutput1.markIdle();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(5)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(5));
watermarkOutput1.emitWatermark(new Watermark(3));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(5)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(5));
}
/**
@@ -145,19 +138,19 @@ public class WatermarkOutputMultiplexerTest {
* when there are no splits assigned and the combined watermark is at its initial value.
*/
@Test
- public void noCombinedDeferredUpdateWhenWeHaveZeroOutputs() {
+ void noCombinedDeferredUpdateWhenWeHaveZeroOutputs() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(nullValue()));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isNull();
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void deferredOutputDoesNotImmediatelyAdvanceWatermark() {
+ void deferredOutputDoesNotImmediatelyAdvanceWatermark() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -168,15 +161,15 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput1.emitWatermark(new Watermark(0));
watermarkOutput2.emitWatermark(new Watermark(1));
- assertThat(underlyingWatermarkOutput.lastWatermark(), nullValue());
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isNull();
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(0)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(0));
}
@Test
- public void singleDeferredWatermark() {
+ void singleDeferredWatermark() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -186,12 +179,12 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput.emitWatermark(new Watermark(0));
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(0)));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(0));
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void singleDeferredIdleness() {
+ void singleDeferredIdleness() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -201,12 +194,12 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput.markIdle();
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), nullValue());
- assertThat(underlyingWatermarkOutput.isIdle(), is(true));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isNull();
+ assertThat(underlyingWatermarkOutput.isIdle()).isTrue();
}
@Test
- public void singleDeferredWatermarkAfterIdleness() {
+ void singleDeferredWatermarkAfterIdleness() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -216,17 +209,17 @@ public class WatermarkOutputMultiplexerTest {
watermarkOutput.markIdle();
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.isIdle(), is(true));
+ assertThat(underlyingWatermarkOutput.isIdle()).isTrue();
watermarkOutput.emitWatermark(new Watermark(0));
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(0)));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(0));
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void multipleDeferredWatermark() {
+ void multipleDeferredWatermark() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -241,12 +234,12 @@ public class WatermarkOutputMultiplexerTest {
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(2)));
- assertThat(underlyingWatermarkOutput.isIdle(), is(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(2));
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
@Test
- public void immediateUpdatesTakeDeferredUpdatesIntoAccount() {
+ void immediateUpdatesTakeDeferredUpdatesIntoAccount() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -256,15 +249,15 @@ public class WatermarkOutputMultiplexerTest {
deferredOutput.emitWatermark(new Watermark(5));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(nullValue()));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isNull();
immediateOutput.emitWatermark(new Watermark(2));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(2)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(2));
}
@Test
- public void immediateUpdateOnSameOutputAsDeferredUpdateDoesNotRegress() {
+ void immediateUpdateOnSameOutputAsDeferredUpdateDoesNotRegress() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -277,18 +270,18 @@ public class WatermarkOutputMultiplexerTest {
deferredOutput.emitWatermark(new Watermark(5));
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(5)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(5));
immediateOutput.emitWatermark(new Watermark(2));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(5)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(5));
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(watermark(5)));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(new Watermark(5));
}
@Test
- public void lowerImmediateUpdateOnSameOutputDoesNotEmitCombinedUpdate() {
+ void lowerImmediateUpdateOnSameOutputDoesNotEmitCombinedUpdate() {
TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -301,11 +294,11 @@ public class WatermarkOutputMultiplexerTest {
deferredOutput.emitWatermark(new Watermark(5));
immediateOutput.emitWatermark(new Watermark(2));
- assertThat(underlyingWatermarkOutput.lastWatermark(), is(nullValue()));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isNull();
}
@Test
- public void testRemoveUnblocksWatermarks() {
+ void testRemoveUnblocksWatermarks() {
final TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
final WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -319,11 +312,12 @@ public class WatermarkOutputMultiplexerTest {
multiplexer.unregisterOutput("lower");
multiplexer.getImmediateOutput("higher").emitWatermark(new Watermark(highTimestamp));
- assertEquals(highTimestamp, underlyingWatermarkOutput.lastWatermark().getTimestamp());
+ assertThat(underlyingWatermarkOutput.lastWatermark().getTimestamp())
+ .isEqualTo(highTimestamp);
}
@Test
- public void testRemoveOfLowestDoesNotImmediatelyAdvanceWatermark() {
+ void testRemoveOfLowestDoesNotImmediatelyAdvanceWatermark() {
final TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
final WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -337,11 +331,12 @@ public class WatermarkOutputMultiplexerTest {
multiplexer.unregisterOutput("lower");
- assertEquals(lowTimestamp, underlyingWatermarkOutput.lastWatermark().getTimestamp());
+ assertThat(underlyingWatermarkOutput.lastWatermark().getTimestamp())
+ .isEqualTo(lowTimestamp);
}
@Test
- public void testRemoveOfHighestDoesNotRetractWatermark() {
+ void testRemoveOfHighestDoesNotRetractWatermark() {
final TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
final WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -355,11 +350,12 @@ public class WatermarkOutputMultiplexerTest {
multiplexer.registerNewOutput("lower", watermark -> {});
multiplexer.getImmediateOutput("lower").emitWatermark(new Watermark(lowTimestamp));
- assertEquals(highTimestamp, underlyingWatermarkOutput.lastWatermark().getTimestamp());
+ assertThat(underlyingWatermarkOutput.lastWatermark().getTimestamp())
+ .isEqualTo(highTimestamp);
}
@Test
- public void testRemoveRegisteredReturnValue() {
+ void testRemoveRegisteredReturnValue() {
final TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
final WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -367,22 +363,22 @@ public class WatermarkOutputMultiplexerTest {
final boolean unregistered = multiplexer.unregisterOutput("does-exist");
- assertTrue(unregistered);
+ assertThat(unregistered).isTrue();
}
@Test
- public void testRemoveNotRegisteredReturnValue() {
+ void testRemoveNotRegisteredReturnValue() {
final TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
final WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
final boolean unregistered = multiplexer.unregisterOutput("does-not-exist");
- assertFalse(unregistered);
+ assertThat(unregistered).isFalse();
}
@Test
- public void testNotEmittingIdleAfterAllSplitsRemoved() {
+ void testNotEmittingIdleAfterAllSplitsRemoved() {
final TestingWatermarkOutput underlyingWatermarkOutput = createTestingWatermarkOutput();
final WatermarkOutputMultiplexer multiplexer =
new WatermarkOutputMultiplexer(underlyingWatermarkOutput);
@@ -395,8 +391,8 @@ public class WatermarkOutputMultiplexerTest {
multiplexer.unregisterOutput(id);
multiplexer.onPeriodicEmit();
- assertThat(underlyingWatermarkOutput.lastWatermark(), equalTo(emittedWatermark));
- assertThat(underlyingWatermarkOutput.isIdle(), equalTo(false));
+ assertThat(underlyingWatermarkOutput.lastWatermark()).isEqualTo(emittedWatermark);
+ assertThat(underlyingWatermarkOutput.isIdle()).isFalse();
}
/**
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkStrategyTest.java b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkStrategyTest.java
index df9d24853d8..b76252e2e2d 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkStrategyTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarkStrategyTest.java
@@ -27,113 +27,104 @@ import org.apache.flink.metrics.Histogram;
import org.apache.flink.metrics.Meter;
import org.apache.flink.metrics.MetricGroup;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.time.Duration;
import java.util.Map;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for the {@link WatermarkStrategy} class. */
public class WatermarkStrategyTest {
@Test
- public void testDefaultTimeStampAssigner() {
+ void testDefaultTimeStampAssigner() {
WatermarkStrategy<Object> wmStrategy = WatermarkStrategy.forMonotonousTimestamps();
- // ensure that the closure can be cleaned through the WatermarkStategies
+ // ensure that the closure can be cleaned through the Watermark Strategies
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
- assertThat(
- wmStrategy.createTimestampAssigner(assignerContext()),
- instanceOf(RecordTimestampAssigner.class));
+ assertThat(wmStrategy.createTimestampAssigner(assignerContext()))
+ .isInstanceOf(RecordTimestampAssigner.class);
}
@Test
- public void testLambdaTimestampAssigner() {
+ void testLambdaTimestampAssigner() {
WatermarkStrategy<Object> wmStrategy =
WatermarkStrategy.forMonotonousTimestamps()
.withTimestampAssigner((event, timestamp) -> 42L);
- // ensure that the closure can be cleaned through the WatermarkStategies
+ // ensure that the closure can be cleaned through the Watermark Strategies
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
TimestampAssigner<Object> timestampAssigner =
wmStrategy.createTimestampAssigner(assignerContext());
- assertThat(timestampAssigner.extractTimestamp(null, 13L), is(42L));
+ assertThat(timestampAssigner.extractTimestamp(null, 13L)).isEqualTo(42L);
}
@Test
- public void testLambdaTimestampAssignerSupplier() {
+ void testLambdaTimestampAssignerSupplier() {
WatermarkStrategy<Object> wmStrategy =
WatermarkStrategy.forMonotonousTimestamps()
.withTimestampAssigner(
TimestampAssignerSupplier.of((event, timestamp) -> 42L));
- // ensure that the closure can be cleaned through the WatermarkStategies
+ // ensure that the closure can be cleaned through the Watermark Strategies
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
TimestampAssigner<Object> timestampAssigner =
wmStrategy.createTimestampAssigner(assignerContext());
- assertThat(timestampAssigner.extractTimestamp(null, 13L), is(42L));
+ assertThat(timestampAssigner.extractTimestamp(null, 13L)).isEqualTo(42L);
}
@Test
- public void testAnonymousInnerTimestampAssigner() {
+ void testAnonymousInnerTimestampAssigner() {
WatermarkStrategy<Object> wmStrategy =
WatermarkStrategy.forMonotonousTimestamps()
.withTimestampAssigner(
- new SerializableTimestampAssigner<Object>() {
- @Override
- public long extractTimestamp(
- Object element, long recordTimestamp) {
- return 42;
- }
- });
- // ensure that the closure can be cleaned through the WatermarkStategies
+ (SerializableTimestampAssigner<Object>)
+ (element, recordTimestamp) -> 42);
+ // ensure that the closure can be cleaned through the Watermark Strategies
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
TimestampAssigner<Object> timestampAssigner =
wmStrategy.createTimestampAssigner(assignerContext());
- assertThat(timestampAssigner.extractTimestamp(null, 13L), is(42L));
+ assertThat(timestampAssigner.extractTimestamp(null, 13L)).isEqualTo(42L);
}
@Test
- public void testClassTimestampAssigner() {
+ void testClassTimestampAssigner() {
WatermarkStrategy<Object> wmStrategy =
WatermarkStrategy.forMonotonousTimestamps()
.withTimestampAssigner((ctx) -> new TestTimestampAssigner());
- // ensure that the closure can be cleaned through the WatermarkStategies
+ // ensure that the closure can be cleaned through the Watermark Strategies
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
TimestampAssigner<Object> timestampAssigner =
wmStrategy.createTimestampAssigner(assignerContext());
- assertThat(timestampAssigner.extractTimestamp(null, 13L), is(42L));
+ assertThat(timestampAssigner.extractTimestamp(null, 13L)).isEqualTo(42L);
}
@Test
- public void testClassTimestampAssignerUsingSupplier() {
+ void testClassTimestampAssignerUsingSupplier() {
WatermarkStrategy<Object> wmStrategy =
WatermarkStrategy.forMonotonousTimestamps()
.withTimestampAssigner((context) -> new TestTimestampAssigner());
- // ensure that the closure can be cleaned through the WatermarkStategies
+ // ensure that the closure can be cleaned through the Watermark Strategies
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
TimestampAssigner<Object> timestampAssigner =
wmStrategy.createTimestampAssigner(assignerContext());
- assertThat(timestampAssigner.extractTimestamp(null, 13L), is(42L));
+ assertThat(timestampAssigner.extractTimestamp(null, 13L)).isEqualTo(42L);
}
@Test
- public void testWithIdlenessHelper() {
+ void testWithIdlenessHelper() {
WatermarkStrategy<String> wmStrategy =
WatermarkStrategy.<String>forMonotonousTimestamps()
.withIdleness(Duration.ofDays(7));
@@ -141,16 +132,14 @@ public class WatermarkStrategyTest {
// ensure that the closure can be cleaned
ClosureCleaner.clean(wmStrategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
- assertThat(
- wmStrategy.createTimestampAssigner(assignerContext()),
- instanceOf(RecordTimestampAssigner.class));
- assertThat(
- wmStrategy.createWatermarkGenerator(generatorContext()),
- instanceOf(WatermarksWithIdleness.class));
+ assertThat(wmStrategy.createTimestampAssigner(assignerContext()))
+ .isInstanceOf(RecordTimestampAssigner.class);
+ assertThat(wmStrategy.createWatermarkGenerator(generatorContext()))
+ .isInstanceOf(WatermarksWithIdleness.class);
}
@Test
- public void testWithWatermarkAlignment() {
+ void testWithWatermarkAlignment() {
final String watermarkGroup = "group-1";
final Duration maxAllowedWatermarkDrift = Duration.ofMillis(200);
final WatermarkStrategy<String> strategy =
@@ -164,19 +153,15 @@ public class WatermarkStrategyTest {
ClosureCleaner.clean(strategy, ExecutionConfig.ClosureCleanerLevel.RECURSIVE, true);
final WatermarkAlignmentParams alignmentParameters = strategy.getAlignmentParameters();
- assertThat(alignmentParameters.getWatermarkGroup(), equalTo(watermarkGroup));
- assertThat(
- alignmentParameters.getMaxAllowedWatermarkDrift(),
- equalTo(maxAllowedWatermarkDrift.toMillis()));
- assertThat(
- alignmentParameters.getUpdateInterval(),
- equalTo(WatermarksWithWatermarkAlignment.DEFAULT_UPDATE_INTERVAL.toMillis()));
- assertThat(
- strategy.createTimestampAssigner(assignerContext()),
- instanceOf(RecordTimestampAssigner.class));
- assertThat(
- strategy.createWatermarkGenerator(generatorContext()),
- instanceOf(WatermarksWithIdleness.class));
+ assertThat(alignmentParameters.getWatermarkGroup()).isEqualTo(watermarkGroup);
+ assertThat(alignmentParameters.getMaxAllowedWatermarkDrift())
+ .isEqualTo(maxAllowedWatermarkDrift.toMillis());
+ assertThat(alignmentParameters.getUpdateInterval())
+ .isEqualTo(WatermarksWithWatermarkAlignment.DEFAULT_UPDATE_INTERVAL.toMillis());
+ assertThat(strategy.createTimestampAssigner(assignerContext()))
+ .isInstanceOf(RecordTimestampAssigner.class);
+ assertThat(strategy.createWatermarkGenerator(generatorContext()))
+ .isInstanceOf(WatermarksWithIdleness.class);
}
static class TestTimestampAssigner implements TimestampAssigner<Object>, Serializable {
@@ -188,21 +173,11 @@ public class WatermarkStrategyTest {
}
static TimestampAssignerSupplier.Context assignerContext() {
- return new TimestampAssignerSupplier.Context() {
- @Override
- public MetricGroup getMetricGroup() {
- return new DummyMetricGroup();
- }
- };
+ return DummyMetricGroup::new;
}
static WatermarkGeneratorSupplier.Context generatorContext() {
- return new WatermarkGeneratorSupplier.Context() {
- @Override
- public MetricGroup getMetricGroup() {
- return new DummyMetricGroup();
- }
- };
+ return DummyMetricGroup::new;
}
/**
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarksWithIdlenessTest.java b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarksWithIdlenessTest.java
index a9b6ab28389..6c2e4f8a54e 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarksWithIdlenessTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/eventtime/WatermarksWithIdlenessTest.java
@@ -21,77 +21,86 @@ package org.apache.flink.api.common.eventtime;
import org.apache.flink.api.common.eventtime.WatermarksWithIdleness.IdlenessTimer;
import org.apache.flink.util.clock.ManualClock;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Duration;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Test for the {@link WatermarksWithIdleness} class. */
-public class WatermarksWithIdlenessTest {
+class WatermarksWithIdlenessTest {
- @Test(expected = IllegalArgumentException.class)
- public void testZeroTimeout() {
- new WatermarksWithIdleness<>(new AscendingTimestampsWatermarks<>(), Duration.ZERO);
+ @Test
+ void testZeroTimeout() {
+ assertThatThrownBy(
+ () ->
+ new WatermarksWithIdleness<>(
+ new AscendingTimestampsWatermarks<>(), Duration.ZERO))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNegativeTimeout() {
- new WatermarksWithIdleness<>(new AscendingTimestampsWatermarks<>(), Duration.ofMillis(-1L));
+ @Test
+ void testNegativeTimeout() {
+ assertThatThrownBy(
+ () ->
+ new WatermarksWithIdleness<>(
+ new AscendingTimestampsWatermarks<>(),
+ Duration.ofMillis(-1L)))
+ .isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testInitiallyActive() {
+ void testInitiallyActive() {
final ManualClock clock = new ManualClock(System.nanoTime());
final IdlenessTimer timer = new IdlenessTimer(clock, Duration.ofMillis(10));
- assertFalse(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isFalse();
}
@Test
- public void testIdleWithoutEvents() {
+ void testIdleWithoutEvents() {
final ManualClock clock = new ManualClock(System.nanoTime());
final IdlenessTimer timer = new IdlenessTimer(clock, Duration.ofMillis(10));
timer.checkIfIdle(); // start timer
clock.advanceTime(11, MILLISECONDS);
- assertTrue(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isTrue();
}
@Test
- public void testRepeatedIdleChecks() {
+ void testRepeatedIdleChecks() {
final ManualClock clock = new ManualClock(System.nanoTime());
final IdlenessTimer timer = createTimerAndMakeIdle(clock, Duration.ofMillis(122));
- assertTrue(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isTrue();
clock.advanceTime(100, MILLISECONDS);
- assertTrue(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isTrue();
}
@Test
- public void testActiveAfterIdleness() {
+ void testActiveAfterIdleness() {
final ManualClock clock = new ManualClock(System.nanoTime());
final IdlenessTimer timer = createTimerAndMakeIdle(clock, Duration.ofMillis(10));
timer.activity();
- assertFalse(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isFalse();
}
@Test
- public void testIdleActiveIdle() {
+ void testIdleActiveIdle() {
final ManualClock clock = new ManualClock(System.nanoTime());
final IdlenessTimer timer = createTimerAndMakeIdle(clock, Duration.ofMillis(122));
// active again
timer.activity();
- assertFalse(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isFalse();
// idle again
timer.checkIfIdle(); // start timer
clock.advanceTime(Duration.ofMillis(123));
- assertTrue(timer.checkIfIdle());
+ assertThat(timer.checkIfIdle()).isTrue();
}
private static IdlenessTimer createTimerAndMakeIdle(ManualClock clock, Duration idleTimeout) {
@@ -99,7 +108,7 @@ public class WatermarksWithIdlenessTest {
timer.checkIfIdle(); // start timer
clock.advanceTime(Duration.ofMillis(idleTimeout.toMillis() + 1));
- assertTrue(timer.checkIfIdle()); // rigger timer
+ assertThat(timer.checkIfIdle()).isTrue(); // rigger timer
return timer;
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/functions/util/RuntimeUDFContextTest.java b/flink-core/src/test/java/org/apache/flink/api/common/functions/util/RuntimeUDFContextTest.java
index 3b43f6f4fc7..d181153dd3c 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/functions/util/RuntimeUDFContextTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/functions/util/RuntimeUDFContextTest.java
@@ -24,200 +24,156 @@ import org.apache.flink.api.common.TaskInfoImpl;
import org.apache.flink.api.common.functions.BroadcastVariableInitializer;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Test for the {@link RuntimeUDFContext}. */
-public class RuntimeUDFContextTest {
+class RuntimeUDFContextTest {
private final TaskInfo taskInfo = new TaskInfoImpl("test name", 3, 1, 3, 0);
@Test
- public void testBroadcastVariableNotFound() {
- try {
- RuntimeUDFContext ctx =
- new RuntimeUDFContext(
- taskInfo,
- getClass().getClassLoader(),
- new ExecutionConfig(),
- new HashMap<>(),
- new HashMap<>(),
- UnregisteredMetricsGroup.createOperatorMetricGroup());
-
- assertFalse(ctx.hasBroadcastVariable("some name"));
-
- try {
- ctx.getBroadcastVariable("some name");
- fail("should throw an exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- ctx.getBroadcastVariableWithInitializer(
- "some name",
- new BroadcastVariableInitializer<Object, Object>() {
- public Object initializeBroadcastVariable(Iterable<Object> data) {
- return null;
- }
- });
-
- fail("should throw an exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testBroadcastVariableNotFound() {
+ RuntimeUDFContext ctx =
+ new RuntimeUDFContext(
+ taskInfo,
+ getClass().getClassLoader(),
+ new ExecutionConfig(),
+ new HashMap<>(),
+ new HashMap<>(),
+ UnregisteredMetricsGroup.createOperatorMetricGroup());
+
+ assertThat(ctx.hasBroadcastVariable("some name")).isFalse();
+
+ assertThatThrownBy(() -> ctx.getBroadcastVariable("some name"))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("some name");
+
+ assertThatThrownBy(() -> ctx.getBroadcastVariableWithInitializer("some name", data -> null))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("some name");
}
@Test
- public void testBroadcastVariableSimple() {
- try {
- RuntimeUDFContext ctx =
- new RuntimeUDFContext(
- taskInfo,
- getClass().getClassLoader(),
- new ExecutionConfig(),
- new HashMap<>(),
- new HashMap<>(),
- UnregisteredMetricsGroup.createOperatorMetricGroup());
-
- ctx.setBroadcastVariable("name1", Arrays.asList(1, 2, 3, 4));
- ctx.setBroadcastVariable("name2", Arrays.asList(1.0, 2.0, 3.0, 4.0));
-
- assertTrue(ctx.hasBroadcastVariable("name1"));
- assertTrue(ctx.hasBroadcastVariable("name2"));
-
- List<Integer> list1 = ctx.getBroadcastVariable("name1");
- List<Double> list2 = ctx.getBroadcastVariable("name2");
-
- assertEquals(Arrays.asList(1, 2, 3, 4), list1);
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list2);
-
- // access again
- List<Integer> list3 = ctx.getBroadcastVariable("name1");
- List<Double> list4 = ctx.getBroadcastVariable("name2");
-
- assertEquals(Arrays.asList(1, 2, 3, 4), list3);
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list4);
-
- // and again ;-)
- List<Integer> list5 = ctx.getBroadcastVariable("name1");
- List<Double> list6 = ctx.getBroadcastVariable("name2");
-
- assertEquals(Arrays.asList(1, 2, 3, 4), list5);
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list6);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testBroadcastVariableSimple() {
+ RuntimeUDFContext ctx =
+ new RuntimeUDFContext(
+ taskInfo,
+ getClass().getClassLoader(),
+ new ExecutionConfig(),
+ new HashMap<>(),
+ new HashMap<>(),
+ UnregisteredMetricsGroup.createOperatorMetricGroup());
+
+ ctx.setBroadcastVariable("name1", Arrays.asList(1, 2, 3, 4));
+ ctx.setBroadcastVariable("name2", Arrays.asList(1.0, 2.0, 3.0, 4.0));
+
+ assertThat(ctx.hasBroadcastVariable("name1")).isTrue();
+ assertThat(ctx.hasBroadcastVariable("name2")).isTrue();
+
+ List<Integer> list1 = ctx.getBroadcastVariable("name1");
+ List<Double> list2 = ctx.getBroadcastVariable("name2");
+
+ assertThat(list1).isEqualTo(Arrays.asList(1, 2, 3, 4));
+ assertThat(list2).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+
+ // access again
+ List<Integer> list3 = ctx.getBroadcastVariable("name1");
+ List<Double> list4 = ctx.getBroadcastVariable("name2");
+
+ assertThat(list3).isEqualTo(Arrays.asList(1, 2, 3, 4));
+ assertThat(list4).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+
+ // and again ;-)
+ List<Integer> list5 = ctx.getBroadcastVariable("name1");
+ List<Double> list6 = ctx.getBroadcastVariable("name2");
+
+ assertThat(list5).isEqualTo(Arrays.asList(1, 2, 3, 4));
+ assertThat(list6).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
}
@Test
- public void testBroadcastVariableWithInitializer() {
- try {
- RuntimeUDFContext ctx =
- new RuntimeUDFContext(
- taskInfo,
- getClass().getClassLoader(),
- new ExecutionConfig(),
- new HashMap<>(),
- new HashMap<>(),
- UnregisteredMetricsGroup.createOperatorMetricGroup());
-
- ctx.setBroadcastVariable("name", Arrays.asList(1, 2, 3, 4));
-
- // access it the first time with an initializer
- List<Double> list =
- ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list);
-
- // access it the second time with an initializer (which might not get executed)
- List<Double> list2 =
- ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list2);
-
- // access it the third time without an initializer (should work by "chance", because the
- // result is a list)
- List<Double> list3 = ctx.getBroadcastVariable("name");
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list3);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testBroadcastVariableWithInitializer() {
+ RuntimeUDFContext ctx =
+ new RuntimeUDFContext(
+ taskInfo,
+ getClass().getClassLoader(),
+ new ExecutionConfig(),
+ new HashMap<>(),
+ new HashMap<>(),
+ UnregisteredMetricsGroup.createOperatorMetricGroup());
+
+ ctx.setBroadcastVariable("name", Arrays.asList(1, 2, 3, 4));
+
+ // access it the first time with an initializer
+ List<Double> list =
+ ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
+ assertThat(list).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+
+ // access it the second time with an initializer (which might not get executed)
+ List<Double> list2 =
+ ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
+ assertThat(list2).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+
+ // access it the third time without an initializer (should work by "chance", because the
+ // result is a list)
+ List<Double> list3 = ctx.getBroadcastVariable("name");
+ assertThat(list3).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
}
@Test
- public void testResetBroadcastVariableWithInitializer() {
- try {
- RuntimeUDFContext ctx =
- new RuntimeUDFContext(
- taskInfo,
- getClass().getClassLoader(),
- new ExecutionConfig(),
- new HashMap<>(),
- new HashMap<>(),
- UnregisteredMetricsGroup.createOperatorMetricGroup());
-
- ctx.setBroadcastVariable("name", Arrays.asList(1, 2, 3, 4));
-
- // access it the first time with an initializer
- List<Double> list =
- ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
- assertEquals(Arrays.asList(1.0, 2.0, 3.0, 4.0), list);
-
- // set it again to something different
- ctx.setBroadcastVariable("name", Arrays.asList(2, 3, 4, 5));
-
- List<Double> list2 =
- ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
- assertEquals(Arrays.asList(2.0, 3.0, 4.0, 5.0), list2);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testResetBroadcastVariableWithInitializer() {
+ RuntimeUDFContext ctx =
+ new RuntimeUDFContext(
+ taskInfo,
+ getClass().getClassLoader(),
+ new ExecutionConfig(),
+ new HashMap<>(),
+ new HashMap<>(),
+ UnregisteredMetricsGroup.createOperatorMetricGroup());
+
+ ctx.setBroadcastVariable("name", Arrays.asList(1, 2, 3, 4));
+
+ // access it the first time with an initializer
+ List<Double> list =
+ ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
+ assertThat(list).isEqualTo(Arrays.asList(1.0, 2.0, 3.0, 4.0));
+
+ // set it again to something different
+ ctx.setBroadcastVariable("name", Arrays.asList(2, 3, 4, 5));
+
+ List<Double> list2 =
+ ctx.getBroadcastVariableWithInitializer("name", new ConvertingInitializer());
+ assertThat(list2).isEqualTo(Arrays.asList(2.0, 3.0, 4.0, 5.0));
}
@Test
- public void testBroadcastVariableWithInitializerAndMismatch() {
- try {
- RuntimeUDFContext ctx =
- new RuntimeUDFContext(
- taskInfo,
- getClass().getClassLoader(),
- new ExecutionConfig(),
- new HashMap<>(),
- new HashMap<>(),
- UnregisteredMetricsGroup.createOperatorMetricGroup());
-
- ctx.setBroadcastVariable("name", Arrays.asList(1, 2, 3, 4));
-
- // access it the first time with an initializer
- int sum = ctx.getBroadcastVariableWithInitializer("name", new SumInitializer());
- assertEquals(10, sum);
-
- // access it the second time with no initializer -> should fail due to type mismatch
- try {
- ctx.getBroadcastVariable("name");
- fail("should throw an exception");
- } catch (IllegalStateException e) {
- // expected
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testBroadcastVariableWithInitializerAndMismatch() {
+ RuntimeUDFContext ctx =
+ new RuntimeUDFContext(
+ taskInfo,
+ getClass().getClassLoader(),
+ new ExecutionConfig(),
+ new HashMap<>(),
+ new HashMap<>(),
+ UnregisteredMetricsGroup.createOperatorMetricGroup());
+
+ ctx.setBroadcastVariable("name", Arrays.asList(1, 2, 3, 4));
+
+ // access it the first time with an initializer
+ int sum = ctx.getBroadcastVariableWithInitializer("name", new SumInitializer());
+ assertThat(sum).isEqualTo(10);
+
+ // access it the second time with no initializer -> should fail due to type mismatch
+ assertThatThrownBy(() -> ctx.getBroadcastVariable("name"))
+ .isInstanceOf(IllegalStateException.class);
}
// --------------------------------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java
index 7de496606ae..ab4791f88f2 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/BinaryInputFormatTest.java
@@ -22,22 +22,23 @@ import org.apache.flink.api.common.io.statistics.BaseStatistics;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.fs.FileInputSplit;
import org.apache.flink.core.memory.DataInputView;
+import org.apache.flink.testutils.junit.utils.TempDirUtils;
import org.apache.flink.types.Record;
-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;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.file.Path;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Fail.fail;
-public class BinaryInputFormatTest {
+class BinaryInputFormatTest {
- @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir private Path tempDir;
private static final class MyBinaryInputFormat extends BinaryInputFormat<Record> {
@@ -55,7 +56,7 @@ public class BinaryInputFormatTest {
}
@Test
- public void testCreateInputSplitsWithOneFile() throws IOException {
+ void testCreateInputSplitsWithOneFile() throws IOException {
final int blockInfoSize = new BlockInfo().getInfoSize();
final int blockSize = blockInfoSize + 8;
final int numBlocks = 3;
@@ -92,7 +93,7 @@ public class BinaryInputFormatTest {
}
@Test
- public void testCreateInputSplitsWithMulitpleFiles() throws IOException {
+ void testCreateInputSplitsWithMultipleFiles() throws IOException {
final int blockInfoSize = new BlockInfo().getInfoSize();
final int blockSize = blockInfoSize + 8;
final int numBlocks1 = 3;
@@ -136,7 +137,7 @@ public class BinaryInputFormatTest {
}
@Test
- public void testGetStatisticsNonExistingFiles() {
+ void testGetStatisticsNonExistingFiles() {
final MyBinaryInputFormat format = new MyBinaryInputFormat();
format.setFilePaths(
"file:///some/none/existing/directory/",
@@ -148,7 +149,7 @@ public class BinaryInputFormatTest {
}
@Test
- public void testGetStatisticsMultiplePaths() throws IOException {
+ void testGetStatisticsMultiplePaths() throws IOException {
final int blockInfoSize = new BlockInfo().getInfoSize();
final int blockSize = blockInfoSize + 8;
final int numBlocks1 = 3;
@@ -167,11 +168,11 @@ public class BinaryInputFormatTest {
assertThat(stats.getTotalInputSize())
.as("The file size statistics is wrong")
- .isEqualTo(blockSize * (numBlocks1 + numBlocks2));
+ .isEqualTo((long) blockSize * (numBlocks1 + numBlocks2));
}
@Test
- public void testCreateInputSplitsWithEmptySplit() throws IOException {
+ void testCreateInputSplitsWithEmptySplit() throws IOException {
final int blockInfoSize = new BlockInfo().getInfoSize();
final int blockSize = blockInfoSize + 8;
final int numBlocks = 3;
@@ -215,7 +216,7 @@ public class BinaryInputFormatTest {
/** Creates a temp file with a certain number of blocks of a certain size. */
private File createBinaryInputFile(String fileName, int blockSize, int numBlocks)
throws IOException {
- final File tempFile = tempFolder.newFile(fileName);
+ final File tempFile = TempDirUtils.newFile(tempDir, fileName);
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
for (int i = 0; i < blockSize * numBlocks; i++) {
fileOutputStream.write(new byte[] {1});
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/DefaultFilterTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/DefaultFilterTest.java
index a287bf616f7..24b68c6967d 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/DefaultFilterTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/DefaultFilterTest.java
@@ -18,21 +18,21 @@
package org.apache.flink.api.common.io;
import org.apache.flink.core.fs.Path;
+import org.apache.flink.testutils.junit.extensions.parameterized.ParameterizedTestExtension;
+import org.apache.flink.testutils.junit.extensions.parameterized.Parameters;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Arrays;
import java.util.Collection;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
-@RunWith(Parameterized.class)
-public class DefaultFilterTest {
+@ExtendWith(ParameterizedTestExtension.class)
+class DefaultFilterTest {
@Parameters
- public static Collection<Object[]> data() {
+ private static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {
{"file.txt", false},
@@ -53,16 +53,15 @@ public class DefaultFilterTest {
private final boolean shouldFilter;
private final String filePath;
- public DefaultFilterTest(String filePath, boolean shouldFilter) {
+ DefaultFilterTest(String filePath, boolean shouldFilter) {
this.filePath = filePath;
this.shouldFilter = shouldFilter;
}
- @Test
- public void test() {
+ @TestTemplate
+ void test() {
FilePathFilter defaultFilter = FilePathFilter.createDefaultFilter();
Path path = new Path(filePath);
- assertEquals(
- String.format("File: %s", filePath), shouldFilter, defaultFilter.filterPath(path));
+ assertThat(defaultFilter.filterPath(path)).as("File: " + filePath).isEqualTo(shouldFilter);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatSamplingTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatSamplingTest.java
index affde39117c..4f311d40fe6 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatSamplingTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatSamplingTest.java
@@ -24,15 +24,19 @@ import org.apache.flink.configuration.OptimizerOptions;
import org.apache.flink.testutils.TestConfigUtils;
import org.apache.flink.testutils.TestFileSystem;
import org.apache.flink.testutils.TestFileUtils;
+import org.apache.flink.testutils.junit.utils.TempDirUtils;
import org.apache.flink.types.IntValue;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Fail.fail;
public class DelimitedInputFormatSamplingTest {
@@ -64,7 +68,7 @@ public class DelimitedInputFormatSamplingTest {
private static Configuration CONFIG;
- @ClassRule public static TemporaryFolder tempFolder = new TemporaryFolder();
+ @TempDir private static Path tempDir;
private static File testTempFolder;
@@ -72,10 +76,10 @@ public class DelimitedInputFormatSamplingTest {
// Setup
// ========================================================================
- @BeforeClass
+ @BeforeAll
public static void initialize() {
try {
- testTempFolder = tempFolder.newFolder();
+ testTempFolder = TempDirUtils.newFolder(tempDir);
// make sure we do 4 samples
CONFIG =
TestConfigUtils.loadGlobalConf(
@@ -87,7 +91,7 @@ public class DelimitedInputFormatSamplingTest {
testTempFolder);
} catch (Throwable t) {
- Assert.fail("Could not load the global configuration.");
+ fail("Could not load the global configuration.");
}
}
@@ -96,236 +100,200 @@ public class DelimitedInputFormatSamplingTest {
// ========================================================================
@Test
- public void testNumSamplesOneFile() {
- try {
- final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath(tempFile.replace("file", "test"));
- format.configure(conf);
-
- TestFileSystem.resetStreamOpenCounter();
- format.getStatistics(null);
- Assert.assertEquals(
- "Wrong number of samples taken.",
- DEFAULT_NUM_SAMPLES,
- TestFileSystem.getNumtimeStreamOpened());
-
- TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
- format2.setFilePath(tempFile.replace("file", "test"));
- format2.setNumLineSamples(8);
- format2.configure(conf);
-
- TestFileSystem.resetStreamOpenCounter();
- format2.getStatistics(null);
- Assert.assertEquals(
- "Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
-
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testNumSamplesOneFile() throws IOException {
+ final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath(tempFile.replace("file", "test"));
+ format.configure(conf);
+
+ TestFileSystem.resetStreamOpenCounter();
+ format.getStatistics(null);
+ assertThat(TestFileSystem.getNumtimeStreamOpened())
+ .as("Wrong number of samples taken.")
+ .isEqualTo(DEFAULT_NUM_SAMPLES);
+
+ TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
+ format2.setFilePath(tempFile.replace("file", "test"));
+ format2.setNumLineSamples(8);
+ format2.configure(conf);
+
+ TestFileSystem.resetStreamOpenCounter();
+ format2.getStatistics(null);
+ assertThat(TestFileSystem.getNumtimeStreamOpened())
+ .as("Wrong number of samples taken.")
+ .isEqualTo(8);
}
@Test
- public void testNumSamplesMultipleFiles() {
- try {
- final String tempFile =
- TestFileUtils.createTempFileDir(
- testTempFolder, TEST_DATA1, TEST_DATA1, TEST_DATA1, TEST_DATA1);
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath(tempFile.replace("file", "test"));
- format.configure(conf);
-
- TestFileSystem.resetStreamOpenCounter();
- format.getStatistics(null);
- Assert.assertEquals(
- "Wrong number of samples taken.",
- DEFAULT_NUM_SAMPLES,
- TestFileSystem.getNumtimeStreamOpened());
-
- TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
- format2.setFilePath(tempFile.replace("file", "test"));
- format2.setNumLineSamples(8);
- format2.configure(conf);
-
- TestFileSystem.resetStreamOpenCounter();
- format2.getStatistics(null);
- Assert.assertEquals(
- "Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
-
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testNumSamplesMultipleFiles() throws IOException {
+ final String tempFile =
+ TestFileUtils.createTempFileDir(
+ testTempFolder, TEST_DATA1, TEST_DATA1, TEST_DATA1, TEST_DATA1);
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath(tempFile.replace("file", "test"));
+ format.configure(conf);
+
+ TestFileSystem.resetStreamOpenCounter();
+ format.getStatistics(null);
+ assertThat(TestFileSystem.getNumtimeStreamOpened())
+ .as("Wrong number of samples taken.")
+ .isEqualTo(DEFAULT_NUM_SAMPLES);
+
+ TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
+ format2.setFilePath(tempFile.replace("file", "test"));
+ format2.setNumLineSamples(8);
+ format2.configure(conf);
+
+ TestFileSystem.resetStreamOpenCounter();
+ format2.getStatistics(null);
+ assertThat(TestFileSystem.getNumtimeStreamOpened())
+ .as("Wrong number of samples taken.")
+ .isEqualTo(8);
}
@Test
- public void testSamplingOneFile() {
- try {
- final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath(tempFile);
- format.configure(conf);
- BaseStatistics stats = format.getStatistics(null);
-
- final int numLines = TEST_DATA_1_LINES;
- final float avgWidth = ((float) TEST_DATA1.length()) / TEST_DATA_1_LINES;
- Assert.assertTrue(
- "Wrong record count.",
- stats.getNumberOfRecords() < numLines + 1
- & stats.getNumberOfRecords() > numLines - 1);
- Assert.assertTrue(
- "Wrong avg record size.",
- stats.getAverageRecordWidth() < avgWidth + 1
- & stats.getAverageRecordWidth() > avgWidth - 1);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testSamplingOneFile() throws IOException {
+ final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath(tempFile);
+ format.configure(conf);
+ BaseStatistics stats = format.getStatistics(null);
+
+ final int numLines = TEST_DATA_1_LINES;
+ final float avgWidth = ((float) TEST_DATA1.length()) / TEST_DATA_1_LINES;
+ assertThat(
+ stats.getNumberOfRecords() < numLines + 1
+ & stats.getNumberOfRecords() > numLines - 1)
+ .as("Wrong record count.")
+ .isTrue();
+ assertThat(
+ stats.getAverageRecordWidth() < avgWidth + 1
+ & stats.getAverageRecordWidth() > avgWidth - 1)
+ .as("Wrong avg record size.")
+ .isTrue();
}
@Test
- public void testSamplingDirectory() {
- try {
- final String tempFile =
- TestFileUtils.createTempFileDir(testTempFolder, TEST_DATA1, TEST_DATA2);
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath(tempFile);
- format.configure(conf);
- BaseStatistics stats = format.getStatistics(null);
-
- final int maxNumLines =
- (int)
- Math.ceil(
- TOTAL_SIZE
- / ((double)
- Math.min(
- TEST_DATA_1_LINEWIDTH,
- TEST_DATA_2_LINEWIDTH)));
- final int minNumLines =
- (int)
- (TOTAL_SIZE
- / ((double)
- Math.max(
- TEST_DATA_1_LINEWIDTH, TEST_DATA_2_LINEWIDTH)));
- final float maxAvgWidth = ((float) (TOTAL_SIZE)) / minNumLines;
- final float minAvgWidth = ((float) (TOTAL_SIZE)) / maxNumLines;
-
- if (!(stats.getNumberOfRecords() <= maxNumLines
- & stats.getNumberOfRecords() >= minNumLines)) {
- System.err.println(
- "Records: "
- + stats.getNumberOfRecords()
- + " out of ("
- + minNumLines
- + ", "
- + maxNumLines
- + ").");
- Assert.fail("Wrong record count.");
- }
- if (!(stats.getAverageRecordWidth() <= maxAvgWidth
- & stats.getAverageRecordWidth() >= minAvgWidth)) {
- Assert.fail("Wrong avg record size.");
- }
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
+ void testSamplingDirectory() throws IOException {
+ final String tempFile =
+ TestFileUtils.createTempFileDir(testTempFolder, TEST_DATA1, TEST_DATA2);
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath(tempFile);
+ format.configure(conf);
+ BaseStatistics stats = format.getStatistics(null);
+
+ final int maxNumLines =
+ (int)
+ Math.ceil(
+ TOTAL_SIZE
+ / ((double)
+ Math.min(
+ TEST_DATA_1_LINEWIDTH,
+ TEST_DATA_2_LINEWIDTH)));
+ final int minNumLines =
+ (int)
+ (TOTAL_SIZE
+ / ((double)
+ Math.max(TEST_DATA_1_LINEWIDTH, TEST_DATA_2_LINEWIDTH)));
+ final float maxAvgWidth = ((float) (TOTAL_SIZE)) / minNumLines;
+ final float minAvgWidth = ((float) (TOTAL_SIZE)) / maxNumLines;
+
+ if (!(stats.getNumberOfRecords() <= maxNumLines
+ & stats.getNumberOfRecords() >= minNumLines)) {
+ System.err.println(
+ "Records: "
+ + stats.getNumberOfRecords()
+ + " out of ("
+ + minNumLines
+ + ", "
+ + maxNumLines
+ + ").");
+ fail("Wrong record count.");
+ }
+ if (!(stats.getAverageRecordWidth() <= maxAvgWidth
+ & stats.getAverageRecordWidth() >= minAvgWidth)) {
+ fail("Wrong avg record size.");
}
}
@Test
- public void testDifferentDelimiter() {
- try {
- final String DELIMITER = "12345678-";
- String testData = TEST_DATA1.replace("\n", DELIMITER);
-
- final String tempFile = TestFileUtils.createTempFile(testData);
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath(tempFile);
- format.setDelimiter(DELIMITER);
- format.configure(conf);
-
- BaseStatistics stats = format.getStatistics(null);
- final int numLines = TEST_DATA_1_LINES;
- final float avgWidth = ((float) testData.length()) / TEST_DATA_1_LINES;
-
- Assert.assertTrue(
- "Wrong record count.",
- stats.getNumberOfRecords() < numLines + 1
- & stats.getNumberOfRecords() > numLines - 1);
- Assert.assertTrue(
- "Wrong avg record size.",
- stats.getAverageRecordWidth() < avgWidth + 1
- & stats.getAverageRecordWidth() > avgWidth - 1);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testDifferentDelimiter() throws IOException {
+ final String DELIMITER = "12345678-";
+ String testData = TEST_DATA1.replace("\n", DELIMITER);
+
+ final String tempFile = TestFileUtils.createTempFile(testData);
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath(tempFile);
+ format.setDelimiter(DELIMITER);
+ format.configure(conf);
+
+ BaseStatistics stats = format.getStatistics(null);
+ final int numLines = TEST_DATA_1_LINES;
+ final float avgWidth = ((float) testData.length()) / TEST_DATA_1_LINES;
+
+ assertThat(
+ stats.getNumberOfRecords() < numLines + 1
+ & stats.getNumberOfRecords() > numLines - 1)
+ .as("Wrong record count.")
+ .isTrue();
+ assertThat(
+ stats.getAverageRecordWidth() < avgWidth + 1
+ & stats.getAverageRecordWidth() > avgWidth - 1)
+ .as("Wrong avg record size.")
+ .isTrue();
}
@Test
- public void testSamplingOverlyLongRecord() {
- try {
- final String tempFile =
- TestFileUtils.createTempFile(
- 2 * OptimizerOptions.DELIMITED_FORMAT_MAX_SAMPLE_LEN.defaultValue());
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath(tempFile);
- format.configure(conf);
-
- Assert.assertNull(
- "Expected exception due to overly long record.", format.getStatistics(null));
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testSamplingOverlyLongRecord() throws IOException {
+ final String tempFile =
+ TestFileUtils.createTempFile(
+ 2L * OptimizerOptions.DELIMITED_FORMAT_MAX_SAMPLE_LEN.defaultValue());
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath(tempFile);
+ format.configure(conf);
+
+ assertThat(format.getStatistics(null))
+ .as("Expected exception due to overly long record.")
+ .isNull();
}
@Test
- public void testCachedStatistics() {
- try {
- final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
- final Configuration conf = new Configuration();
-
- final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
- format.setFilePath("test://" + tempFile);
- format.configure(conf);
-
- TestFileSystem.resetStreamOpenCounter();
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "Wrong number of samples taken.",
- DEFAULT_NUM_SAMPLES,
- TestFileSystem.getNumtimeStreamOpened());
-
- final TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
- format2.setFilePath("test://" + tempFile);
- format2.configure(conf);
-
- TestFileSystem.resetStreamOpenCounter();
- BaseStatistics stats2 = format2.getStatistics(stats);
- Assert.assertTrue(
- "Using cached statistics should cicumvent sampling.",
- 0 == TestFileSystem.getNumtimeStreamOpened());
- Assert.assertTrue(
- "Using cached statistics should cicumvent sampling.", stats == stats2);
-
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testCachedStatistics() throws IOException {
+ final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
+ final Configuration conf = new Configuration();
+
+ final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
+ format.setFilePath("test://" + tempFile);
+ format.configure(conf);
+
+ TestFileSystem.resetStreamOpenCounter();
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(TestFileSystem.getNumtimeStreamOpened())
+ .as("Wrong number of samples taken.")
+ .isEqualTo(DEFAULT_NUM_SAMPLES);
+
+ final TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
+ format2.setFilePath("test://" + tempFile);
+ format2.configure(conf);
+
+ TestFileSystem.resetStreamOpenCounter();
+ BaseStatistics stats2 = format2.getStatistics(stats);
+ assertThat(TestFileSystem.getNumtimeStreamOpened())
+ .as("Using cached statistics should cicumvent sampling.")
+ .isZero();
+ assertThat(stats2).as("Using cached statistics should cicumvent sampling.").isSameAs(stats);
}
// ========================================================================
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatTest.java
index ce17dddf606..8e9f62ca3c9 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/DelimitedInputFormatTest.java
@@ -27,42 +27,38 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.util.function.FunctionWithException;
import org.apache.commons.lang3.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
-public class DelimitedInputFormatTest {
+class DelimitedInputFormatTest {
private DelimitedInputFormat<String> format;
// --------------------------------------------------------------------------------------------
- @Before
+ @BeforeEach
public void setup() {
format = new MyTextInputFormat();
this.format.setFilePath(new Path("file:///some/file/that/will/not/be/read"));
}
- @After
+ @AfterEach
public void shutdown() throws Exception {
if (this.format != null) {
this.format.close();
@@ -72,20 +68,20 @@ public class DelimitedInputFormatTest {
// --------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
@Test
- public void testConfigure() {
+ void testConfigure() {
Configuration cfg = new Configuration();
cfg.setString("delimited-format.delimiter", "\n");
format.configure(cfg);
- assertEquals("\n", new String(format.getDelimiter(), format.getCharset()));
+ assertThat(new String(format.getDelimiter(), format.getCharset())).isEqualTo("\n");
cfg.setString("delimited-format.delimiter", "&-&");
format.configure(cfg);
- assertEquals("&-&", new String(format.getDelimiter(), format.getCharset()));
+ assertThat(new String(format.getDelimiter(), format.getCharset())).isEqualTo("&-&");
}
@Test
- public void testSerialization() throws Exception {
+ void testSerialization() throws Exception {
final byte[] DELIMITER = new byte[] {1, 2, 3, 4};
final int NUM_LINE_SAMPLES = 7;
final int LINE_LENGTH_LIMIT = 12345;
@@ -107,27 +103,27 @@ public class DelimitedInputFormatTest {
@SuppressWarnings("unchecked")
DelimitedInputFormat<String> deserialized = (DelimitedInputFormat<String>) ois.readObject();
- assertEquals(NUM_LINE_SAMPLES, deserialized.getNumLineSamples());
- assertEquals(LINE_LENGTH_LIMIT, deserialized.getLineLengthLimit());
- assertEquals(BUFFER_SIZE, deserialized.getBufferSize());
- assertArrayEquals(DELIMITER, deserialized.getDelimiter());
+ assertThat(deserialized.getNumLineSamples()).isEqualTo(NUM_LINE_SAMPLES);
+ assertThat(deserialized.getLineLengthLimit()).isEqualTo(LINE_LENGTH_LIMIT);
+ assertThat(deserialized.getBufferSize()).isEqualTo(BUFFER_SIZE);
+ assertThat(deserialized.getDelimiter()).isEqualTo(DELIMITER);
}
@Test
- public void testOpen() throws IOException {
+ void testOpen() throws IOException {
final String myString = "my mocked line 1\nmy mocked line 2\n";
final FileInputSplit split = createTempFile(myString);
int bufferSize = 5;
format.setBufferSize(bufferSize);
format.open(split);
- assertEquals(0, format.splitStart);
- assertEquals(myString.length() - bufferSize, format.splitLength);
- assertEquals(bufferSize, format.getBufferSize());
+ assertThat(format.splitStart).isZero();
+ assertThat(format.splitLength).isEqualTo(myString.length() - bufferSize);
+ assertThat(format.getBufferSize()).isEqualTo(bufferSize);
}
@Test
- public void testReadWithoutTrailingDelimiter() throws IOException {
+ void testReadWithoutTrailingDelimiter() throws IOException {
// 2. test case
final String myString = "my key|my val$$$my key2\n$$ctd.$$|my value2";
final FileInputSplit split = createTempFile(myString);
@@ -141,18 +137,18 @@ public class DelimitedInputFormatTest {
String first = format.nextRecord(null);
String second = format.nextRecord(null);
- assertNotNull(first);
- assertNotNull(second);
+ assertThat(first).isNotNull();
+ assertThat(second).isNotNull();
- assertEquals("my key|my val$$$my key2", first);
- assertEquals("$$ctd.$$|my value2", second);
+ assertThat(first).isEqualTo("my key|my val$$$my key2");
+ assertThat(second).isEqualTo("$$ctd.$$|my value2");
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadWithTrailingDelimiter() throws IOException {
+ void testReadWithTrailingDelimiter() throws IOException {
// 2. test case
final String myString = "my key|my val$$$my key2\n$$ctd.$$|my value2\n";
final FileInputSplit split = createTempFile(myString);
@@ -166,18 +162,18 @@ public class DelimitedInputFormatTest {
String first = format.nextRecord(null);
String second = format.nextRecord(null);
- assertNotNull(first);
- assertNotNull(second);
+ assertThat(first).isNotNull();
+ assertThat(second).isNotNull();
- assertEquals("my key|my val$$$my key2", first);
- assertEquals("$$ctd.$$|my value2", second);
+ assertThat(first).isEqualTo("my key|my val$$$my key2");
+ assertThat(second).isEqualTo("$$ctd.$$|my value2");
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadCustomDelimiter() throws IOException {
+ void testReadCustomDelimiter() throws IOException {
final String myString = "my key|my val$$$my key2\n$$ctd.$$|my value2";
final FileInputSplit split = createTempFile(myString);
@@ -188,19 +184,19 @@ public class DelimitedInputFormatTest {
format.open(split);
String first = format.nextRecord(null);
- assertNotNull(first);
- assertEquals("my key|my val", first);
+ assertThat(first).isNotNull();
+ assertThat(first).isEqualTo("my key|my val");
String second = format.nextRecord(null);
- assertNotNull(second);
- assertEquals("my key2\n$$ctd.$$|my value2", second);
+ assertThat(second).isNotNull();
+ assertThat(second).isEqualTo("my key2\n$$ctd.$$|my value2");
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testMultiCharDelimiter() throws IOException {
+ void testMultiCharDelimiter() throws IOException {
final String myString = "www112xx1123yyy11123zzzzz1123";
final FileInputSplit split = createTempFile(myString);
@@ -211,23 +207,23 @@ public class DelimitedInputFormatTest {
format.open(split);
String first = format.nextRecord(null);
- assertNotNull(first);
- assertEquals("www112xx", first);
+ assertThat(first).isNotNull();
+ assertThat(first).isEqualTo("www112xx");
String second = format.nextRecord(null);
- assertNotNull(second);
- assertEquals("yyy1", second);
+ assertThat(second).isNotNull();
+ assertThat(second).isEqualTo("yyy1");
String third = format.nextRecord(null);
- assertNotNull(third);
- assertEquals("zzzzz", third);
+ assertThat(third).isNotNull();
+ assertThat(third).isEqualTo("zzzzz");
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadCustomDelimiterWithCharset() throws IOException {
+ void testReadCustomDelimiterWithCharset() throws IOException {
// Unicode row fragments
String[] records =
new String[] {
@@ -263,11 +259,11 @@ public class DelimitedInputFormatTest {
for (String record : records) {
String value = format.nextRecord(null);
- assertEquals(record, value);
+ assertThat(value).isEqualTo(record);
}
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
}
@@ -276,7 +272,7 @@ public class DelimitedInputFormatTest {
* record.
*/
@Test
- public void testReadOverSplitBoundariesUnaligned() throws IOException {
+ void testReadOverSplitBoundariesUnaligned() throws IOException {
final String myString = "value1\nvalue2\nvalue3";
final FileInputSplit split = createTempFile(myString);
@@ -296,17 +292,17 @@ public class DelimitedInputFormatTest {
format.configure(parameters);
format.open(split1);
- assertEquals("value1", format.nextRecord(null));
- assertEquals("value2", format.nextRecord(null));
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isEqualTo("value1");
+ assertThat(format.nextRecord(null)).isEqualTo("value2");
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
format.open(split2);
- assertEquals("value3", format.nextRecord(null));
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isEqualTo("value3");
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
}
@@ -316,7 +312,7 @@ public class DelimitedInputFormatTest {
* record boundary.
*/
@Test
- public void testReadWithBufferSizeIsMultiple() throws IOException {
+ void testReadWithBufferSizeIsMultiple() throws IOException {
final String myString = "aaaaaaa\nbbbbbbb\nccccccc\nddddddd\n";
final FileInputSplit split = createTempFile(myString);
@@ -342,31 +338,31 @@ public class DelimitedInputFormatTest {
// read split 1
format.open(split1);
while ((next = format.nextRecord(null)) != null) {
- assertEquals(7, next.length());
+ assertThat(next).hasSize(7);
count++;
}
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
// this one must have read one too many, because the next split will skip the trailing
// remainder
// which happens to be one full record
- assertEquals(3, count);
+ assertThat(count).isEqualTo(3);
// read split 2
format.open(split2);
while ((next = format.nextRecord(null)) != null) {
- assertEquals(7, next.length());
+ assertThat(next).hasSize(7);
count++;
}
format.close();
- assertEquals(4, count);
+ assertThat(count).isEqualTo(4);
}
@Test
- public void testReadExactlyBufferSize() throws IOException {
+ void testReadExactlyBufferSize() throws IOException {
final String myString = "aaaaaaa\nbbbbbbb\nccccccc\nddddddd\n";
final FileInputSplit split = createTempFile(myString);
@@ -379,19 +375,19 @@ public class DelimitedInputFormatTest {
String next;
int count = 0;
while ((next = format.nextRecord(null)) != null) {
- assertEquals(7, next.length());
+ assertThat(next).hasSize(7);
count++;
}
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
- assertEquals(4, count);
+ assertThat(count).isEqualTo(4);
}
@Test
- public void testReadRecordsLargerThanBuffer() throws IOException {
+ void testReadRecordsLargerThanBuffer() throws IOException {
final String myString =
"aaaaaaaaaaaaaaaaaaaaa\n"
+ "bbbbbbbbbbbbbbbbbbbbbbbbb\n"
@@ -416,36 +412,36 @@ public class DelimitedInputFormatTest {
format.configure(parameters);
String next;
- List<String> result = new ArrayList<String>();
+ List<String> result = new ArrayList<>();
format.open(split1);
while ((next = format.nextRecord(null)) != null) {
result.add(next);
}
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
format.open(split2);
while ((next = format.nextRecord(null)) != null) {
result.add(next);
}
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
- assertEquals(4, result.size());
- assertEquals(Arrays.asList(myString.split("\n")), result);
+ assertThat(result).hasSize(4);
+ assertThat(result).isEqualTo(Arrays.asList(myString.split("\n")));
}
@Test
- public void testDelimiterOnBufferBoundary() throws IOException {
+ void testDelimiterOnBufferBoundary() throws IOException {
- testDelimiterOnBufferBoundary(fileContent -> createTempFile(fileContent));
+ testDelimiterOnBufferBoundary(DelimitedInputFormatTest::createTempFile);
}
@Test
- public void testDelimiterOnBufferBoundaryWithWholeFileSplit() throws IOException {
+ void testDelimiterOnBufferBoundaryWithWholeFileSplit() throws IOException {
testDelimiterOnBufferBoundary(
fileContent -> {
@@ -474,11 +470,11 @@ public class DelimitedInputFormatTest {
for (String record : records) {
String value = format.nextRecord(null);
- assertEquals(record, value);
+ assertThat(value).isEqualTo(record);
}
- assertNull(format.nextRecord(null));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(null)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
format.close();
}
@@ -486,7 +482,7 @@ public class DelimitedInputFormatTest {
// -- Statistics --//
@Test
- public void testGetStatistics() throws IOException {
+ void testGetStatistics() throws IOException {
final String myString = "my mocked line 1\nmy mocked line 2\n";
final long size = myString.length();
final Path filePath = createTempFilePath(myString);
@@ -501,25 +497,24 @@ public class DelimitedInputFormatTest {
format.setFilePaths(filePath.toUri().toString(), filePath2.toUri().toString());
FileInputFormat.FileBaseStatistics stats = format.getStatistics(null);
- assertNotNull(stats);
- assertEquals(
- "The file size from the statistics is wrong.",
- totalSize,
- stats.getTotalInputSize());
+ assertThat(stats).isNotNull();
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(totalSize);
}
@Test
- public void testGetStatisticsFileDoesNotExist() throws IOException {
+ void testGetStatisticsFileDoesNotExist() throws IOException {
DelimitedInputFormat<String> format = new MyTextInputFormat();
format.setFilePaths(
"file:///path/does/not/really/exist", "file:///another/path/that/does/not/exist");
FileBaseStatistics stats = format.getStatistics(null);
- assertNull("The file statistics should be null.", stats);
+ assertThat(stats).as("The file statistics should be null.").isNull();
}
@Test
- public void testGetStatisticsSingleFileWithCachedVersion() throws IOException {
+ void testGetStatisticsSingleFileWithCachedVersion() throws IOException {
final String myString = "my mocked line 1\nmy mocked line 2\n";
final Path tempFile = createTempFilePath(myString);
final long size = myString.length();
@@ -530,16 +525,17 @@ public class DelimitedInputFormatTest {
format.configure(new Configuration());
FileBaseStatistics stats = format.getStatistics(null);
- assertNotNull(stats);
- assertEquals(
- "The file size from the statistics is wrong.", size, stats.getTotalInputSize());
+ assertThat(stats).isNotNull();
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(size);
format = new MyTextInputFormat();
format.setFilePath(tempFile);
format.configure(new Configuration());
FileBaseStatistics newStats = format.getStatistics(stats);
- assertEquals("Statistics object was changed.", newStats, stats);
+ assertThat(newStats).as("Statistics object was changed.").isEqualTo(stats);
// insert fake stats with the correct modification time. the call should return the fake
// stats
@@ -553,10 +549,9 @@ public class DelimitedInputFormatTest {
fakeSize,
BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
BaseStatistics latest = format.getStatistics(fakeStats);
- assertEquals(
- "The file size from the statistics is wrong.",
- fakeSize,
- latest.getTotalInputSize());
+ assertThat(latest.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(fakeSize);
// insert fake stats with the expired modification time. the call should return new accurate
// stats
@@ -570,17 +565,16 @@ public class DelimitedInputFormatTest {
fakeSize,
BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
BaseStatistics reGathered = format.getStatistics(outDatedFakeStats);
- assertEquals(
- "The file size from the statistics is wrong.",
- size,
- reGathered.getTotalInputSize());
+ assertThat(reGathered.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(size);
}
static FileInputSplit createTempFile(String contents) throws IOException {
File tempFile = File.createTempFile("test_contents", "tmp");
tempFile.deleteOnExit();
- try (Writer out = new OutputStreamWriter(new FileOutputStream(tempFile))) {
+ try (Writer out = new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()))) {
out.write(contents);
}
@@ -596,7 +590,8 @@ public class DelimitedInputFormatTest {
File tempFile = File.createTempFile("test_contents", "tmp");
tempFile.deleteOnExit();
- try (Writer out = new OutputStreamWriter(new FileOutputStream(tempFile), charset)) {
+ try (Writer out =
+ new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()), charset)) {
out.write(contents);
}
@@ -626,7 +621,8 @@ public class DelimitedInputFormatTest {
File tempFile = File.createTempFile("test_contents", "tmp");
tempFile.deleteOnExit();
- try (OutputStreamWriter wrt = new OutputStreamWriter(new FileOutputStream(tempFile))) {
+ try (OutputStreamWriter wrt =
+ new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()))) {
wrt.write(contents);
}
return new Path(tempFile.toURI().toString());
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/EnumerateNestedFilesTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/EnumerateNestedFilesTest.java
index fbf99dc6510..051e6c87a11 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/EnumerateNestedFilesTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/EnumerateNestedFilesTest.java
@@ -23,33 +23,34 @@ import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.fs.FileInputSplit;
import org.apache.flink.core.fs.Path;
import org.apache.flink.testutils.TestFileUtils;
+import org.apache.flink.testutils.junit.utils.TempDirUtils;
import org.apache.flink.types.IntValue;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.IOException;
-public class EnumerateNestedFilesTest {
+import static org.assertj.core.api.Assertions.assertThat;
- @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+class EnumerateNestedFilesTest {
+
+ @TempDir private static java.nio.file.Path tempDir;
protected Configuration config;
private DummyFileInputFormat format;
- @Before
+ @BeforeEach
public void setup() {
this.config = new Configuration();
format = new DummyFileInputFormat();
}
- @After
+ @AfterEach
public void setdown() throws Exception {
if (this.format != null) {
this.format.close();
@@ -58,261 +59,226 @@ public class EnumerateNestedFilesTest {
/** Test without nested directory and recursive.file.enumeration = true */
@Test
- public void testNoNestedDirectoryTrue() {
- try {
- String filePath = TestFileUtils.createTempFile("foo");
-
- this.format.setFilePath(new Path(filePath));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(1, splits.length);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testNoNestedDirectoryTrue() throws IOException {
+ String filePath = TestFileUtils.createTempFile("foo");
+
+ this.format.setFilePath(new Path(filePath));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ FileInputSplit[] splits = format.createInputSplits(1);
+ assertThat(splits).hasSize(1);
}
/** Test with one nested directory and recursive.file.enumeration = true */
@Test
- public void testOneNestedDirectoryTrue() {
- try {
- String firstLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir = TestFileUtils.randomFileName();
-
- File insideNestedDir = tempFolder.newFolder(firstLevelDir, secondLevelDir);
- File nestedDir = insideNestedDir.getParentFile();
-
- // create a file in the first-level and two files in the nested dir
- TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
-
- this.format.setFilePath(new Path(nestedDir.toURI().toString()));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(3, splits.length);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testOneNestedDirectoryTrue() throws IOException {
+ String firstLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir = TestFileUtils.randomFileName();
+
+ File insideNestedDir = TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelDir);
+ File nestedDir = insideNestedDir.getParentFile();
+
+ // create a file in the first-level and two files in the nested dir
+ TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
+
+ this.format.setFilePath(new Path(nestedDir.toURI().toString()));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ FileInputSplit[] splits = format.createInputSplits(1);
+ assertThat(splits).hasSize(3);
}
/** Test with one nested directory and recursive.file.enumeration = false */
@Test
- public void testOneNestedDirectoryFalse() {
- try {
- String firstLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir = TestFileUtils.randomFileName();
-
- File insideNestedDir = tempFolder.newFolder(firstLevelDir, secondLevelDir);
- File nestedDir = insideNestedDir.getParentFile();
-
- // create a file in the first-level and two files in the nested dir
- TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
-
- this.format.setFilePath(new Path(nestedDir.toURI().toString()));
- this.config.setBoolean("recursive.file.enumeration", false);
- format.configure(this.config);
-
- FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(1, splits.length);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testOneNestedDirectoryFalse() throws IOException {
+ String firstLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir = TestFileUtils.randomFileName();
+
+ File insideNestedDir = TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelDir);
+ File nestedDir = insideNestedDir.getParentFile();
+
+ // create a file in the first-level and two files in the nested dir
+ TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
+
+ this.format.setFilePath(new Path(nestedDir.toURI().toString()));
+ this.config.setBoolean("recursive.file.enumeration", false);
+ format.configure(this.config);
+
+ FileInputSplit[] splits = format.createInputSplits(1);
+ assertThat(splits).hasSize(1);
}
/** Test with two nested directories and recursive.file.enumeration = true */
@Test
- public void testTwoNestedDirectoriesTrue() {
- try {
- String firstLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir = TestFileUtils.randomFileName();
- String thirdLevelDir = TestFileUtils.randomFileName();
-
- File nestedNestedDir =
- tempFolder.newFolder(firstLevelDir, secondLevelDir, thirdLevelDir);
- File insideNestedDir = nestedNestedDir.getParentFile();
- File nestedDir = insideNestedDir.getParentFile();
-
- // create a file in the first-level, two files in the second level and one in the third
- // level
- TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
- TestFileUtils.createTempFileInDirectory(nestedNestedDir.getAbsolutePath(), "bravas");
-
- this.format.setFilePath(new Path(nestedDir.toURI().toString()));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(4, splits.length);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testTwoNestedDirectoriesTrue() throws IOException {
+
+ String firstLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir = TestFileUtils.randomFileName();
+ String thirdLevelDir = TestFileUtils.randomFileName();
+
+ File nestedNestedDir =
+ TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelDir, thirdLevelDir);
+ File insideNestedDir = nestedNestedDir.getParentFile();
+ File nestedDir = insideNestedDir.getParentFile();
+
+ // create a file in the first-level, two files in the second level and one in the third
+ // level
+ TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
+ TestFileUtils.createTempFileInDirectory(nestedNestedDir.getAbsolutePath(), "bravas");
+
+ this.format.setFilePath(new Path(nestedDir.toURI().toString()));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ FileInputSplit[] splits = format.createInputSplits(1);
+ assertThat(splits).hasSize(4);
}
/** Tests if the recursion is invoked correctly in nested directories. */
@Test
- public void testOnlyLevel2NestedDirectories() {
- try {
- String rootDir = TestFileUtils.randomFileName();
- String nestedDir = TestFileUtils.randomFileName();
- String firstNestedNestedDir = TestFileUtils.randomFileName();
- String secondNestedNestedDir = TestFileUtils.randomFileName();
-
- File testDir = tempFolder.newFolder(rootDir);
- tempFolder.newFolder(rootDir, nestedDir);
- File nestedNestedDir1 = tempFolder.newFolder(rootDir, nestedDir, firstNestedNestedDir);
- File nestedNestedDir2 = tempFolder.newFolder(rootDir, nestedDir, secondNestedNestedDir);
-
- // create files in second level
- TestFileUtils.createTempFileInDirectory(nestedNestedDir1.getAbsolutePath(), "paella");
- TestFileUtils.createTempFileInDirectory(nestedNestedDir1.getAbsolutePath(), "kalamari");
- TestFileUtils.createTempFileInDirectory(nestedNestedDir2.getAbsolutePath(), "fideua");
- TestFileUtils.createTempFileInDirectory(nestedNestedDir2.getAbsolutePath(), "bravas");
-
- this.format.setFilePath(new Path(testDir.getAbsolutePath()));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(4, splits.length);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testOnlyLevel2NestedDirectories() throws IOException {
+
+ String rootDir = TestFileUtils.randomFileName();
+ String nestedDir = TestFileUtils.randomFileName();
+ String firstNestedNestedDir = TestFileUtils.randomFileName();
+ String secondNestedNestedDir = TestFileUtils.randomFileName();
+
+ File testDir = TempDirUtils.newFolder(tempDir, rootDir);
+ TempDirUtils.newFolder(tempDir, rootDir, nestedDir);
+ File nestedNestedDir1 =
+ TempDirUtils.newFolder(tempDir, rootDir, nestedDir, firstNestedNestedDir);
+ File nestedNestedDir2 =
+ TempDirUtils.newFolder(tempDir, rootDir, nestedDir, secondNestedNestedDir);
+
+ // create files in second level
+ TestFileUtils.createTempFileInDirectory(nestedNestedDir1.getAbsolutePath(), "paella");
+ TestFileUtils.createTempFileInDirectory(nestedNestedDir1.getAbsolutePath(), "kalamari");
+ TestFileUtils.createTempFileInDirectory(nestedNestedDir2.getAbsolutePath(), "fideua");
+ TestFileUtils.createTempFileInDirectory(nestedNestedDir2.getAbsolutePath(), "bravas");
+
+ this.format.setFilePath(new Path(testDir.getAbsolutePath()));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ FileInputSplit[] splits = format.createInputSplits(1);
+ assertThat(splits).hasSize(4);
}
/** Test with two nested directories and recursive.file.enumeration = true */
@Test
- public void testTwoNestedDirectoriesWithFilteredFilesTrue() {
- try {
- String firstLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir = TestFileUtils.randomFileName();
- String thirdLevelDir = TestFileUtils.randomFileName();
- String secondLevelFilterDir = "_" + TestFileUtils.randomFileName();
- String thirdLevelFilterDir = "_" + TestFileUtils.randomFileName();
-
- File nestedNestedDirFiltered =
- tempFolder.newFolder(
- firstLevelDir, secondLevelDir, thirdLevelDir, thirdLevelFilterDir);
- File nestedNestedDir = nestedNestedDirFiltered.getParentFile();
- File insideNestedDir = nestedNestedDir.getParentFile();
- File nestedDir = insideNestedDir.getParentFile();
- File insideNestedDirFiltered =
- tempFolder.newFolder(firstLevelDir, secondLevelFilterDir);
- File filteredFile = new File(nestedDir, "_IWillBeFiltered");
- filteredFile.createNewFile();
-
- // create a file in the first-level, two files in the second level and one in the third
- // level
- TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
- TestFileUtils.createTempFileInDirectory(nestedNestedDir.getAbsolutePath(), "bravas");
- // create files which are filtered
- TestFileUtils.createTempFileInDirectory(
- insideNestedDirFiltered.getAbsolutePath(), "kalamari");
- TestFileUtils.createTempFileInDirectory(
- insideNestedDirFiltered.getAbsolutePath(), "fideua");
- TestFileUtils.createTempFileInDirectory(
- nestedNestedDirFiltered.getAbsolutePath(), "bravas");
-
- this.format.setFilePath(new Path(nestedDir.toURI().toString()));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(4, splits.length);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testTwoNestedDirectoriesWithFilteredFilesTrue() throws IOException {
+
+ String firstLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir = TestFileUtils.randomFileName();
+ String thirdLevelDir = TestFileUtils.randomFileName();
+ String secondLevelFilterDir = "_" + TestFileUtils.randomFileName();
+ String thirdLevelFilterDir = "_" + TestFileUtils.randomFileName();
+
+ File nestedNestedDirFiltered =
+ TempDirUtils.newFolder(
+ tempDir, firstLevelDir, secondLevelDir, thirdLevelDir, thirdLevelFilterDir);
+ File nestedNestedDir = nestedNestedDirFiltered.getParentFile();
+ File insideNestedDir = nestedNestedDir.getParentFile();
+ File nestedDir = insideNestedDir.getParentFile();
+ File insideNestedDirFiltered =
+ TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelFilterDir);
+ File filteredFile = new File(nestedDir, "_IWillBeFiltered");
+ filteredFile.createNewFile();
+
+ // create a file in the first-level, two files in the second level and one in the third
+ // level
+ TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), "paella");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "kalamari");
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), "fideua");
+ TestFileUtils.createTempFileInDirectory(nestedNestedDir.getAbsolutePath(), "bravas");
+ // create files which are filtered
+ TestFileUtils.createTempFileInDirectory(
+ insideNestedDirFiltered.getAbsolutePath(), "kalamari");
+ TestFileUtils.createTempFileInDirectory(
+ insideNestedDirFiltered.getAbsolutePath(), "fideua");
+ TestFileUtils.createTempFileInDirectory(
+ nestedNestedDirFiltered.getAbsolutePath(), "bravas");
+
+ this.format.setFilePath(new Path(nestedDir.toURI().toString()));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ FileInputSplit[] splits = format.createInputSplits(1);
+ assertThat(splits).hasSize(4);
}
@Test
- public void testGetStatisticsOneFileInNestedDir() {
- try {
- final long SIZE = 1024 * 500;
- String firstLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir = TestFileUtils.randomFileName();
-
- File insideNestedDir = tempFolder.newFolder(firstLevelDir, secondLevelDir);
- File nestedDir = insideNestedDir.getParentFile();
-
- // create a file in the nested dir
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), SIZE);
-
- this.format.setFilePath(new Path(nestedDir.toURI().toString()));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.", SIZE, stats.getTotalInputSize());
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testGetStatisticsOneFileInNestedDir() throws IOException {
+
+ final long SIZE = 1024 * 500;
+ String firstLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir = TestFileUtils.randomFileName();
+
+ File insideNestedDir = TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelDir);
+ File nestedDir = insideNestedDir.getParentFile();
+
+ // create a file in the nested dir
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), SIZE);
+
+ this.format.setFilePath(new Path(nestedDir.toURI().toString()));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(SIZE);
}
@Test
- public void testGetStatisticsMultipleNestedFiles() {
- try {
- final long SIZE1 = 2077;
- final long SIZE2 = 31909;
- final long SIZE3 = 10;
- final long SIZE4 = 71;
- final long TOTAL = SIZE1 + SIZE2 + SIZE3 + SIZE4;
-
- String firstLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir = TestFileUtils.randomFileName();
- String secondLevelDir2 = TestFileUtils.randomFileName();
-
- File insideNestedDir = tempFolder.newFolder(firstLevelDir, secondLevelDir);
- File insideNestedDir2 = tempFolder.newFolder(firstLevelDir, secondLevelDir2);
- File nestedDir = insideNestedDir.getParentFile();
-
- // create a file in the first-level and two files in the nested dir
- TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), SIZE1);
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), SIZE2);
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), SIZE3);
- TestFileUtils.createTempFileInDirectory(insideNestedDir2.getAbsolutePath(), SIZE4);
-
- this.format.setFilePath(new Path(nestedDir.toURI().toString()));
- this.config.setBoolean("recursive.file.enumeration", true);
- format.configure(this.config);
-
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- TOTAL,
- stats.getTotalInputSize());
-
- /* Now invalidate the cache and check again */
- Thread.sleep(1000); // accuracy of file modification times is rather low
- TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), 42L);
-
- BaseStatistics stats2 = format.getStatistics(stats);
- Assert.assertNotEquals(stats2, stats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- TOTAL + 42L,
- stats2.getTotalInputSize());
-
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testGetStatisticsMultipleNestedFiles() throws IOException, InterruptedException {
+
+ final long SIZE1 = 2077;
+ final long SIZE2 = 31909;
+ final long SIZE3 = 10;
+ final long SIZE4 = 71;
+ final long TOTAL = SIZE1 + SIZE2 + SIZE3 + SIZE4;
+
+ String firstLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir = TestFileUtils.randomFileName();
+ String secondLevelDir2 = TestFileUtils.randomFileName();
+
+ File insideNestedDir = TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelDir);
+ File insideNestedDir2 = TempDirUtils.newFolder(tempDir, firstLevelDir, secondLevelDir2);
+ File nestedDir = insideNestedDir.getParentFile();
+
+ // create a file in the first-level and two files in the nested dir
+ TestFileUtils.createTempFileInDirectory(nestedDir.getAbsolutePath(), SIZE1);
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), SIZE2);
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), SIZE3);
+ TestFileUtils.createTempFileInDirectory(insideNestedDir2.getAbsolutePath(), SIZE4);
+
+ this.format.setFilePath(new Path(nestedDir.toURI().toString()));
+ this.config.setBoolean("recursive.file.enumeration", true);
+ format.configure(this.config);
+
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(TOTAL);
+
+ /* Now invalidate the cache and check again */
+ Thread.sleep(1000); // accuracy of file modification times is rather low
+ TestFileUtils.createTempFileInDirectory(insideNestedDir.getAbsolutePath(), 42L);
+
+ BaseStatistics stats2 = format.getStatistics(stats);
+ assertThat(stats).isNotEqualTo(stats2);
+ assertThat(stats2.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(TOTAL + 42L);
}
// ------------------------------------------------------------------------
@@ -321,12 +287,12 @@ public class EnumerateNestedFilesTest {
private static final long serialVersionUID = 1L;
@Override
- public boolean reachedEnd() throws IOException {
+ public boolean reachedEnd() {
return true;
}
@Override
- public IntValue nextRecord(IntValue reuse) throws IOException {
+ public IntValue nextRecord(IntValue reuse) {
return null;
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/FileInputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/FileInputFormatTest.java
index 920e3be52fc..66d43e9b6a9 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/FileInputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/FileInputFormatTest.java
@@ -28,12 +28,11 @@ import org.apache.flink.core.fs.FileStatus;
import org.apache.flink.core.fs.FileSystem;
import org.apache.flink.core.fs.Path;
import org.apache.flink.testutils.TestFileUtils;
+import org.apache.flink.testutils.junit.utils.TempDirUtils;
import org.apache.flink.types.IntValue;
-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;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -41,108 +40,115 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Fail.fail;
+
/** Tests for the FileInputFormat */
-public class FileInputFormatTest {
+class FileInputFormatTest {
- @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @TempDir private java.nio.file.Path temporaryFolder;
@Test
- public void testGetPathWithoutSettingFirst() {
+ void testGetPathWithoutSettingFirst() {
final DummyFileInputFormat format = new DummyFileInputFormat();
- Assert.assertNull("Path should be null.", format.getFilePath());
+ assertThat(format.getFilePath()).as("Path should be null.").isNull();
}
@Test
- public void testGetPathsWithoutSettingFirst() {
+ void testGetPathsWithoutSettingFirst() {
final DummyFileInputFormat format = new DummyFileInputFormat();
Path[] paths = format.getFilePaths();
- Assert.assertNotNull("Paths should not be null.", paths);
- Assert.assertEquals("Paths size should be 0.", 0, paths.length);
+ assertThat(paths).as("Paths should not be null.").isNotNull();
+ assertThat(paths).as("Paths should be empty.").isEmpty();
}
@Test
- public void testToStringWithoutPathSet() {
+ void testToStringWithoutPathSet() {
final DummyFileInputFormat format = new DummyFileInputFormat();
- Assert.assertEquals(
- "The toString() should be correct.",
- "File Input (unknown file)",
- format.toString());
+ assertThat(format.toString())
+ .as("The toString() should be correct.")
+ .isEqualTo("File Input (unknown file)");
}
- @Test(expected = IllegalArgumentException.class)
- public void testSetPathsNull() {
- final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
- format.setFilePaths((String) null);
+ @Test
+ void testSetPathsNull() {
+ assertThatThrownBy(() -> new MultiDummyFileInputFormat().setFilePaths((String) null))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testSetPathNullString() {
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath((String) null);
+ @Test
+ void testSetPathNullString() {
+ assertThatThrownBy(() -> new DummyFileInputFormat().setFilePath((String) null))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testSetPathNullPath() {
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath((Path) null);
+ @Test
+ void testSetPathNullPath() {
+ assertThatThrownBy(() -> new DummyFileInputFormat().setFilePath((Path) null))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testSetPathsOnePathNull() {
- final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
- format.setFilePaths("/an/imaginary/path", null);
+ @Test
+ void testSetPathsOnePathNull() {
+ assertThatThrownBy(
+ () ->
+ new MultiDummyFileInputFormat()
+ .setFilePaths("/an/imaginary/path", null))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testSetPathsEmptyArray() {
- final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
- format.setFilePaths(new String[0]);
+ @Test
+ void testSetPathsEmptyArray() {
+ assertThatThrownBy(() -> new MultiDummyFileInputFormat().setFilePaths(new String[0]))
+ .isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testSetPath() {
+ void testSetPath() {
final DummyFileInputFormat format = new DummyFileInputFormat();
format.setFilePath("/some/imaginary/path");
- Assert.assertEquals(format.getFilePath().toString(), "/some/imaginary/path");
+ assertThat("/some/imaginary/path").isEqualTo(format.getFilePath().toString());
}
@Test
- public void testSetPathOnMulti() {
+ void testSetPathOnMulti() {
final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
final String myPath = "/an/imaginary/path";
format.setFilePath(myPath);
final Path[] filePaths = format.getFilePaths();
- Assert.assertEquals(1, filePaths.length);
- Assert.assertEquals(myPath, filePaths[0].toUri().toString());
+ assertThat(filePaths).hasSize(1);
+ assertThat(filePaths[0].toUri().toString()).isEqualTo(myPath);
// ensure backwards compatibility
- Assert.assertEquals(myPath, format.filePath.toUri().toString());
+ assertThat(format.filePath.toUri().toString()).isEqualTo(myPath);
}
@Test
- public void testSetPathsSingleWithMulti() {
+ void testSetPathsSingleWithMulti() {
final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
final String myPath = "/an/imaginary/path";
format.setFilePaths(myPath);
final Path[] filePaths = format.getFilePaths();
- Assert.assertEquals(1, filePaths.length);
- Assert.assertEquals(myPath, filePaths[0].toUri().toString());
+ assertThat(filePaths).hasSize(1);
+ assertThat(filePaths[0].toUri().toString()).isEqualTo(myPath);
// ensure backwards compatibility
- Assert.assertEquals(myPath, format.filePath.toUri().toString());
+ assertThat(format.filePath.toUri().toString()).isEqualTo(myPath);
}
@Test
- public void testSetPathsMulti() {
+ void testSetPathsMulti() {
final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
final String myPath = "/an/imaginary/path";
final String myPath2 = "/an/imaginary/path2";
@@ -150,57 +156,64 @@ public class FileInputFormatTest {
format.setFilePaths(myPath, myPath2);
final Path[] filePaths = format.getFilePaths();
- Assert.assertEquals(2, filePaths.length);
- Assert.assertEquals(myPath, filePaths[0].toUri().toString());
- Assert.assertEquals(myPath2, filePaths[1].toUri().toString());
+ assertThat(filePaths).hasSize(2);
+ assertThat(filePaths[0].toUri().toString()).isEqualTo(myPath);
+ assertThat(filePaths[1].toUri().toString()).isEqualTo(myPath2);
}
- @Test(expected = UnsupportedOperationException.class)
- public void testMultiPathSetOnSinglePathIF() {
+ @Test
+ void testMultiPathSetOnSinglePathIF() {
final DummyFileInputFormat format = new DummyFileInputFormat();
final String myPath = "/an/imaginary/path";
final String myPath2 = "/an/imaginary/path2";
- format.setFilePaths(myPath, myPath2);
+ assertThatThrownBy(() -> format.setFilePaths(myPath, myPath2))
+ .isInstanceOf(UnsupportedOperationException.class);
}
- @Test(expected = UnsupportedOperationException.class)
- public void testMultiPathSetOnSinglePathIF2() {
+ @Test
+ void testMultiPathSetOnSinglePathIF2() {
final DummyFileInputFormat format = new DummyFileInputFormat();
final String myPath = "/an/imaginary/path";
final String myPath2 = "/an/imaginary/path2";
- format.setFilePaths(new Path(myPath), new Path(myPath2));
+ // format.setFilePaths(new Path(myPath), new Path(myPath2));
+ assertThatThrownBy(() -> format.setFilePaths(new Path(myPath), new Path(myPath2)))
+ .isInstanceOf(UnsupportedOperationException.class);
}
- @Test(expected = UnsupportedOperationException.class)
- public void testSinglePathGetOnMultiPathIF() {
+ @Test
+ void testSinglePathGetOnMultiPathIF() {
final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
final String myPath = "/an/imaginary/path";
final String myPath2 = "/an/imaginary/path2";
format.setFilePaths(myPath, myPath2);
- format.getFilePath();
+ assertThatThrownBy(format::getFilePath).isInstanceOf(UnsupportedOperationException.class);
}
@Test
- public void testSetFileViaConfiguration() {
+ void testSetFileViaConfiguration() {
final DummyFileInputFormat format = new DummyFileInputFormat();
final String filePath = "file:///some/none/existing/directory/";
Configuration conf = new Configuration();
conf.setString("input.file.path", filePath);
format.configure(conf);
- Assert.assertEquals("Paths should be equal.", new Path(filePath), format.getFilePath());
+ assertThat(format.getFilePath()).isEqualTo(new Path(filePath));
}
- @Test(expected = RuntimeException.class)
- public void testSetFileViaConfigurationEmptyPath() {
- final DummyFileInputFormat format = new DummyFileInputFormat();
- final String filePath = null;
- Configuration conf = new Configuration();
- conf.setString("input.file.path", filePath);
- format.configure(conf);
+ @Test
+ void testSetFileViaConfigurationEmptyPath() {
+ assertThatThrownBy(
+ () -> {
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ final String filePath = null;
+ Configuration conf = new Configuration();
+ conf.setString("input.file.path", filePath);
+ format.configure(conf);
+ })
+ .isInstanceOf(RuntimeException.class);
}
// ------------------------------------------------------------------------
@@ -208,25 +221,25 @@ public class FileInputFormatTest {
// ------------------------------------------------------------------------
@Test
- public void testCreateInputSplitSingleFile() throws IOException {
+ void testCreateInputSplitSingleFile() throws IOException {
String tempFile = TestFileUtils.createTempFile("Hello World");
- FileInputFormat fif = new DummyFileInputFormat();
+ FileInputFormat<IntValue> fif = new DummyFileInputFormat();
fif.setFilePath(tempFile);
fif.configure(new Configuration());
FileInputSplit[] splits = fif.createInputSplits(2);
- Assert.assertEquals(2, splits.length);
- Assert.assertEquals(tempFile, splits[0].getPath().toString());
- Assert.assertEquals(tempFile, splits[1].getPath().toString());
+ assertThat(splits).hasSize(2);
+ assertThat(splits[0].getPath().toString()).isEqualTo(tempFile);
+ assertThat(splits[1].getPath().toString()).isEqualTo(tempFile);
}
@Test
- public void testCreateInputSplitMultiFiles() throws IOException {
+ void testCreateInputSplitMultiFiles() throws IOException {
String tempFile1 = TestFileUtils.createTempFile(21);
String tempFile2 = TestFileUtils.createTempFile(22);
String tempFile3 = TestFileUtils.createTempFile(23);
- FileInputFormat fif = new MultiDummyFileInputFormat();
+ FileInputFormat<IntValue> fif = new MultiDummyFileInputFormat();
fif.setFilePaths(tempFile1, tempFile2, tempFile3);
fif.configure(new Configuration());
@@ -236,26 +249,26 @@ public class FileInputFormatTest {
int numSplitsFile2 = 0;
int numSplitsFile3 = 0;
- Assert.assertEquals(3, splits.length);
+ assertThat(splits).hasSize(3);
for (FileInputSplit fis : splits) {
- Assert.assertEquals(0, fis.getStart());
+ assertThat(fis.getStart()).isZero();
if (fis.getPath().toString().equals(tempFile1)) {
numSplitsFile1++;
- Assert.assertEquals(21, fis.getLength());
+ assertThat(fis.getLength()).isEqualTo(21);
} else if (fis.getPath().toString().equals(tempFile2)) {
numSplitsFile2++;
- Assert.assertEquals(22, fis.getLength());
+ assertThat(fis.getLength()).isEqualTo(22);
} else if (fis.getPath().toString().equals(tempFile3)) {
numSplitsFile3++;
- Assert.assertEquals(23, fis.getLength());
+ assertThat(fis.getLength()).isEqualTo(23);
} else {
- Assert.fail("Got split for unknown file.");
+ fail("Got split for unknown file.");
}
}
- Assert.assertEquals(1, numSplitsFile1);
- Assert.assertEquals(1, numSplitsFile2);
- Assert.assertEquals(1, numSplitsFile3);
+ assertThat(numSplitsFile1).isOne();
+ assertThat(numSplitsFile2).isOne();
+ assertThat(numSplitsFile3).isOne();
}
// ------------------------------------------------------------------------
@@ -263,221 +276,195 @@ public class FileInputFormatTest {
// ------------------------------------------------------------------------
@Test
- public void testGetStatisticsNonExistingFile() {
- try {
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath("file:///some/none/existing/directory/");
- format.configure(new Configuration());
+ void testGetStatisticsNonExistingFile() throws IOException {
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertNull("The file statistics should be null.", stats);
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath("file:///some/none/existing/directory/");
+ format.configure(new Configuration());
+
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(stats).as("The file statistics should be null.").isNull();
}
@Test
- public void testGetStatisticsOneFileNoCachedVersion() {
- try {
- final long SIZE = 1024 * 500;
- String tempFile = TestFileUtils.createTempFile(SIZE);
+ void testGetStatisticsOneFileNoCachedVersion() throws IOException {
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
+ final long SIZE = 1024 * 500;
+ String tempFile = TestFileUtils.createTempFile(SIZE);
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.", SIZE, stats.getTotalInputSize());
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(SIZE);
}
@Test
- public void testGetStatisticsMultipleFilesNoCachedVersion() {
- try {
- final long SIZE1 = 2077;
- final long SIZE2 = 31909;
- final long SIZE3 = 10;
- final long TOTAL = SIZE1 + SIZE2 + SIZE3;
+ void testGetStatisticsMultipleFilesNoCachedVersion() throws IOException {
- String tempDir =
- TestFileUtils.createTempFileDir(
- temporaryFolder.newFolder(), SIZE1, SIZE2, SIZE3);
+ final long SIZE1 = 2077;
+ final long SIZE2 = 31909;
+ final long SIZE3 = 10;
+ final long TOTAL = SIZE1 + SIZE2 + SIZE3;
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(tempDir);
- format.configure(new Configuration());
+ String tempDir =
+ TestFileUtils.createTempFileDir(
+ TempDirUtils.newFolder(temporaryFolder), SIZE1, SIZE2, SIZE3);
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- TOTAL,
- stats.getTotalInputSize());
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(tempDir);
+ format.configure(new Configuration());
+
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(TOTAL);
}
@Test
- public void testGetStatisticsOneFileWithCachedVersion() {
- try {
- final long SIZE = 50873;
- final long FAKE_SIZE = 10065;
-
- String tempFile = TestFileUtils.createTempFile(SIZE);
-
- DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
-
- FileBaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.", SIZE, stats.getTotalInputSize());
-
- format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
-
- FileBaseStatistics newStats = format.getStatistics(stats);
- Assert.assertTrue("Statistics object was changed", newStats == stats);
-
- // insert fake stats with the correct modification time. the call should return the fake
- // stats
- format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
-
- FileBaseStatistics fakeStats =
- new FileBaseStatistics(
- stats.getLastModificationTime(),
- FAKE_SIZE,
- BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
- BaseStatistics latest = format.getStatistics(fakeStats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- FAKE_SIZE,
- latest.getTotalInputSize());
-
- // insert fake stats with the expired modification time. the call should return new
- // accurate stats
- format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
-
- FileBaseStatistics outDatedFakeStats =
- new FileBaseStatistics(
- stats.getLastModificationTime() - 1,
- FAKE_SIZE,
- BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
- BaseStatistics reGathered = format.getStatistics(outDatedFakeStats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- SIZE,
- reGathered.getTotalInputSize());
-
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testGetStatisticsOneFileWithCachedVersion() throws IOException {
+
+ final long SIZE = 50873;
+ final long FAKE_SIZE = 10065;
+
+ String tempFile = TestFileUtils.createTempFile(SIZE);
+
+ DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+
+ FileBaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(SIZE);
+
+ format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+
+ FileBaseStatistics newStats = format.getStatistics(stats);
+ assertThat(stats).as("Statistics object was changed").isSameAs(newStats);
+
+ // insert fake stats with the correct modification time. the call should return the fake
+ // stats
+ format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+
+ FileBaseStatistics fakeStats =
+ new FileBaseStatistics(
+ stats.getLastModificationTime(),
+ FAKE_SIZE,
+ BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
+ BaseStatistics latest = format.getStatistics(fakeStats);
+ assertThat(latest.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(FAKE_SIZE);
+
+ // insert fake stats with the expired modification time. the call should return new
+ // accurate stats
+ format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+
+ FileBaseStatistics outDatedFakeStats =
+ new FileBaseStatistics(
+ stats.getLastModificationTime() - 1,
+ FAKE_SIZE,
+ BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
+ BaseStatistics reGathered = format.getStatistics(outDatedFakeStats);
+ assertThat(reGathered.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(SIZE);
}
@Test
- public void testGetStatisticsMultipleFilesWithCachedVersion() {
- try {
- FileSystem fs = FileSystem.getLocalFileSystem();
-
- final long SIZE1 = 2077;
- final long SIZE2 = 31909;
- final long SIZE3 = 10;
- final long TOTAL = SIZE1 + SIZE2 + SIZE3;
- final long FAKE_SIZE = 10065;
-
- File tempDirFile = temporaryFolder.newFolder();
- String tempDir = tempDirFile.getAbsolutePath();
- String f1 = TestFileUtils.createTempFileInDirectory(tempDir, SIZE1);
- long modTime1 = fs.getFileStatus(new Path(f1)).getModificationTime();
- String f2 = TestFileUtils.createTempFileInDirectory(tempDir, SIZE2);
- long modTime2 = fs.getFileStatus(new Path(f2)).getModificationTime();
- String f3 = TestFileUtils.createTempFileInDirectory(tempDir, SIZE3);
- long modTime3 = fs.getFileStatus(new Path(f3)).getModificationTime();
-
- DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(tempDir);
- format.configure(new Configuration());
-
- FileBaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- TOTAL,
- stats.getTotalInputSize());
-
- format = new DummyFileInputFormat();
- format.setFilePath(tempDir);
- format.configure(new Configuration());
-
- FileBaseStatistics newStats = format.getStatistics(stats);
- Assert.assertTrue("Statistics object was changed", newStats == stats);
-
- // insert fake stats with the correct modification time. the call should return the fake
- // stats
- format = new DummyFileInputFormat();
- format.setFilePath(tempDir);
- format.configure(new Configuration());
-
- FileBaseStatistics fakeStats =
- new FileBaseStatistics(
- stats.getLastModificationTime(),
- FAKE_SIZE,
- BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
- BaseStatistics latest = format.getStatistics(fakeStats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- FAKE_SIZE,
- latest.getTotalInputSize());
-
- // insert fake stats with the correct modification time. the call should return the fake
- // stats
- format = new DummyFileInputFormat();
- format.setFilePath(tempDir);
- format.configure(new Configuration());
-
- FileBaseStatistics outDatedFakeStats =
- new FileBaseStatistics(
- Math.min(Math.min(modTime1, modTime2), modTime3) - 1,
- FAKE_SIZE,
- BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
- BaseStatistics reGathered = format.getStatistics(outDatedFakeStats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- TOTAL,
- reGathered.getTotalInputSize());
-
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
- }
+ void testGetStatisticsMultipleFilesWithCachedVersion() throws IOException {
+
+ FileSystem fs = FileSystem.getLocalFileSystem();
+
+ final long SIZE1 = 2077;
+ final long SIZE2 = 31909;
+ final long SIZE3 = 10;
+ final long TOTAL = SIZE1 + SIZE2 + SIZE3;
+ final long FAKE_SIZE = 10065;
+
+ File tempDirFile = TempDirUtils.newFolder(temporaryFolder);
+ String tempDir = tempDirFile.getAbsolutePath();
+ String f1 = TestFileUtils.createTempFileInDirectory(tempDir, SIZE1);
+ long modTime1 = fs.getFileStatus(new Path(f1)).getModificationTime();
+ String f2 = TestFileUtils.createTempFileInDirectory(tempDir, SIZE2);
+ long modTime2 = fs.getFileStatus(new Path(f2)).getModificationTime();
+ String f3 = TestFileUtils.createTempFileInDirectory(tempDir, SIZE3);
+ long modTime3 = fs.getFileStatus(new Path(f3)).getModificationTime();
+
+ DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(tempDir);
+ format.configure(new Configuration());
+
+ FileBaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(TOTAL);
+
+ format = new DummyFileInputFormat();
+ format.setFilePath(tempDir);
+ format.configure(new Configuration());
+
+ FileBaseStatistics newStats = format.getStatistics(stats);
+ assertThat(stats).as("Statistics object was changed").isSameAs(newStats);
+
+ // insert fake stats with the correct modification time. the call should return the fake
+ // stats
+ format = new DummyFileInputFormat();
+ format.setFilePath(tempDir);
+ format.configure(new Configuration());
+
+ FileBaseStatistics fakeStats =
+ new FileBaseStatistics(
+ stats.getLastModificationTime(),
+ FAKE_SIZE,
+ BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
+ BaseStatistics latest = format.getStatistics(fakeStats);
+ assertThat(latest.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(FAKE_SIZE);
+
+ // insert fake stats with the correct modification time. the call should return the fake
+ // stats
+ format = new DummyFileInputFormat();
+ format.setFilePath(tempDir);
+ format.configure(new Configuration());
+
+ FileBaseStatistics outDatedFakeStats =
+ new FileBaseStatistics(
+ Math.min(Math.min(modTime1, modTime2), modTime3) - 1,
+ FAKE_SIZE,
+ BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
+ BaseStatistics reGathered = format.getStatistics(outDatedFakeStats);
+ assertThat(reGathered.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(TOTAL);
}
// -- Multiple Files -- //
@Test
- public void testGetStatisticsMultipleNonExistingFile() throws IOException {
+ void testGetStatisticsMultipleNonExistingFile() throws IOException {
final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
format.setFilePaths(
"file:///some/none/existing/directory/", "file:///another/non/existing/directory/");
format.configure(new Configuration());
BaseStatistics stats = format.getStatistics(null);
- Assert.assertNull("The file statistics should be null.", stats);
+ assertThat(stats).as("The file statistics should be null.").isNull();
}
@Test
- public void testGetStatisticsMultipleOneFileNoCachedVersion() throws IOException {
+ void testGetStatisticsMultipleOneFileNoCachedVersion() throws IOException {
final long size1 = 1024 * 500;
String tempFile = TestFileUtils.createTempFile(size1);
@@ -491,42 +478,42 @@ public class FileInputFormatTest {
format.configure(new Configuration());
BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- totalSize,
- stats.getTotalInputSize());
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(totalSize);
}
@Test
- public void testGetStatisticsMultipleFilesMultiplePathsNoCachedVersion() throws IOException {
+ void testGetStatisticsMultipleFilesMultiplePathsNoCachedVersion() throws IOException {
final long size1 = 2077;
final long size2 = 31909;
final long size3 = 10;
final long totalSize123 = size1 + size2 + size3;
String tempDir =
- TestFileUtils.createTempFileDir(temporaryFolder.newFolder(), size1, size2, size3);
+ TestFileUtils.createTempFileDir(
+ TempDirUtils.newFolder(temporaryFolder), size1, size2, size3);
final long size4 = 2051;
final long size5 = 31902;
final long size6 = 15;
final long totalSize456 = size4 + size5 + size6;
String tempDir2 =
- TestFileUtils.createTempFileDir(temporaryFolder.newFolder(), size4, size5, size6);
+ TestFileUtils.createTempFileDir(
+ TempDirUtils.newFolder(temporaryFolder), size4, size5, size6);
final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat();
format.setFilePaths(tempDir, tempDir2);
format.configure(new Configuration());
BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- totalSize123 + totalSize456,
- stats.getTotalInputSize());
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(totalSize123 + totalSize456);
}
@Test
- public void testGetStatisticsMultipleOneFileWithCachedVersion() throws IOException {
+ void testGetStatisticsMultipleOneFileWithCachedVersion() throws IOException {
FileSystem fs = FileSystem.getLocalFileSystem();
final long size1 = 50873;
@@ -545,17 +532,16 @@ public class FileInputFormatTest {
format.configure(new Configuration());
FileBaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- sizeTotal,
- stats.getTotalInputSize());
+ assertThat(stats.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(sizeTotal);
format = new MultiDummyFileInputFormat();
format.setFilePath(tempFile1);
format.configure(new Configuration());
FileBaseStatistics newStats = format.getStatistics(stats);
- Assert.assertTrue("Statistics object was changed", newStats == stats);
+ assertThat(stats).as("Statistics object was changed").isSameAs(newStats);
// insert fake stats with the correct modification time. the call should return the fake
// stats
@@ -569,10 +555,9 @@ public class FileInputFormatTest {
fakeSize,
BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
BaseStatistics latest = format.getStatistics(fakeStats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- fakeSize,
- latest.getTotalInputSize());
+ assertThat(latest.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(fakeSize);
// insert fake stats with the expired modification time. the call should return new accurate
// stats
@@ -586,10 +571,9 @@ public class FileInputFormatTest {
fakeSize,
BaseStatistics.AVG_RECORD_BYTES_UNKNOWN);
BaseStatistics reGathered = format.getStatistics(outDatedFakeStats);
- Assert.assertEquals(
- "The file size from the statistics is wrong.",
- sizeTotal,
- reGathered.getTotalInputSize());
+ assertThat(reGathered.getTotalInputSize())
+ .as("The file size from the statistics is wrong.")
+ .isEqualTo(sizeTotal);
}
// ------------------------------------------------------------------------
@@ -603,55 +587,52 @@ public class FileInputFormatTest {
* split has to start from the beginning.
*/
@Test
- public void testFileInputFormatWithCompression() {
- try {
- String tempFile =
- TestFileUtils.createTempFileDirForProvidedFormats(
- temporaryFolder.newFolder(),
- FileInputFormat.getSupportedCompressionFormats());
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
- FileInputSplit[] splits = format.createInputSplits(2);
- final Set<String> supportedCompressionFormats =
- FileInputFormat.getSupportedCompressionFormats();
- Assert.assertEquals(supportedCompressionFormats.size(), splits.length);
- for (FileInputSplit split : splits) {
- Assert.assertEquals(
- FileInputFormat.READ_WHOLE_SPLIT_FLAG,
- split.getLength()); // unsplittable compressed files have this size as a
- // flag for "read whole file"
- Assert.assertEquals(0L, split.getStart()); // always read from the beginning.
- }
+ void testFileInputFormatWithCompression() throws IOException {
- // test if this also works for "mixed" directories
- TestFileUtils.createTempFileInDirectory(
- tempFile.replace("file:", ""),
- "this creates a test file with a random extension (at least not .deflate)");
-
- final DummyFileInputFormat formatMixed = new DummyFileInputFormat();
- formatMixed.setFilePath(tempFile);
- formatMixed.configure(new Configuration());
- FileInputSplit[] splitsMixed = formatMixed.createInputSplits(2);
- Assert.assertEquals(supportedCompressionFormats.size() + 1, splitsMixed.length);
- for (FileInputSplit split : splitsMixed) {
- final String extension =
- FileInputFormat.extractFileExtension(split.getPath().getName());
- if (supportedCompressionFormats.contains(extension)) {
- Assert.assertEquals(
- FileInputFormat.READ_WHOLE_SPLIT_FLAG,
- split.getLength()); // unsplittable compressed files have this size as a
- // flag for "read whole file"
- Assert.assertEquals(0L, split.getStart()); // always read from the beginning.
- } else {
- Assert.assertEquals(0L, split.getStart());
- Assert.assertTrue("split size not correct", split.getLength() > 0);
- }
- }
+ String tempFile =
+ TestFileUtils.createTempFileDirForProvidedFormats(
+ TempDirUtils.newFolder(temporaryFolder),
+ FileInputFormat.getSupportedCompressionFormats());
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+ FileInputSplit[] splits = format.createInputSplits(2);
+ final Set<String> supportedCompressionFormats =
+ FileInputFormat.getSupportedCompressionFormats();
+ assertThat(splits).hasSameSizeAs(supportedCompressionFormats);
+ for (FileInputSplit split : splits) {
+ assertThat(split.getLength())
+ .isEqualTo(
+ FileInputFormat.READ_WHOLE_SPLIT_FLAG); // unsplittable compressed files
+ // have this size as a
+ // flag for "read whole file"
+ assertThat(split.getStart()).isZero(); // always read from the beginning.
+ }
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
+ // test if this also works for "mixed" directories
+ TestFileUtils.createTempFileInDirectory(
+ tempFile.replace("file:", ""),
+ "this creates a test file with a random extension (at least not .deflate)");
+
+ final DummyFileInputFormat formatMixed = new DummyFileInputFormat();
+ formatMixed.setFilePath(tempFile);
+ formatMixed.configure(new Configuration());
+ FileInputSplit[] splitsMixed = formatMixed.createInputSplits(2);
+ assertThat(splitsMixed).hasSize(supportedCompressionFormats.size() + 1);
+ for (FileInputSplit split : splitsMixed) {
+ final String extension =
+ FileInputFormat.extractFileExtension(split.getPath().getName());
+ if (supportedCompressionFormats.contains(extension)) {
+ assertThat(split.getLength())
+ .isEqualTo(
+ FileInputFormat.READ_WHOLE_SPLIT_FLAG); // unsplittable compressed
+ // files have this size as a
+ // flag for "read whole file"
+ assertThat(split.getStart()).isZero(); // always read from the beginning.
+ } else {
+ assertThat(split.getStart()).isEqualTo(0L);
+ assertThat(split.getLength() > 0).as("split size not correct").isTrue();
+ }
}
}
@@ -662,35 +643,32 @@ public class FileInputFormatTest {
* split is not the compressed file size and that the compression decorator is called.
*/
@Test
- public void testFileInputFormatWithCompressionFromFileSource() {
- try {
- String tempFile =
- TestFileUtils.createTempFileDirForProvidedFormats(
- temporaryFolder.newFolder(),
- FileInputFormat.getSupportedCompressionFormats());
- DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(tempFile);
- format.configure(new Configuration());
-
- // manually create a FileInputSplit per file as FileSource would do
- // see org.apache.flink.connector.file.table.DeserializationSchemaAdapter.Reader()
- List<FileInputSplit> splits = manuallyCreateSplits(tempFile);
- final Set<String> supportedCompressionFormats =
- FileInputFormat.getSupportedCompressionFormats();
- // one file per compression format, one split per file
- Assert.assertEquals(supportedCompressionFormats.size(), splits.size());
- for (FileInputSplit split : splits) {
- Assert.assertEquals(0L, split.getStart()); // always read from the beginning.
- format.open(split);
- Assert.assertTrue(format.compressedRead);
- Assert.assertEquals(
- FileInputFormat.READ_WHOLE_SPLIT_FLAG,
- format.getSplitLength()); // unsplittable compressed files have this size
- // as flag for "read whole file"
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- Assert.fail(ex.getMessage());
+ void testFileInputFormatWithCompressionFromFileSource() throws IOException {
+
+ String tempFile =
+ TestFileUtils.createTempFileDirForProvidedFormats(
+ TempDirUtils.newFolder(temporaryFolder),
+ FileInputFormat.getSupportedCompressionFormats());
+ DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(tempFile);
+ format.configure(new Configuration());
+
+ // manually create a FileInputSplit per file as FileSource would do
+ // see org.apache.flink.connector.file.table.DeserializationSchemaAdapter.Reader()
+ List<FileInputSplit> splits = manuallyCreateSplits(tempFile);
+ final Set<String> supportedCompressionFormats =
+ FileInputFormat.getSupportedCompressionFormats();
+ // one file per compression format, one split per file
+ assertThat(splits).hasSameSizeAs(supportedCompressionFormats);
+ for (FileInputSplit split : splits) {
+ assertThat(split.getStart()).isZero(); // always read from the beginning.
+ format.open(split);
+ assertThat(format.compressedRead).isTrue();
+ assertThat(format.getSplitLength())
+ .isEqualTo(
+ FileInputFormat.READ_WHOLE_SPLIT_FLAG); // unsplittable compressed files
+ // have this size
+ // as flag for "read whole file"
}
}
@@ -715,98 +693,89 @@ public class FileInputFormatTest {
// ------------------------------------------------------------------------
@Test
- public void testIgnoredUnderscoreFiles() {
- try {
- final String contents = "CONTENTS";
+ void testIgnoredUnderscoreFiles() throws IOException {
- // create some accepted, some ignored files
+ final String contents = "CONTENTS";
- File child1 = temporaryFolder.newFile("dataFile1.txt");
- File child2 = temporaryFolder.newFile("another_file.bin");
- File luigiFile = temporaryFolder.newFile("_luigi");
- File success = temporaryFolder.newFile("_SUCCESS");
+ // create some accepted, some ignored files
- createTempFiles(
- contents.getBytes(ConfigConstants.DEFAULT_CHARSET),
- child1,
- child2,
- luigiFile,
- success);
+ File child1 = TempDirUtils.newFile(temporaryFolder, "dataFile1.txt");
+ File child2 = TempDirUtils.newFile(temporaryFolder, "another_file.bin");
+ File luigiFile = TempDirUtils.newFile(temporaryFolder, "_luigi");
+ File success = TempDirUtils.newFile(temporaryFolder, "_SUCCESS");
- // test that only the valid files are accepted
+ createTempFiles(
+ contents.getBytes(ConfigConstants.DEFAULT_CHARSET),
+ child1,
+ child2,
+ luigiFile,
+ success);
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(temporaryFolder.getRoot().toURI().toString());
- format.configure(new Configuration());
- FileInputSplit[] splits = format.createInputSplits(1);
+ // test that only the valid files are accepted
- Assert.assertEquals(2, splits.length);
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(temporaryFolder.toFile().getPath());
+ format.configure(new Configuration());
+ FileInputSplit[] splits = format.createInputSplits(1);
- final URI uri1 = splits[0].getPath().toUri();
- final URI uri2 = splits[1].getPath().toUri();
+ assertThat(splits).hasSize(2);
- final URI childUri1 = child1.toURI();
- final URI childUri2 = child2.toURI();
+ final URI uri1 = splits[0].getPath().toUri();
+ final URI uri2 = splits[1].getPath().toUri();
- Assert.assertTrue(
- (uri1.equals(childUri1) && uri2.equals(childUri2))
- || (uri1.equals(childUri2) && uri2.equals(childUri1)));
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ final URI childUri1 = child1.toURI();
+ final URI childUri2 = child2.toURI();
+
+ assertThat(
+ (uri1.equals(childUri1) && uri2.equals(childUri2))
+ || (uri1.equals(childUri2) && uri2.equals(childUri1)))
+ .isTrue();
}
@Test
- public void testExcludeFiles() {
- try {
- final String contents = "CONTENTS";
+ void testExcludeFiles() throws IOException {
- // create some accepted, some ignored files
+ final String contents = "CONTENTS";
- File child1 = temporaryFolder.newFile("dataFile1.txt");
- File child2 = temporaryFolder.newFile("another_file.bin");
+ // create some accepted, some ignored files
- File[] files = {child1, child2};
+ File child1 = TempDirUtils.newFile(temporaryFolder, "dataFile1.txt");
+ File child2 = TempDirUtils.newFile(temporaryFolder, "another_file.bin");
- createTempFiles(contents.getBytes(ConfigConstants.DEFAULT_CHARSET), files);
+ File[] files = {child1, child2};
- // test that only the valid files are accepted
+ createTempFiles(contents.getBytes(ConfigConstants.DEFAULT_CHARSET), files);
- Configuration configuration = new Configuration();
+ // test that only the valid files are accepted
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(temporaryFolder.getRoot().toURI().toString());
- format.configure(configuration);
- format.setFilesFilter(
- new GlobFilePathFilter(
- Collections.singletonList("**"),
- Collections.singletonList("**/another_file.bin")));
- FileInputSplit[] splits = format.createInputSplits(1);
+ Configuration configuration = new Configuration();
- Assert.assertEquals(1, splits.length);
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(temporaryFolder.toFile().getPath());
+ format.configure(configuration);
+ format.setFilesFilter(
+ new GlobFilePathFilter(
+ Collections.singletonList("**"),
+ Collections.singletonList("**/another_file.bin")));
+ FileInputSplit[] splits = format.createInputSplits(1);
- final URI uri1 = splits[0].getPath().toUri();
+ assertThat(splits).hasSize(1);
- final URI childUri1 = child1.toURI();
+ final URI uri1 = splits[0].getPath().toUri();
- Assert.assertEquals(uri1, childUri1);
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ final URI childUri1 = child1.toURI();
+
+ assertThat(childUri1).isEqualTo(uri1);
}
@Test
- public void testReadMultiplePatterns() throws Exception {
+ void testReadMultiplePatterns() throws Exception {
final String contents = "CONTENTS";
// create some accepted, some ignored files
- File child1 = temporaryFolder.newFile("dataFile1.txt");
- File child2 = temporaryFolder.newFile("another_file.bin");
+ File child1 = TempDirUtils.newFile(temporaryFolder, "dataFile1.txt");
+ File child2 = TempDirUtils.newFile(temporaryFolder, "another_file.bin");
createTempFiles(contents.getBytes(ConfigConstants.DEFAULT_CHARSET), child1, child2);
// test that only the valid files are accepted
@@ -814,7 +783,7 @@ public class FileInputFormatTest {
Configuration configuration = new Configuration();
final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(temporaryFolder.getRoot().toURI().toString());
+ format.setFilePath(temporaryFolder.toFile().getPath());
format.configure(configuration);
format.setFilesFilter(
new GlobFilePathFilter(
@@ -822,35 +791,30 @@ public class FileInputFormatTest {
Arrays.asList("**/another_file.bin", "**/dataFile1.txt")));
FileInputSplit[] splits = format.createInputSplits(1);
- Assert.assertEquals(0, splits.length);
+ assertThat(splits.length).isZero();
}
@Test
- public void testGetStatsIgnoredUnderscoreFiles() {
- try {
- final int SIZE = 2048;
- final long TOTAL = 2 * SIZE;
+ void testGetStatsIgnoredUnderscoreFiles() throws IOException {
- // create two accepted and two ignored files
- File child1 = temporaryFolder.newFile("dataFile1.txt");
- File child2 = temporaryFolder.newFile("another_file.bin");
- File luigiFile = temporaryFolder.newFile("_luigi");
- File success = temporaryFolder.newFile("_SUCCESS");
+ final int SIZE = 2048;
+ final long TOTAL = 2 * SIZE;
- createTempFiles(new byte[SIZE], child1, child2, luigiFile, success);
+ // create two accepted and two ignored files
+ File child1 = TempDirUtils.newFile(temporaryFolder, "dataFile1.txt");
+ File child2 = TempDirUtils.newFile(temporaryFolder, "another_file.bin");
+ File luigiFile = TempDirUtils.newFile(temporaryFolder, "_luigi");
+ File success = TempDirUtils.newFile(temporaryFolder, "_SUCCESS");
- final DummyFileInputFormat format = new DummyFileInputFormat();
- format.setFilePath(temporaryFolder.getRoot().toURI().toString());
- format.configure(new Configuration());
+ createTempFiles(new byte[SIZE], child1, child2, luigiFile, success);
- // check that only valid files are used for statistics computation
- BaseStatistics stats = format.getStatistics(null);
- Assert.assertEquals(TOTAL, stats.getTotalInputSize());
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ final DummyFileInputFormat format = new DummyFileInputFormat();
+ format.setFilePath(temporaryFolder.toFile().getPath());
+ format.configure(new Configuration());
+
+ // check that only valid files are used for statistics computation
+ BaseStatistics stats = format.getStatistics(null);
+ assertThat(stats.getTotalInputSize()).isEqualTo(TOTAL);
}
// ------------------------------------------------------------------------
@@ -858,7 +822,7 @@ public class FileInputFormatTest {
// ------------------------------------------------------------------------
@Test
- public void testDecorateInputStream() throws IOException {
+ void testDecorateInputStream() throws IOException {
// create temporary file with 3 blocks
final File tempFile = File.createTempFile("input-stream-decoration-test", "tmp");
tempFile.deleteOnExit();
@@ -886,7 +850,7 @@ public class FileInputFormatTest {
inputFormat.open(inputSplit);
while (!inputFormat.reachedEnd()) {
if ((bytes = inputFormat.nextRecord(bytes)) != null) {
- Assert.assertArrayEquals(new byte[] {--prev}, bytes);
+ assertThat(bytes).isEqualTo(new byte[] {--prev});
}
}
}
@@ -900,11 +864,9 @@ public class FileInputFormatTest {
for (File child : files) {
child.deleteOnExit();
- BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(child));
- try {
+ try (BufferedOutputStream out =
+ new BufferedOutputStream(Files.newOutputStream(child.toPath()))) {
out.write(contents);
- } finally {
- out.close();
}
}
}
@@ -914,12 +876,12 @@ public class FileInputFormatTest {
private boolean compressedRead = false;
@Override
- public boolean reachedEnd() throws IOException {
+ public boolean reachedEnd() {
return true;
}
@Override
- public IntValue nextRecord(IntValue record) throws IOException {
+ public IntValue nextRecord(IntValue record) {
return null;
}
@@ -931,7 +893,7 @@ public class FileInputFormatTest {
@Override
protected FSDataInputStream decorateInputStream(
- FSDataInputStream inputStream, FileInputSplit fileSplit) throws Throwable {
+ FSDataInputStream inputStream, FileInputSplit fileSplit) {
compressedRead =
getInflaterInputStreamFactory(
extractFileExtension(fileSplit.getPath().getName()))
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/FileOutputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/FileOutputFormatTest.java
index 5ec6fcc32f0..d3c9ccd29d6 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/FileOutputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/FileOutputFormatTest.java
@@ -24,18 +24,18 @@ import org.apache.flink.core.fs.FileSystem.WriteMode;
import org.apache.flink.core.fs.Path;
import org.apache.flink.types.IntValue;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class FileOutputFormatTest {
+class FileOutputFormatTest {
@Test
- public void testCreateNonParallelLocalFS() throws IOException {
+ void testCreateNonParallelLocalFS() throws IOException {
File tmpOutPath = File.createTempFile("fileOutputFormatTest", "Test1");
File tmpOutFile = new File(tmpOutPath.getAbsolutePath() + "/1");
@@ -43,73 +43,67 @@ public class FileOutputFormatTest {
String tmpFilePath = tmpOutPath.toURI().toString();
// check fail if file exists
- DummyFileOutputFormat dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
-
- dfof.configure(new Configuration());
-
- try {
- dfof.open(0, 1);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+
+ dfof.configure(new Configuration());
+
+ dfof.open(0, 1);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
tmpOutPath.delete();
// check fail if directory exists
- Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
- dfof.open(0, 1);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ dfof.open(0, 1);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
tmpOutPath.delete();
// check success
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThat(tmpOutPath).exists().isFile();
tmpOutPath.delete();
// check fail for path with tailing '/'
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThat(tmpOutPath).exists().isFile();
tmpOutPath.delete();
// ----------- test again with always directory mode
@@ -117,60 +111,55 @@ public class FileOutputFormatTest {
// check fail if file exists
tmpOutPath.createNewFile();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
- dfof.open(0, 1);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ dfof.open(0, 1);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
tmpOutPath.delete();
// check success if directory exists
- Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
(new File(tmpOutPath.getAbsoluteFile() + "/1")).delete();
// check custom file name inside directory if directory exists
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.testFileName = true;
- Configuration c = new Configuration();
- dfof.configure(c);
-
- try {
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ dfof.testFileName = true;
+ Configuration c = new Configuration();
+ dfof.configure(c);
+
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
File customOutFile = new File(tmpOutPath.getAbsolutePath() + "/fancy-1-0.avro");
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(customOutFile.exists() && customOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(customOutFile).exists().isFile();
customOutFile.delete();
// check fail if file in directory exists
@@ -178,67 +167,62 @@ public class FileOutputFormatTest {
customOutFile = new File(tmpOutPath.getAbsolutePath() + "/1");
customOutFile.createNewFile();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
- dfof.open(0, 1);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ dfof.open(0, 1);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
(new File(tmpOutPath.getAbsoluteFile() + "/1")).delete();
tmpOutPath.delete();
// check success if no file exists
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
(new File(tmpOutPath.getAbsoluteFile() + "/1")).delete();
tmpOutPath.delete();
// check success for path with tailing '/'
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath + '/'));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
(new File(tmpOutPath.getAbsoluteFile() + "/1")).delete();
tmpOutPath.delete();
}
@Test
- public void testCreateParallelLocalFS() throws IOException {
+ void testCreateParallelLocalFS() throws IOException {
- File tmpOutPath = null;
- File tmpOutFile = null;
+ File tmpOutPath;
+ File tmpOutFile;
tmpOutPath = File.createTempFile("fileOutputFormatTest", "Test1");
tmpOutFile = new File(tmpOutPath.getAbsolutePath() + "/1");
@@ -246,40 +230,38 @@ public class FileOutputFormatTest {
String tmpFilePath = tmpOutPath.toURI().toString();
// check fail if file exists
- DummyFileOutputFormat dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
+
+ dfof.open(0, 2);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
- try {
- dfof.open(0, 2);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
tmpOutPath.delete();
// check success if directory exists
- Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
@@ -287,67 +269,62 @@ public class FileOutputFormatTest {
tmpOutPath.mkdir();
tmpOutFile.createNewFile();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
- dfof.open(0, 2);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ dfof.open(0, 2);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
tmpOutFile.delete();
tmpOutPath.delete();
// check success if no file exists
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
// check success for path with tailing '/'
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
}
@Test
- public void testOverwriteNonParallelLocalFS() throws IOException {
+ void testOverwriteNonParallelLocalFS() throws IOException {
- File tmpOutPath = null;
- File tmpOutFile = null;
+ File tmpOutPath;
+ File tmpOutFile;
tmpOutPath = File.createTempFile("fileOutputFormatTest", "Test1");
tmpOutFile = new File(tmpOutPath.getAbsolutePath() + "/1");
@@ -355,73 +332,65 @@ public class FileOutputFormatTest {
String tmpFilePath = tmpOutPath.toURI().toString();
// check success if file exists
- DummyFileOutputFormat dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThat(tmpOutPath).exists().isFile();
// check success if directory exists
tmpOutPath.delete();
- Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThat(tmpOutPath).exists().isFile();
tmpOutPath.delete();
// check success
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThat(tmpOutPath).exists().isFile();
tmpOutPath.delete();
// check fail for path with tailing '/'
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThat(tmpOutPath).exists().isFile();
tmpOutPath.delete();
// ----------- test again with always directory mode
@@ -429,43 +398,39 @@ public class FileOutputFormatTest {
// check success if file exists
tmpOutPath.createNewFile();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
// check success if directory exists
- Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutPath.delete();
tmpOutFile.delete();
@@ -473,68 +438,63 @@ public class FileOutputFormatTest {
tmpOutPath.mkdir();
tmpOutFile.createNewFile();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutPath.delete();
tmpOutFile.delete();
// check success if no file exists
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
// check success for path with tailing '/'
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.ALWAYS);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 1);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
}
@Test
- public void testOverwriteParallelLocalFS() throws IOException {
+ void testOverwriteParallelLocalFS() throws IOException {
- File tmpOutPath = null;
- File tmpOutFile = null;
+ File tmpOutPath;
+ File tmpOutFile;
tmpOutPath = File.createTempFile("fileOutputFormatTest", "Test1");
tmpOutFile = new File(tmpOutPath.getAbsolutePath() + "/1");
@@ -542,42 +502,38 @@ public class FileOutputFormatTest {
String tmpFilePath = tmpOutPath.toURI().toString();
// check success if file exists
- DummyFileOutputFormat dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
// check success if directory exists
- Assert.assertTrue("Directory could not be created.", tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
@@ -585,59 +541,53 @@ public class FileOutputFormatTest {
tmpOutPath.mkdir();
tmpOutFile.createNewFile();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
(new File(tmpOutPath.getAbsoluteFile() + "/1")).delete();
tmpOutPath.delete();
// check success if no file exists
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
// check success for path with tailing '/'
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
- dfof.setWriteMode(WriteMode.OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ {
+ DummyFileOutputFormat dfof = new DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath + "/"));
+ dfof.setWriteMode(WriteMode.OVERWRITE);
+ dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
dfof.open(0, 2);
dfof.close();
- } catch (Exception e) {
- fail();
}
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isDirectory());
- Assert.assertTrue(tmpOutFile.exists() && tmpOutFile.isFile());
+ assertThat(tmpOutPath).exists().isDirectory();
+ assertThat(tmpOutFile).exists().isFile();
tmpOutFile.delete();
tmpOutPath.delete();
}
@@ -650,7 +600,7 @@ public class FileOutputFormatTest {
public boolean testFileName = false;
@Override
- public void writeRecord(IntValue record) throws IOException {
+ public void writeRecord(IntValue record) {
// DO NOTHING
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/GenericCsvInputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/GenericCsvInputFormatTest.java
index 4918040d147..84a9bcfdd55 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/GenericCsvInputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/GenericCsvInputFormatTest.java
@@ -29,40 +29,36 @@ import org.apache.flink.types.Value;
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
import org.apache.commons.lang3.StringUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
-import java.util.Arrays;
+import java.nio.file.Files;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.GZIPOutputStream;
import static org.apache.flink.api.common.io.DelimitedInputFormatTest.createTempFile;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class GenericCsvInputFormatTest {
+class GenericCsvInputFormatTest {
private TestCsvInputFormat format;
// --------------------------------------------------------------------------------------------
- @Before
+ @BeforeEach
public void setup() {
format = new TestCsvInputFormat();
format.setFilePath("file:///some/file/that/will/not/be/read");
}
- @After
+ @AfterEach
public void setdown() throws Exception {
if (this.format != null) {
this.format.close();
@@ -70,7 +66,7 @@ public class GenericCsvInputFormatTest {
}
@Test
- public void testSparseFieldArray() {
+ void testSparseFieldArray() {
@SuppressWarnings("unchecked")
Class<? extends Value>[] originalTypes =
@@ -79,527 +75,460 @@ public class GenericCsvInputFormatTest {
};
format.setFieldTypesGeneric(originalTypes);
- assertEquals(3, format.getNumberOfNonNullFields());
- assertEquals(6, format.getNumberOfFieldsTotal());
+ assertThat(format.getNumberOfNonNullFields()).isEqualTo(3);
+ assertThat(format.getNumberOfFieldsTotal()).isEqualTo(6);
- assertTrue(Arrays.equals(originalTypes, format.getGenericFieldTypes()));
+ assertThat(format.getGenericFieldTypes()).isEqualTo(originalTypes);
}
@Test
- public void testReadNoPosAll() throws IOException {
- try {
- final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
- final FileInputSplit split = createTempFile(fileContent);
+ void testReadNoPosAll() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
- Value[] values = createIntValues(5);
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(222, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
- assertEquals(444, ((IntValue) values[3]).getValue());
- assertEquals(555, ((IntValue) values[4]).getValue());
+ Value[] values = createIntValues(5);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(666, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
- assertEquals(999, ((IntValue) values[3]).getValue());
- assertEquals(000, ((IntValue) values[4]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(222);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(555);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(666);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(999);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(000);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadNoPosAllDeflate() throws IOException {
- try {
- final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
- final FileInputSplit split = createTempDeflateFile(fileContent);
+ void testReadNoPosAllDeflate() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
+ final FileInputSplit split = createTempDeflateFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
- Value[] values = createIntValues(5);
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(222, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
- assertEquals(444, ((IntValue) values[3]).getValue());
- assertEquals(555, ((IntValue) values[4]).getValue());
+ Value[] values = createIntValues(5);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(666, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
- assertEquals(999, ((IntValue) values[3]).getValue());
- assertEquals(000, ((IntValue) values[4]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(222);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(555);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(666);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(999);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(000);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadNoPosAllGzip() throws IOException {
- try {
- final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
- final FileInputSplit split = createTempGzipFile(fileContent);
+ void testReadNoPosAllGzip() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
+ final FileInputSplit split = createTempGzipFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
- Value[] values = createIntValues(5);
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(222, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
- assertEquals(444, ((IntValue) values[3]).getValue());
- assertEquals(555, ((IntValue) values[4]).getValue());
+ Value[] values = createIntValues(5);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(666, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
- assertEquals(999, ((IntValue) values[3]).getValue());
- assertEquals(000, ((IntValue) values[4]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(222);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(555);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(666);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(999);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(000);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadNoPosAllZStandard() throws IOException {
- try {
- final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
- final FileInputSplit split = createTempZStandardFile(fileContent);
+ void testReadNoPosAllZStandard() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "111|222|333|444|555\n666|777|888|999|000|";
+ final FileInputSplit split = createTempZStandardFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
- Value[] values = createIntValues(5);
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(222, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
- assertEquals(444, ((IntValue) values[3]).getValue());
- assertEquals(555, ((IntValue) values[4]).getValue());
+ Value[] values = createIntValues(5);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(666, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
- assertEquals(999, ((IntValue) values[3]).getValue());
- assertEquals(000, ((IntValue) values[4]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(222);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(555);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(666);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
+ assertThat(((IntValue) values[3]).getValue()).isEqualTo(999);
+ assertThat(((IntValue) values[4]).getValue()).isEqualTo(000);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadNoPosFirstN() throws IOException {
- try {
- final String fileContent = "111|222|333|444|555|\n666|777|888|999|000|";
- final FileInputSplit split = createTempFile(fileContent);
+ void testReadNoPosFirstN() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "111|222|333|444|555|\n666|777|888|999|000|";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(IntValue.class, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(IntValue.class, IntValue.class);
- Value[] values = createIntValues(2);
+ format.configure(parameters);
+ format.open(split);
- // if this would parse all, we would get an index out of bounds exception
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(222, ((IntValue) values[1]).getValue());
+ Value[] values = createIntValues(2);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(666, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ // if this would parse all, we would get an index out of bounds exception
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(222);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(666);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testSparseParse() {
- try {
- final String fileContent =
- "111|222|333|444|555|666|777|888|999|000|\n"
- + "000|999|888|777|666|555|444|333|222|111|";
- final FileInputSplit split = createTempFile(fileContent);
+ void testSparseParse() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent =
+ "111|222|333|444|555|666|777|888|999|000|\n"
+ + "000|999|888|777|666|555|444|333|222|111|";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, null, null, IntValue.class, null, null, null, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, null, null, IntValue.class, null, null, null, IntValue.class);
- Value[] values = createIntValues(3);
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(444, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
+ Value[] values = createIntValues(3);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(000, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- System.err.println(ex.getMessage());
- ex.printStackTrace();
- fail("Test erroneous");
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(000);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testLongLongLong() {
- try {
- final String fileContent = "1,2,3\n3,2,1";
- final FileInputSplit split = createTempFile(fileContent);
+ void testLongLongLong() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "1,2,3\n3,2,1";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter(",");
- format.setFieldTypesGeneric(LongValue.class, LongValue.class, LongValue.class);
- format.configure(parameters);
- format.open(split);
+ final Configuration parameters = new Configuration();
- Value[] values = createLongValues(3);
+ format.setFieldDelimiter(",");
+ format.setFieldTypesGeneric(LongValue.class, LongValue.class, LongValue.class);
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(1L, ((LongValue) values[0]).getValue());
- assertEquals(2L, ((LongValue) values[1]).getValue());
- assertEquals(3L, ((LongValue) values[2]).getValue());
+ Value[] values = createLongValues(3);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(3L, ((LongValue) values[0]).getValue());
- assertEquals(2L, ((LongValue) values[1]).getValue());
- assertEquals(1L, ((LongValue) values[2]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- System.err.println(ex.getMessage());
- ex.printStackTrace();
- fail("Test erroneous");
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((LongValue) values[0]).getValue()).isEqualTo(1L);
+ assertThat(((LongValue) values[1]).getValue()).isEqualTo(2L);
+ assertThat(((LongValue) values[2]).getValue()).isEqualTo(3L);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((LongValue) values[0]).getValue()).isEqualTo(3L);
+ assertThat(((LongValue) values[1]).getValue()).isEqualTo(2L);
+ assertThat(((LongValue) values[2]).getValue()).isEqualTo(1L);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@SuppressWarnings("unchecked")
@Test
- public void testSparseParseWithIndices() {
- try {
- final String fileContent =
- "111|222|333|444|555|666|777|888|999|000|\n000|999|888|777|666|555|444|333|222|111|";
- final FileInputSplit split = createTempFile(fileContent);
-
- final Configuration parameters = new Configuration();
-
- format.setFieldDelimiter("|");
- format.setFieldsGeneric(
- new int[] {0, 3, 7},
- (Class<? extends Value>[])
- new Class[] {IntValue.class, IntValue.class, IntValue.class});
- format.configure(parameters);
- format.open(split);
-
- Value[] values = createIntValues(3);
+ void testSparseParseWithIndices() throws IOException {
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(444, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
+ final String fileContent =
+ "111|222|333|444|555|666|777|888|999|000|\n000|999|888|777|666|555|444|333|222|111|";
+ final FileInputSplit split = createTempFile(fileContent);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(000, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- System.err.println(ex.getMessage());
- ex.printStackTrace();
- fail("Test erroneous");
- }
- }
+ final Configuration parameters = new Configuration();
- @SuppressWarnings("unchecked")
- @Test
- public void testSparseParseWithIndicesMultiCharDelimiter() {
- try {
- final String fileContent =
- "111|-|222|-|333|-|444|-|555|-|666|-|777|-|888|-|999|-|000|-|\n"
- + "000|-|999|-|888|-|777|-|666|-|555|-|444|-|333|-|222|-|111\n"
- + "555|-|999|-|888|-|111|-|666|-|555|-|444|-|777|-|222|-|111|-|\n"
- + "22222|-|99999|-|8|-|99999999|-|6666666|-|5|-|4444|-|8|-|22222|-|1\n";
-
- final FileInputSplit split = createTempFile(fileContent);
-
- final Configuration parameters = new Configuration();
-
- format.setFieldDelimiter("|-|");
- format.setFieldsGeneric(
- new int[] {0, 3, 7},
- (Class<? extends Value>[])
- new Class[] {IntValue.class, IntValue.class, IntValue.class});
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldsGeneric(
+ new int[] {0, 3, 7}, new Class[] {IntValue.class, IntValue.class, IntValue.class});
+ format.configure(parameters);
+ format.open(split);
- Value[] values = createIntValues(3);
+ Value[] values = createIntValues(3);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(111, ((IntValue) values[0]).getValue());
- assertEquals(444, ((IntValue) values[1]).getValue());
- assertEquals(888, ((IntValue) values[2]).getValue());
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(000, ((IntValue) values[0]).getValue());
- assertEquals(777, ((IntValue) values[1]).getValue());
- assertEquals(333, ((IntValue) values[2]).getValue());
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(000);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(555, ((IntValue) values[0]).getValue());
- assertEquals(111, ((IntValue) values[1]).getValue());
- assertEquals(777, ((IntValue) values[2]).getValue());
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
+ }
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals(22222, ((IntValue) values[0]).getValue());
- assertEquals(99999999, ((IntValue) values[1]).getValue());
- assertEquals(8, ((IntValue) values[2]).getValue());
-
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
- } catch (Exception ex) {
- System.err.println(ex.getMessage());
- ex.printStackTrace();
- fail("Test erroneous");
- }
+ @SuppressWarnings("unchecked")
+ @Test
+ void testSparseParseWithIndicesMultiCharDelimiter() throws IOException {
+
+ final String fileContent =
+ "111|-|222|-|333|-|444|-|555|-|666|-|777|-|888|-|999|-|000|-|\n"
+ + "000|-|999|-|888|-|777|-|666|-|555|-|444|-|333|-|222|-|111\n"
+ + "555|-|999|-|888|-|111|-|666|-|555|-|444|-|777|-|222|-|111|-|\n"
+ + "22222|-|99999|-|8|-|99999999|-|6666666|-|5|-|4444|-|8|-|22222|-|1\n";
+
+ final FileInputSplit split = createTempFile(fileContent);
+
+ final Configuration parameters = new Configuration();
+
+ format.setFieldDelimiter("|-|");
+ format.setFieldsGeneric(
+ new int[] {0, 3, 7}, new Class[] {IntValue.class, IntValue.class, IntValue.class});
+ format.configure(parameters);
+ format.open(split);
+
+ Value[] values = createIntValues(3);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(444);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(888);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(000);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(777);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(333);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(555);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(111);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(777);
+
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((IntValue) values[0]).getValue()).isEqualTo(22222);
+ assertThat(((IntValue) values[1]).getValue()).isEqualTo(99999999);
+ assertThat(((IntValue) values[2]).getValue()).isEqualTo(8);
+
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
@Test
- public void testReadTooShortInput() throws IOException {
- try {
- final String fileContent = "111|222|333|444\n666|777|888|999";
- final FileInputSplit split = createTempFile(fileContent);
+ void testReadTooShortInput() throws IOException {
- final Configuration parameters = new Configuration();
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
+ final String fileContent = "111|222|333|444\n666|777|888|999";
+ final FileInputSplit split = createTempFile(fileContent);
- format.configure(parameters);
- format.open(split);
+ final Configuration parameters = new Configuration();
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
- Value[] values = createIntValues(5);
+ format.configure(parameters);
+ format.open(split);
- try {
- format.nextRecord(values);
- fail("Should have thrown a parse exception on too short input.");
- } catch (ParseException e) {
- // all is well
- }
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ Value[] values = createIntValues(5);
+
+ assertThatThrownBy(() -> format.nextRecord(values)).isInstanceOf(ParseException.class);
}
@Test
- public void testReadTooShortInputLenient() throws IOException {
- try {
- final String fileContent = "666|777|888|999|555\n111|222|333|444\n666|777|888|999|555";
- final FileInputSplit split = createTempFile(fileContent);
-
- final Configuration parameters = new Configuration();
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
- format.setLenient(true);
-
- format.configure(parameters);
- format.open(split);
+ void testReadTooShortInputLenient() throws IOException {
- Value[] values = createIntValues(5);
+ final String fileContent = "666|777|888|999|555\n111|222|333|444\n666|777|888|999|555";
+ final FileInputSplit split = createTempFile(fileContent);
- assertNotNull(format.nextRecord(values)); // line okay
- assertNull(format.nextRecord(values)); // line too short
- assertNotNull(format.nextRecord(values)); // line okay
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ final Configuration parameters = new Configuration();
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, IntValue.class, IntValue.class, IntValue.class, IntValue.class);
+ format.setLenient(true);
+
+ format.configure(parameters);
+ format.open(split);
+
+ Value[] values = createIntValues(5);
+
+ assertThat(format.nextRecord(values)).isNotNull(); // line okay
+ assertThat(format.nextRecord(values)).isNull(); // line too short
+ assertThat(format.nextRecord(values)).isNotNull(); // line okay
}
@Test
- public void testReadInvalidContents() throws IOException {
- try {
- final String fileContent = "abc|222|def|444\nkkz|777|888|hhg";
- final FileInputSplit split = createTempFile(fileContent);
+ void testReadInvalidContents() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "abc|222|def|444\nkkz|777|888|hhg";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- StringValue.class, IntValue.class, StringValue.class, IntValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ StringValue.class, IntValue.class, StringValue.class, IntValue.class);
- Value[] values =
- new Value[] {
- new StringValue(), new IntValue(), new StringValue(), new IntValue()
- };
+ format.configure(parameters);
+ format.open(split);
- assertNotNull(format.nextRecord(values));
+ Value[] values =
+ new Value[] {new StringValue(), new IntValue(), new StringValue(), new IntValue()};
- try {
- format.nextRecord(values);
- fail("Input format accepted on invalid input.");
- } catch (ParseException ignored) {
- }
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ assertThat(format.nextRecord(values)).isNotNull();
+
+ assertThatThrownBy(() -> format.nextRecord(values)).isInstanceOf(ParseException.class);
}
@Test
- public void testReadInvalidContentsLenient() {
- try {
- final String fileContent = "abc|222|def|444\nkkz|777|888|hhg";
- final FileInputSplit split = createTempFile(fileContent);
+ void testReadInvalidContentsLenient() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "abc|222|def|444\nkkz|777|888|hhg";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- StringValue.class, IntValue.class, StringValue.class, IntValue.class);
- format.setLenient(true);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ StringValue.class, IntValue.class, StringValue.class, IntValue.class);
+ format.setLenient(true);
- Value[] values =
- new Value[] {
- new StringValue(), new IntValue(), new StringValue(), new IntValue()
- };
+ format.configure(parameters);
+ format.open(split);
- assertNotNull(format.nextRecord(values));
- assertNull(format.nextRecord(values));
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ Value[] values =
+ new Value[] {new StringValue(), new IntValue(), new StringValue(), new IntValue()};
+
+ assertThat(format.nextRecord(values)).isNotNull();
+ assertThat(format.nextRecord(values)).isNull();
}
@Test
- public void testReadInvalidContentsLenientWithSkipping() {
- try {
- final String fileContent =
- "abc|dfgsdf|777|444\n"
- + // good line
- "kkz|777|foobar|hhg\n"
- + // wrong data type in field
- "kkz|777foobarhhg \n"
- + // too short, a skipped field never ends
- "xyx|ignored|42|\n"; // another good line
- final FileInputSplit split = createTempFile(fileContent);
-
- final Configuration parameters = new Configuration();
-
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(StringValue.class, null, IntValue.class);
- format.setLenient(true);
-
- format.configure(parameters);
- format.open(split);
+ void testReadInvalidContentsLenientWithSkipping() throws IOException {
- Value[] values = new Value[] {new StringValue(), new IntValue()};
+ final String fileContent =
+ "abc|dfgsdf|777|444\n"
+ + // good line
+ "kkz|777|foobar|hhg\n"
+ + // wrong data type in field
+ "kkz|777foobarhhg \n"
+ + // too short, a skipped field never ends
+ "xyx|ignored|42|\n"; // another good line
+ final FileInputSplit split = createTempFile(fileContent);
- assertNotNull(format.nextRecord(values));
- assertNull(format.nextRecord(values));
- assertNull(format.nextRecord(values));
- assertNotNull(format.nextRecord(values));
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ final Configuration parameters = new Configuration();
+
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(StringValue.class, null, IntValue.class);
+ format.setLenient(true);
+
+ format.configure(parameters);
+ format.open(split);
+
+ Value[] values = new Value[] {new StringValue(), new IntValue()};
+
+ assertThat(format.nextRecord(values)).isNotNull();
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.nextRecord(values)).isNotNull();
}
@Test
- public void testReadWithCharset() throws IOException {
+ void testReadWithCharset() throws IOException {
// Unicode row fragments
String[] records = new String[] {"\u020e\u021f", "Flink", "\u020b\u020f"};
@@ -613,8 +542,7 @@ public class GenericCsvInputFormatTest {
new GenericCsvInputFormat<String[]>() {
@Override
public String[] readRecord(
- String[] target, byte[] bytes, int offset, int numBytes)
- throws IOException {
+ String[] target, byte[] bytes, int offset, int numBytes) {
return parseRecord(target, bytes, offset, numBytes) ? target : null;
}
};
@@ -625,7 +553,8 @@ public class GenericCsvInputFormatTest {
tempFile.deleteOnExit();
// write string with proper encoding
- try (Writer out = new OutputStreamWriter(new FileOutputStream(tempFile), charset)) {
+ try (Writer out =
+ new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()), charset)) {
out.write(fileContent);
}
@@ -649,163 +578,140 @@ public class GenericCsvInputFormatTest {
values = format.nextRecord(values);
// validate results
- assertNotNull(values);
+ assertThat(values).isNotNull();
for (int i = 0; i < records.length; i++) {
- assertEquals(records[i], values[i]);
+ assertThat(values[i]).isEqualTo(records[i]);
}
- assertNull(format.nextRecord(values));
- assertTrue(format.reachedEnd());
+ assertThat(format.nextRecord(values)).isNull();
+ assertThat(format.reachedEnd()).isTrue();
}
format.close();
}
@Test
- public void readWithEmptyField() {
- try {
- final String fileContent = "abc|def|ghijk\nabc||hhg\n|||";
- final FileInputSplit split = createTempFile(fileContent);
+ void readWithEmptyField() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "abc|def|ghijk\nabc||hhg\n|||";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(StringValue.class, StringValue.class, StringValue.class);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(StringValue.class, StringValue.class, StringValue.class);
- Value[] values = new Value[] {new StringValue(), new StringValue(), new StringValue()};
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals("abc", ((StringValue) values[0]).getValue());
- assertEquals("def", ((StringValue) values[1]).getValue());
- assertEquals("ghijk", ((StringValue) values[2]).getValue());
+ Value[] values = new Value[] {new StringValue(), new StringValue(), new StringValue()};
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals("abc", ((StringValue) values[0]).getValue());
- assertEquals("", ((StringValue) values[1]).getValue());
- assertEquals("hhg", ((StringValue) values[2]).getValue());
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((StringValue) values[0]).getValue()).isEqualTo("abc");
+ assertThat(((StringValue) values[1]).getValue()).isEqualTo("def");
+ assertThat(((StringValue) values[2]).getValue()).isEqualTo("ghijk");
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals("", ((StringValue) values[0]).getValue());
- assertEquals("", ((StringValue) values[1]).getValue());
- assertEquals("", ((StringValue) values[2]).getValue());
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((StringValue) values[0]).getValue()).isEqualTo("abc");
+ assertThat(((StringValue) values[1]).getValue()).isEqualTo("");
+ assertThat(((StringValue) values[2]).getValue()).isEqualTo("hhg");
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((StringValue) values[0]).getValue()).isEqualTo("");
+ assertThat(((StringValue) values[1]).getValue()).isEqualTo("");
+ assertThat(((StringValue) values[2]).getValue()).isEqualTo("");
}
@Test
- public void readWithParseQuotedStrings() {
- try {
- final String fileContent = "\"ab\\\"c\"|\"def\"\n\"ghijk\"|\"abc\"";
- final FileInputSplit split = createTempFile(fileContent);
+ void readWithParseQuotedStrings() throws IOException {
- final Configuration parameters = new Configuration();
+ final String fileContent = "\"ab\\\"c\"|\"def\"\n\"ghijk\"|\"abc\"";
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(StringValue.class, StringValue.class);
- format.enableQuotedStringParsing('"');
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(StringValue.class, StringValue.class);
+ format.enableQuotedStringParsing('"');
- Value[] values = new Value[] {new StringValue(), new StringValue()};
+ format.configure(parameters);
+ format.open(split);
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals("ab\\\"c", ((StringValue) values[0]).getValue());
- assertEquals("def", ((StringValue) values[1]).getValue());
+ Value[] values = new Value[] {new StringValue(), new StringValue()};
- values = format.nextRecord(values);
- assertNotNull(values);
- assertEquals("ghijk", ((StringValue) values[0]).getValue());
- assertEquals("abc", ((StringValue) values[1]).getValue());
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((StringValue) values[0]).getValue()).isEqualTo("ab\\\"c");
+ assertThat(((StringValue) values[1]).getValue()).isEqualTo("def");
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ values = format.nextRecord(values);
+ assertThat(values).isNotNull();
+ assertThat(((StringValue) values[0]).getValue()).isEqualTo("ghijk");
+ assertThat(((StringValue) values[1]).getValue()).isEqualTo("abc");
}
@Test
- public void readWithHeaderLine() {
- try {
- final String fileContent =
- "colname-1|colname-2|some name 3|column four|\n"
- + "123|abc|456|def|\n"
- + "987|xyz|654|pqr|\n";
+ void readWithHeaderLine() throws IOException {
- final FileInputSplit split = createTempFile(fileContent);
+ final String fileContent =
+ "colname-1|colname-2|some name 3|column four|\n"
+ + "123|abc|456|def|\n"
+ + "987|xyz|654|pqr|\n";
- final Configuration parameters = new Configuration();
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, StringValue.class, IntValue.class, StringValue.class);
- format.setSkipFirstLineAsHeader(true);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, StringValue.class, IntValue.class, StringValue.class);
+ format.setSkipFirstLineAsHeader(true);
- Value[] values =
- new Value[] {
- new IntValue(), new StringValue(), new IntValue(), new StringValue()
- };
-
- // first line is skipped as header
- assertNotNull(format.nextRecord(values)); // first row (= second line)
- assertNotNull(format.nextRecord(values)); // second row (= third line)
- assertNull(format.nextRecord(values)); // exhausted
- assertTrue(format.reachedEnd()); // exhausted
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ format.configure(parameters);
+ format.open(split);
+
+ Value[] values =
+ new Value[] {new IntValue(), new StringValue(), new IntValue(), new StringValue()};
+
+ // first line is skipped as header
+ assertThat(format.nextRecord(values)); // first row (= second line).isNotNull()
+ assertThat(format.nextRecord(values)); // second row (= third line).isNotNull()
+ assertThat(format.nextRecord(values)).isNull(); // exhausted
+ assertThat(format.reachedEnd()).isTrue(); // exhausted
}
@Test
- public void readWithHeaderLineAndInvalidIntermediate() {
- try {
- final String fileContent =
- "colname-1|colname-2|some name 3|column four|\n"
- + "123|abc|456|def|\n"
- + "colname-1|colname-2|some name 3|column four|\n"
- + // repeated header in the middle
- "987|xyz|654|pqr|\n";
+ void readWithHeaderLineAndInvalidIntermediate() throws IOException {
- final FileInputSplit split = createTempFile(fileContent);
+ final String fileContent =
+ "colname-1|colname-2|some name 3|column four|\n"
+ + "123|abc|456|def|\n"
+ + "colname-1|colname-2|some name 3|column four|\n"
+ + // repeated header in the middle
+ "987|xyz|654|pqr|\n";
- final Configuration parameters = new Configuration();
+ final FileInputSplit split = createTempFile(fileContent);
- format.setFieldDelimiter("|");
- format.setFieldTypesGeneric(
- IntValue.class, StringValue.class, IntValue.class, StringValue.class);
- format.setSkipFirstLineAsHeader(true);
+ final Configuration parameters = new Configuration();
- format.configure(parameters);
- format.open(split);
+ format.setFieldDelimiter("|");
+ format.setFieldTypesGeneric(
+ IntValue.class, StringValue.class, IntValue.class, StringValue.class);
+ format.setSkipFirstLineAsHeader(true);
- Value[] values =
- new Value[] {
- new IntValue(), new StringValue(), new IntValue(), new StringValue()
- };
+ format.configure(parameters);
+ format.open(split);
- // first line is skipped as header
- assertNotNull(format.nextRecord(values)); // first row (= second line)
+ Value[] values =
+ new Value[] {new IntValue(), new StringValue(), new IntValue(), new StringValue()};
- try {
- format.nextRecord(values);
- fail("Format accepted invalid line.");
- } catch (ParseException e) {
- // as we expected
- }
- } catch (Exception ex) {
- fail("Test failed due to a " + ex.getClass().getSimpleName() + ": " + ex.getMessage());
- }
+ // first line is skipped as header
+ assertThat(format.nextRecord(values)); // first row (= second line).isNotNull()
+
+ assertThatThrownBy(() -> format.nextRecord(values)).isInstanceOf(ParseException.class);
}
private FileInputSplit createTempDeflateFile(String content) throws IOException {
@@ -813,7 +719,8 @@ public class GenericCsvInputFormatTest {
tempFile.deleteOnExit();
DataOutputStream dos =
- new DataOutputStream(new DeflaterOutputStream(new FileOutputStream(tempFile)));
+ new DataOutputStream(
+ new DeflaterOutputStream(Files.newOutputStream(tempFile.toPath())));
dos.writeBytes(content);
dos.close();
@@ -830,7 +737,8 @@ public class GenericCsvInputFormatTest {
tempFile.deleteOnExit();
DataOutputStream dos =
- new DataOutputStream(new GZIPOutputStream(new FileOutputStream(tempFile)));
+ new DataOutputStream(
+ new GZIPOutputStream(Files.newOutputStream(tempFile.toPath())));
dos.writeBytes(content);
dos.close();
@@ -848,7 +756,7 @@ public class GenericCsvInputFormatTest {
DataOutputStream dos =
new DataOutputStream(
- new ZstdCompressorOutputStream(new FileOutputStream(tempFile)));
+ new ZstdCompressorOutputStream(Files.newOutputStream(tempFile.toPath())));
dos.writeBytes(content);
dos.close();
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/GlobFilePathFilterTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/GlobFilePathFilterTest.java
index d9ecb595cf4..e7120bae1ea 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/GlobFilePathFilterTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/GlobFilePathFilterTest.java
@@ -21,43 +21,41 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.core.testutils.CommonTestUtils;
import org.apache.flink.util.OperatingSystem;
-import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assumptions.assumeThat;
-public class GlobFilePathFilterTest {
+class GlobFilePathFilterTest {
@Test
- public void testDefaultConstructorCreateMatchAllFilter() {
+ void testDefaultConstructorCreateMatchAllFilter() {
GlobFilePathFilter matcher = new GlobFilePathFilter();
assertThat(matcher.filterPath(new Path("dir/file.txt"))).isFalse();
}
@Test
- public void testMatchAllFilesByDefault() {
+ void testMatchAllFilesByDefault() {
GlobFilePathFilter matcher =
- new GlobFilePathFilter(
- Collections.<String>emptyList(), Collections.<String>emptyList());
+ new GlobFilePathFilter(Collections.emptyList(), Collections.emptyList());
assertThat(matcher.filterPath(new Path("dir/file.txt"))).isFalse();
}
@Test
- public void testExcludeFilesNotInIncludePatterns() {
+ void testExcludeFilesNotInIncludePatterns() {
GlobFilePathFilter matcher =
- new GlobFilePathFilter(
- Collections.singletonList("dir/*"), Collections.<String>emptyList());
+ new GlobFilePathFilter(Collections.singletonList("dir/*"), Collections.emptyList());
assertThat(matcher.filterPath(new Path("dir/file.txt"))).isFalse();
assertThat(matcher.filterPath(new Path("dir1/file.txt"))).isTrue();
}
@Test
- public void testExcludeFilesIfMatchesExclude() {
+ void testExcludeFilesIfMatchesExclude() {
GlobFilePathFilter matcher =
new GlobFilePathFilter(
Collections.singletonList("dir/*"),
@@ -67,21 +65,20 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testIncludeFileWithAnyCharacterMatcher() {
+ void testIncludeFileWithAnyCharacterMatcher() {
GlobFilePathFilter matcher =
new GlobFilePathFilter(
- Collections.singletonList("dir/?.txt"), Collections.<String>emptyList());
+ Collections.singletonList("dir/?.txt"), Collections.emptyList());
assertThat(matcher.filterPath(new Path("dir/a.txt"))).isFalse();
assertThat(matcher.filterPath(new Path("dir/aa.txt"))).isTrue();
}
@Test
- public void testIncludeFileWithCharacterSetMatcher() {
+ void testIncludeFileWithCharacterSetMatcher() {
GlobFilePathFilter matcher =
new GlobFilePathFilter(
- Collections.singletonList("dir/[acd].txt"),
- Collections.<String>emptyList());
+ Collections.singletonList("dir/[acd].txt"), Collections.emptyList());
assertThat(matcher.filterPath(new Path("dir/a.txt"))).isFalse();
assertThat(matcher.filterPath(new Path("dir/c.txt"))).isFalse();
@@ -90,11 +87,10 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testIncludeFileWithCharacterRangeMatcher() {
+ void testIncludeFileWithCharacterRangeMatcher() {
GlobFilePathFilter matcher =
new GlobFilePathFilter(
- Collections.singletonList("dir/[a-d].txt"),
- Collections.<String>emptyList());
+ Collections.singletonList("dir/[a-d].txt"), Collections.emptyList());
assertThat(matcher.filterPath(new Path("dir/a.txt"))).isFalse();
assertThat(matcher.filterPath(new Path("dir/b.txt"))).isFalse();
@@ -104,7 +100,7 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testExcludeHDFSFile() {
+ void testExcludeHDFSFile() {
GlobFilePathFilter matcher =
new GlobFilePathFilter(
Collections.singletonList("**"),
@@ -116,7 +112,7 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testExcludeFilenameWithStart() {
+ void testExcludeFilenameWithStart() {
assumeThat(OperatingSystem.isWindows())
.as("Windows does not allow asterisks in file names.")
.isFalse();
@@ -131,10 +127,9 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testSingleStarPattern() {
+ void testSingleStarPattern() {
GlobFilePathFilter matcher =
- new GlobFilePathFilter(
- Collections.singletonList("*"), Collections.<String>emptyList());
+ new GlobFilePathFilter(Collections.singletonList("*"), Collections.emptyList());
assertThat(matcher.filterPath(new Path("a"))).isFalse();
assertThat(matcher.filterPath(new Path("a/b"))).isTrue();
@@ -142,10 +137,9 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testDoubleStarPattern() {
+ void testDoubleStarPattern() {
GlobFilePathFilter matcher =
- new GlobFilePathFilter(
- Collections.singletonList("**"), Collections.<String>emptyList());
+ new GlobFilePathFilter(Collections.singletonList("**"), Collections.emptyList());
assertThat(matcher.filterPath(new Path("a"))).isFalse();
assertThat(matcher.filterPath(new Path("a/b"))).isFalse();
@@ -153,24 +147,21 @@ public class GlobFilePathFilterTest {
}
@Test
- public void testIncluePatternIsNull() {
- Assertions.assertThatThrownBy(
- () -> new GlobFilePathFilter(null, Collections.<String>emptyList()))
+ void testIncludePatternIsNull() {
+ assertThatThrownBy(() -> new GlobFilePathFilter(null, Collections.emptyList()))
.isInstanceOf(NullPointerException.class);
}
@Test
- public void testExcludePatternIsNull() {
- Assertions.assertThatThrownBy(
- () -> new GlobFilePathFilter(Collections.singletonList("**"), null))
+ void testExcludePatternIsNull() {
+ assertThatThrownBy(() -> new GlobFilePathFilter(Collections.singletonList("**"), null))
.isInstanceOf(NullPointerException.class);
}
@Test
- public void testGlobFilterSerializable() throws IOException {
+ void testGlobFilterSerializable() throws IOException {
GlobFilePathFilter matcher =
- new GlobFilePathFilter(
- Collections.singletonList("**"), Collections.<String>emptyList());
+ new GlobFilePathFilter(Collections.singletonList("**"), Collections.emptyList());
GlobFilePathFilter matcherCopy = CommonTestUtils.createCopySerializable(matcher);
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/InputStreamFSInputWrapperTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/InputStreamFSInputWrapperTest.java
index d417d772996..b4319d929a0 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/InputStreamFSInputWrapperTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/InputStreamFSInputWrapperTest.java
@@ -18,7 +18,7 @@
package org.apache.flink.api.common.io;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
@@ -26,10 +26,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static org.assertj.core.api.Assertions.assertThat;
-public class InputStreamFSInputWrapperTest {
+class InputStreamFSInputWrapperTest {
@Test
- public void testClose() throws Exception {
+ void testClose() throws Exception {
final AtomicBoolean closeCalled = new AtomicBoolean(false);
InputStream mockedInputStream =
new InputStream() {
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/OutputFormatBaseTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/OutputFormatBaseTest.java
index 94c292344f9..6cc13d5bdf2 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/OutputFormatBaseTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/OutputFormatBaseTest.java
@@ -52,13 +52,13 @@ class OutputFormatBaseTest {
testOutputFormat.enqueueCompletableFuture(CompletableFuture.completedFuture(null));
final int originalPermits = testOutputFormat.getAvailablePermits();
- assertThat(originalPermits).isGreaterThan(0);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(originalPermits).isPositive();
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
testOutputFormat.writeRecord("hello");
assertThat(testOutputFormat.getAvailablePermits()).isEqualTo(originalPermits);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
}
}
@@ -71,7 +71,7 @@ class OutputFormatBaseTest {
testOutputFormat.enqueueCompletableFuture(FutureUtils.completedExceptionally(cause));
testOutputFormat.writeRecord("none");
- assertThatThrownBy(() -> testOutputFormat.close())
+ assertThatThrownBy(testOutputFormat::close)
.isInstanceOf(IOException.class)
.hasCauseReference(cause);
}
@@ -91,7 +91,7 @@ class OutputFormatBaseTest {
"Sending of second value should have failed.")
.isInstanceOf(IOException.class)
.hasCauseReference(cause);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
}
}
@@ -103,7 +103,7 @@ class OutputFormatBaseTest {
testOutputFormat.enqueueCompletableFuture(completableFuture);
testOutputFormat.writeRecord("hello");
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(1);
+ assertThat(testOutputFormat.getAcquiredPermits()).isOne();
CheckedThread checkedThread =
new CheckedThread("Flink-OutputFormatBaseTest") {
@@ -117,12 +117,12 @@ class OutputFormatBaseTest {
Thread.sleep(5);
}
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(1);
+ assertThat(testOutputFormat.getAcquiredPermits()).isOne();
// start writing
completableFuture.complete(null);
// wait for the close
checkedThread.sync();
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
}
}
@@ -130,21 +130,21 @@ class OutputFormatBaseTest {
void testReleaseOnSuccess() throws Exception {
try (TestOutputFormat openedTestOutputFormat = createOpenedTestOutputFormat()) {
- assertThat(openedTestOutputFormat.getAvailablePermits()).isEqualTo(1);
- assertThat(openedTestOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(openedTestOutputFormat.getAvailablePermits()).isOne();
+ assertThat(openedTestOutputFormat.getAcquiredPermits()).isZero();
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
openedTestOutputFormat.enqueueCompletableFuture(completableFuture);
openedTestOutputFormat.writeRecord("hello");
- assertThat(openedTestOutputFormat.getAvailablePermits()).isEqualTo(0);
- assertThat(openedTestOutputFormat.getAcquiredPermits()).isEqualTo(1);
+ assertThat(openedTestOutputFormat.getAvailablePermits()).isZero();
+ assertThat(openedTestOutputFormat.getAcquiredPermits()).isOne();
// start writing
completableFuture.complete(null);
- assertThat(openedTestOutputFormat.getAvailablePermits()).isEqualTo(1);
- assertThat(openedTestOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(openedTestOutputFormat.getAvailablePermits()).isOne();
+ assertThat(openedTestOutputFormat.getAcquiredPermits()).isZero();
}
}
@@ -152,21 +152,21 @@ class OutputFormatBaseTest {
void testReleaseOnFailure() throws Exception {
TestOutputFormat testOutputFormat = createOpenedTestOutputFormat();
- assertThat(testOutputFormat.getAvailablePermits()).isEqualTo(1);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(testOutputFormat.getAvailablePermits()).isOne();
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
CompletableFuture<Void> completableFuture = new CompletableFuture<>();
testOutputFormat.enqueueCompletableFuture(completableFuture);
testOutputFormat.writeRecord("none");
- assertThat(testOutputFormat.getAvailablePermits()).isEqualTo(0);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(1);
+ assertThat(testOutputFormat.getAvailablePermits()).isZero();
+ assertThat(testOutputFormat.getAcquiredPermits()).isOne();
completableFuture.completeExceptionally(new RuntimeException());
- assertThat(testOutputFormat.getAvailablePermits()).isEqualTo(1);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
- assertThatThrownBy(() -> testOutputFormat.close());
+ assertThat(testOutputFormat.getAvailablePermits()).isOne();
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
+ assertThatThrownBy(testOutputFormat::close);
}
@Test
@@ -179,8 +179,8 @@ class OutputFormatBaseTest {
try (TestOutputFormat testOutputFormat =
createOpenedTestOutputFormat(failingSendFunction)) {
- assertThat(testOutputFormat.getAvailablePermits()).isEqualTo(1);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(testOutputFormat.getAvailablePermits()).isOne();
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
try {
testOutputFormat.writeRecord("none");
@@ -189,8 +189,8 @@ class OutputFormatBaseTest {
// just avoid the test failure
}
// writeRecord acquires a permit that is then released when send fails
- assertThat(testOutputFormat.getAvailablePermits()).isEqualTo(1);
- assertThat(testOutputFormat.getAcquiredPermits()).isEqualTo(0);
+ assertThat(testOutputFormat.getAvailablePermits()).isOne();
+ assertThat(testOutputFormat.getAcquiredPermits()).isZero();
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/RichInputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/RichInputFormatTest.java
index 0916ecca289..b6621484886 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/RichInputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/RichInputFormatTest.java
@@ -21,37 +21,34 @@ package org.apache.flink.api.common.io;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.TaskInfo;
import org.apache.flink.api.common.TaskInfoImpl;
-import org.apache.flink.api.common.accumulators.Accumulator;
import org.apache.flink.api.common.functions.util.RuntimeUDFContext;
-import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
import org.apache.flink.types.Value;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
-import java.util.concurrent.Future;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests runtime context access from inside an RichInputFormat class. */
-public class RichInputFormatTest {
+class RichInputFormatTest {
@Test
- public void testCheckRuntimeContextAccess() {
- final SerializedInputFormat<Value> inputFormat = new SerializedInputFormat<Value>();
+ void testCheckRuntimeContextAccess() {
+ final SerializedInputFormat<Value> inputFormat = new SerializedInputFormat<>();
final TaskInfo taskInfo = new TaskInfoImpl("test name", 3, 1, 3, 0);
inputFormat.setRuntimeContext(
new RuntimeUDFContext(
taskInfo,
getClass().getClassLoader(),
new ExecutionConfig(),
- new HashMap<String, Future<Path>>(),
- new HashMap<String, Accumulator<?, ?>>(),
+ new HashMap<>(),
+ new HashMap<>(),
UnregisteredMetricsGroup.createOperatorMetricGroup()));
- assertEquals(inputFormat.getRuntimeContext().getTaskInfo().getIndexOfThisSubtask(), 1);
- assertEquals(
- inputFormat.getRuntimeContext().getTaskInfo().getNumberOfParallelSubtasks(), 3);
+ assertThat(inputFormat.getRuntimeContext().getTaskInfo().getIndexOfThisSubtask()).isOne();
+ assertThat(inputFormat.getRuntimeContext().getTaskInfo().getNumberOfParallelSubtasks())
+ .isEqualTo(3);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/io/RichOutputFormatTest.java b/flink-core/src/test/java/org/apache/flink/api/common/io/RichOutputFormatTest.java
index 902b6ede7f5..b8fc795f874 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/io/RichOutputFormatTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/io/RichOutputFormatTest.java
@@ -21,25 +21,22 @@ package org.apache.flink.api.common.io;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.TaskInfo;
import org.apache.flink.api.common.TaskInfoImpl;
-import org.apache.flink.api.common.accumulators.Accumulator;
import org.apache.flink.api.common.functions.util.RuntimeUDFContext;
-import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
import org.apache.flink.types.Value;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
-import java.util.concurrent.Future;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests runtime context access from inside an RichOutputFormat class. */
-public class RichOutputFormatTest {
+class RichOutputFormatTest {
@Test
- public void testCheckRuntimeContextAccess() {
- final SerializedOutputFormat<Value> inputFormat = new SerializedOutputFormat<Value>();
+ void testCheckRuntimeContextAccess() {
+ final SerializedOutputFormat<Value> inputFormat = new SerializedOutputFormat<>();
final TaskInfo taskInfo = new TaskInfoImpl("test name", 3, 1, 3, 0);
inputFormat.setRuntimeContext(
@@ -47,12 +44,12 @@ public class RichOutputFormatTest {
taskInfo,
getClass().getClassLoader(),
new ExecutionConfig(),
- new HashMap<String, Future<Path>>(),
- new HashMap<String, Accumulator<?, ?>>(),
+ new HashMap<>(),
+ new HashMap<>(),
UnregisteredMetricsGroup.createOperatorMetricGroup()));
- assertEquals(inputFormat.getRuntimeContext().getTaskInfo().getIndexOfThisSubtask(), 1);
- assertEquals(
- inputFormat.getRuntimeContext().getTaskInfo().getNumberOfParallelSubtasks(), 3);
+ assertThat(inputFormat.getRuntimeContext().getTaskInfo().getIndexOfThisSubtask()).isOne();
+ assertThat(inputFormat.getRuntimeContext().getTaskInfo().getNumberOfParallelSubtasks())
+ .isEqualTo(3);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/DualInputSemanticPropertiesTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/DualInputSemanticPropertiesTest.java
index d00e276b2ed..81deb6f5114 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/DualInputSemanticPropertiesTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/DualInputSemanticPropertiesTest.java
@@ -20,16 +20,15 @@ package org.apache.flink.api.common.operators;
import org.apache.flink.api.common.operators.util.FieldSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class DualInputSemanticPropertiesTest {
+class DualInputSemanticPropertiesTest {
@Test
- public void testGetTargetFields() {
+ void testGetTargetFields() {
// first input
DualInputSemanticProperties sp = new DualInputSemanticProperties();
@@ -38,16 +37,16 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(0, 2, 3);
sp.addForwardedField(0, 3, 2);
- assertEquals(1, sp.getForwardingTargetFields(0, 0).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 1).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 2).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 3).size());
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(1));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(4));
- assertTrue(sp.getForwardingTargetFields(0, 2).contains(3));
- assertTrue(sp.getForwardingTargetFields(0, 3).contains(2));
- assertNotNull(sp.getForwardingTargetFields(0, 4));
- assertEquals(0, sp.getForwardingTargetFields(0, 4).size());
+ assertThat(sp.getForwardingTargetFields(0, 0)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 1)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 2)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 3)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 2).contains(3)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 3).contains(2)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 4)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(0, 4)).isEmpty();
sp = new DualInputSemanticProperties();
sp.addForwardedField(0, 0, 0);
@@ -56,15 +55,15 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(0, 1, 2);
sp.addForwardedField(0, 1, 3);
- assertEquals(2, sp.getForwardingTargetFields(0, 0).size());
- assertEquals(3, sp.getForwardingTargetFields(0, 1).size());
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(0));
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(4));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(1));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(2));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(3));
- assertNotNull(sp.getForwardingTargetFields(0, 2));
- assertEquals(0, sp.getForwardingTargetFields(0, 2).size());
+ assertThat(sp.getForwardingTargetFields(0, 0)).hasSize(2);
+ assertThat(sp.getForwardingTargetFields(0, 1)).hasSize(3);
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(0)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(2)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(3)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 2)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(0, 2)).isEmpty();
// second input
sp = new DualInputSemanticProperties();
@@ -73,16 +72,16 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(1, 2, 3);
sp.addForwardedField(1, 3, 2);
- assertEquals(1, sp.getForwardingTargetFields(1, 0).size());
- assertEquals(1, sp.getForwardingTargetFields(1, 1).size());
- assertEquals(1, sp.getForwardingTargetFields(1, 2).size());
- assertEquals(1, sp.getForwardingTargetFields(1, 3).size());
- assertTrue(sp.getForwardingTargetFields(1, 0).contains(1));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(4));
- assertTrue(sp.getForwardingTargetFields(1, 2).contains(3));
- assertTrue(sp.getForwardingTargetFields(1, 3).contains(2));
- assertNotNull(sp.getForwardingTargetFields(1, 4));
- assertEquals(0, sp.getForwardingTargetFields(1, 4).size());
+ assertThat(sp.getForwardingTargetFields(1, 0)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 1)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 2)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 3)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 0).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 2).contains(3)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 3).contains(2)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 4)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(1, 4)).isEmpty();
sp = new DualInputSemanticProperties();
sp.addForwardedField(1, 0, 0);
@@ -91,15 +90,15 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(1, 1, 2);
sp.addForwardedField(1, 1, 3);
- assertEquals(2, sp.getForwardingTargetFields(1, 0).size());
- assertEquals(3, sp.getForwardingTargetFields(1, 1).size());
- assertTrue(sp.getForwardingTargetFields(1, 0).contains(0));
- assertTrue(sp.getForwardingTargetFields(1, 0).contains(4));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(1));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(2));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(3));
- assertNotNull(sp.getForwardingTargetFields(1, 2));
- assertEquals(0, sp.getForwardingTargetFields(1, 2).size());
+ assertThat(sp.getForwardingTargetFields(1, 0)).hasSize(2);
+ assertThat(sp.getForwardingTargetFields(1, 1)).hasSize(3);
+ assertThat(sp.getForwardingTargetFields(1, 0).contains(0)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 0).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(2)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(3)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 2)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(1, 2)).isEmpty();
// both inputs
sp = new DualInputSemanticProperties();
@@ -108,18 +107,18 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(1, 0, 1);
sp.addForwardedField(1, 1, 4);
- assertEquals(1, sp.getForwardingTargetFields(0, 2).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 7).size());
- assertEquals(1, sp.getForwardingTargetFields(1, 0).size());
- assertEquals(1, sp.getForwardingTargetFields(1, 1).size());
- assertTrue(sp.getForwardingTargetFields(0, 2).contains(6));
- assertTrue(sp.getForwardingTargetFields(0, 7).contains(8));
- assertTrue(sp.getForwardingTargetFields(1, 0).contains(1));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(4));
- assertNotNull(sp.getForwardingTargetFields(0, 1));
- assertNotNull(sp.getForwardingTargetFields(1, 4));
- assertEquals(0, sp.getForwardingTargetFields(0, 1).size());
- assertEquals(0, sp.getForwardingTargetFields(1, 4).size());
+ assertThat(sp.getForwardingTargetFields(0, 2)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 7)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 0)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 1)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 2).contains(6)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 7).contains(8)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 0).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(1, 4)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(0, 1)).isEmpty();
+ assertThat(sp.getForwardingTargetFields(1, 4)).isEmpty();
sp = new DualInputSemanticProperties();
sp.addForwardedField(0, 0, 0);
@@ -129,20 +128,20 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(1, 1, 2);
sp.addForwardedField(1, 4, 8);
- assertEquals(2, sp.getForwardingTargetFields(0, 0).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 3).size());
- assertEquals(2, sp.getForwardingTargetFields(1, 1).size());
- assertEquals(1, sp.getForwardingTargetFields(1, 4).size());
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(0));
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(4));
- assertTrue(sp.getForwardingTargetFields(0, 3).contains(8));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(1));
- assertTrue(sp.getForwardingTargetFields(1, 1).contains(1));
- assertTrue(sp.getForwardingTargetFields(1, 4).contains(8));
+ assertThat(sp.getForwardingTargetFields(0, 0)).hasSize(2);
+ assertThat(sp.getForwardingTargetFields(0, 3)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(1, 1)).hasSize(2);
+ assertThat(sp.getForwardingTargetFields(1, 4)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(0)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 3).contains(8)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 1).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(1, 4).contains(8)).isTrue();
}
@Test
- public void testGetSourceField() {
+ void testGetSourceField() {
// first input
DualInputSemanticProperties sp = new DualInputSemanticProperties();
@@ -151,12 +150,12 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(0, 2, 3);
sp.addForwardedField(0, 3, 2);
- assertEquals(0, sp.getForwardingSourceField(0, 1));
- assertEquals(1, sp.getForwardingSourceField(0, 4));
- assertEquals(2, sp.getForwardingSourceField(0, 3));
- assertEquals(3, sp.getForwardingSourceField(0, 2));
- assertTrue(sp.getForwardingSourceField(0, 0) < 0);
- assertTrue(sp.getForwardingSourceField(0, 5) < 0);
+ assertThat(sp.getForwardingSourceField(0, 1)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 4)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 3)).isEqualTo(2);
+ assertThat(sp.getForwardingSourceField(0, 2)).isEqualTo(3);
+ assertThat(sp.getForwardingSourceField(0, 0)).isNegative();
+ assertThat(sp.getForwardingSourceField(0, 5)).isNegative();
sp = new DualInputSemanticProperties();
sp.addForwardedField(0, 0, 0);
@@ -165,12 +164,12 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(0, 1, 2);
sp.addForwardedField(0, 1, 3);
- assertEquals(0, sp.getForwardingSourceField(0, 0));
- assertEquals(0, sp.getForwardingSourceField(0, 4));
- assertEquals(1, sp.getForwardingSourceField(0, 1));
- assertEquals(1, sp.getForwardingSourceField(0, 2));
- assertEquals(1, sp.getForwardingSourceField(0, 3));
- assertTrue(sp.getForwardingSourceField(0, 5) < 0);
+ assertThat(sp.getForwardingSourceField(0, 0)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 4)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 1)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 2)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 3)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 5)).isNegative();
// second input
sp = new DualInputSemanticProperties();
@@ -179,12 +178,12 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(1, 2, 3);
sp.addForwardedField(1, 3, 2);
- assertEquals(0, sp.getForwardingSourceField(1, 1));
- assertEquals(1, sp.getForwardingSourceField(1, 4));
- assertEquals(2, sp.getForwardingSourceField(1, 3));
- assertEquals(3, sp.getForwardingSourceField(1, 2));
- assertTrue(sp.getForwardingSourceField(1, 0) < 0);
- assertTrue(sp.getForwardingSourceField(1, 5) < 0);
+ assertThat(sp.getForwardingSourceField(1, 1)).isZero();
+ assertThat(sp.getForwardingSourceField(1, 4)).isOne();
+ assertThat(sp.getForwardingSourceField(1, 3)).isEqualTo(2);
+ assertThat(sp.getForwardingSourceField(1, 2)).isEqualTo(3);
+ assertThat(sp.getForwardingSourceField(1, 0)).isNegative();
+ assertThat(sp.getForwardingSourceField(1, 5)).isNegative();
sp = new DualInputSemanticProperties();
sp.addForwardedField(1, 0, 0);
@@ -193,61 +192,69 @@ public class DualInputSemanticPropertiesTest {
sp.addForwardedField(1, 1, 2);
sp.addForwardedField(1, 1, 3);
- assertEquals(0, sp.getForwardingSourceField(1, 0));
- assertEquals(0, sp.getForwardingSourceField(1, 4));
- assertEquals(1, sp.getForwardingSourceField(1, 1));
- assertEquals(1, sp.getForwardingSourceField(1, 2));
- assertEquals(1, sp.getForwardingSourceField(1, 3));
- assertTrue(sp.getForwardingSourceField(1, 5) < 0);
+ assertThat(sp.getForwardingSourceField(1, 0)).isZero();
+ assertThat(sp.getForwardingSourceField(1, 4)).isZero();
+ assertThat(sp.getForwardingSourceField(1, 1)).isOne();
+ assertThat(sp.getForwardingSourceField(1, 2)).isOne();
+ assertThat(sp.getForwardingSourceField(1, 3)).isOne();
+ assertThat(sp.getForwardingSourceField(1, 5)).isNegative();
}
@Test
- public void testGetReadSet() {
+ void testGetReadSet() {
// first input
DualInputSemanticProperties sp = new DualInputSemanticProperties();
sp.addReadFields(0, new FieldSet(0, 1));
- assertEquals(2, sp.getReadFields(0).size());
- assertTrue(sp.getReadFields(0).contains(0));
- assertTrue(sp.getReadFields(0).contains(1));
+ assertThat(sp.getReadFields(0)).hasSize(2);
+ assertThat(sp.getReadFields(0).contains(0)).isTrue();
+ assertThat(sp.getReadFields(0).contains(1)).isTrue();
sp.addReadFields(0, new FieldSet(3));
- assertEquals(3, sp.getReadFields(0).size());
- assertTrue(sp.getReadFields(0).contains(0));
- assertTrue(sp.getReadFields(0).contains(1));
- assertTrue(sp.getReadFields(0).contains(3));
+ assertThat(sp.getReadFields(0)).hasSize(3);
+ assertThat(sp.getReadFields(0).contains(0)).isTrue();
+ assertThat(sp.getReadFields(0).contains(1)).isTrue();
+ assertThat(sp.getReadFields(0).contains(3)).isTrue();
// second input
sp = new DualInputSemanticProperties();
sp.addReadFields(1, new FieldSet(0, 1));
- assertEquals(2, sp.getReadFields(1).size());
- assertTrue(sp.getReadFields(1).contains(0));
- assertTrue(sp.getReadFields(1).contains(1));
+ assertThat(sp.getReadFields(1)).hasSize(2);
+ assertThat(sp.getReadFields(1).contains(0)).isTrue();
+ assertThat(sp.getReadFields(1).contains(1)).isTrue();
sp.addReadFields(1, new FieldSet(3));
- assertEquals(3, sp.getReadFields(1).size());
- assertTrue(sp.getReadFields(1).contains(0));
- assertTrue(sp.getReadFields(1).contains(1));
- assertTrue(sp.getReadFields(1).contains(3));
+ assertThat(sp.getReadFields(1)).hasSize(3);
+ assertThat(sp.getReadFields(1).contains(0)).isTrue();
+ assertThat(sp.getReadFields(1).contains(1)).isTrue();
+ assertThat(sp.getReadFields(1).contains(3)).isTrue();
}
- @Test(expected = SemanticProperties.InvalidSemanticAnnotationException.class)
- public void testAddForwardedFieldsTargetTwice1() {
-
- DualInputSemanticProperties sp = new DualInputSemanticProperties();
- sp.addForwardedField(0, 0, 2);
- sp.addForwardedField(0, 1, 2);
+ @Test
+ void testAddForwardedFieldsTargetTwice1() {
+
+ assertThatThrownBy(
+ () -> {
+ DualInputSemanticProperties sp = new DualInputSemanticProperties();
+ sp.addForwardedField(0, 0, 2);
+ sp.addForwardedField(0, 1, 2);
+ })
+ .isInstanceOf(SemanticProperties.InvalidSemanticAnnotationException.class);
}
- @Test(expected = SemanticProperties.InvalidSemanticAnnotationException.class)
- public void testAddForwardedFieldsTargetTwice2() {
-
- DualInputSemanticProperties sp = new DualInputSemanticProperties();
- sp.addForwardedField(1, 0, 2);
- sp.addForwardedField(1, 1, 2);
+ @Test
+ void testAddForwardedFieldsTargetTwice2() {
+
+ assertThatThrownBy(
+ () -> {
+ DualInputSemanticProperties sp = new DualInputSemanticProperties();
+ sp.addForwardedField(1, 0, 2);
+ sp.addForwardedField(1, 1, 2);
+ })
+ .isInstanceOf(SemanticProperties.InvalidSemanticAnnotationException.class);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/ExpressionKeysTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/ExpressionKeysTest.java
index 4fdb5c7ac72..2c8bd032b11 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/ExpressionKeysTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/ExpressionKeysTest.java
@@ -33,42 +33,46 @@ import org.apache.flink.api.java.typeutils.TupleTypeInfo;
import org.apache.flink.api.java.typeutils.TypeExtractor;
import org.apache.commons.lang3.ArrayUtils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
@SuppressWarnings("unused")
public class ExpressionKeysTest {
@Test
- public void testBasicType() {
+ void testBasicType() {
TypeInformation<Long> longType = BasicTypeInfo.LONG_TYPE_INFO;
ExpressionKeys<Long> ek = new ExpressionKeys<>("*", longType);
- Assert.assertArrayEquals(new int[] {0}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).isEqualTo(new int[] {0});
}
- @Test(expected = InvalidProgramException.class)
- public void testGenericNonKeyType() {
+ @Test
+ void testGenericNonKeyType() {
// Fail: GenericType cannot be used as key
TypeInformation<GenericNonKeyType> genericType =
new GenericTypeInfo<>(GenericNonKeyType.class);
- new ExpressionKeys<>("*", genericType);
+ assertThatExceptionOfType(InvalidProgramException.class)
+ .isThrownBy(() -> new ExpressionKeys<>("*", genericType));
}
@Test
- public void testKeyGenericType() {
+ void testKeyGenericType() {
TypeInformation<GenericKeyType> genericType = new GenericTypeInfo<>(GenericKeyType.class);
ExpressionKeys<GenericKeyType> ek = new ExpressionKeys<>("*", genericType);
- Assert.assertArrayEquals(new int[] {0}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).isEqualTo(new int[] {0});
}
@Test
- public void testTupleRangeCheck() throws IllegalArgumentException {
+ void testTupleRangeCheck() throws IllegalArgumentException {
// valid indexes
Keys.rangeCheckFields(new int[] {1, 2, 3, 4}, 4);
@@ -76,18 +80,11 @@ public class ExpressionKeysTest {
// corner case tests
Keys.rangeCheckFields(new int[] {0}, 0);
- Throwable ex = null;
- try {
- // throws illegal argument.
- Keys.rangeCheckFields(new int[] {5}, 0);
- } catch (Throwable iae) {
- ex = iae;
- }
- Assert.assertNotNull(ex);
+ assertThatThrownBy(() -> Keys.rangeCheckFields(new int[] {5}, 0));
}
@Test
- public void testStandardTupleKeys() {
+ void testStandardTupleKeys() {
TupleTypeInfo<Tuple7<String, String, String, String, String, String, String>> typeInfo =
new TupleTypeInfo<>(
BasicTypeInfo.STRING_TYPE_INFO,
@@ -111,19 +108,19 @@ public class ExpressionKeysTest {
ints.length); // copy, just to make sure that the code is not cheating
// by changing the ints.
ek = new ExpressionKeys<>(inInts, typeInfo);
- Assert.assertArrayEquals(ints, ek.computeLogicalKeyPositions());
- Assert.assertEquals(ints.length, ek.computeLogicalKeyPositions().length);
+ assertThat(ek.computeLogicalKeyPositions()).isEqualTo(ints);
+ assertThat(ek.computeLogicalKeyPositions()).hasSameSizeAs(ints);
ArrayUtils.reverse(ints);
inInts = Arrays.copyOf(ints, ints.length);
ek = new ExpressionKeys<>(inInts, typeInfo);
- Assert.assertArrayEquals(ints, ek.computeLogicalKeyPositions());
- Assert.assertEquals(ints.length, ek.computeLogicalKeyPositions().length);
+ assertThat(ek.computeLogicalKeyPositions()).isEqualTo(ints);
+ assertThat(ek.computeLogicalKeyPositions()).hasSameSizeAs(ints);
}
}
@Test
- public void testInvalidTuple() throws Throwable {
+ void testInvalidTuple() {
TupleTypeInfo<Tuple3<String, Tuple3<String, String, String>, String>> typeInfo =
new TupleTypeInfo<>(
BasicTypeInfo.STRING_TYPE_INFO,
@@ -142,18 +139,12 @@ public class ExpressionKeysTest {
new String[] {"f1.f33"}
};
for (String[] test : tests) {
- Throwable e = null;
- try {
- new ExpressionKeys<>(test, typeInfo);
- } catch (Throwable t) {
- e = t;
- }
- Assert.assertNotNull(e);
+ assertThatThrownBy(() -> new ExpressionKeys<>(test, typeInfo));
}
}
- @Test(expected = InvalidProgramException.class)
- public void testTupleNonKeyField() {
+ @Test
+ void testTupleNonKeyField() {
// selected field is not a key type
TypeInformation<Tuple3<String, Long, GenericNonKeyType>> ti =
new TupleTypeInfo<>(
@@ -161,11 +152,12 @@ public class ExpressionKeysTest {
BasicTypeInfo.LONG_TYPE_INFO,
TypeExtractor.getForClass(GenericNonKeyType.class));
- new ExpressionKeys<>(2, ti);
+ assertThatExceptionOfType(InvalidProgramException.class)
+ .isThrownBy(() -> new ExpressionKeys<>(2, ti));
}
@Test
- public void testTupleKeyExpansion() {
+ void testTupleKeyExpansion() {
TupleTypeInfo<Tuple3<String, Tuple3<String, String, String>, String>> typeInfo =
new TupleTypeInfo<>(
BasicTypeInfo.STRING_TYPE_INFO,
@@ -176,39 +168,39 @@ public class ExpressionKeysTest {
BasicTypeInfo.STRING_TYPE_INFO);
ExpressionKeys<Tuple3<String, Tuple3<String, String, String>, String>> fpk =
new ExpressionKeys<>(0, typeInfo);
- Assert.assertArrayEquals(new int[] {0}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).isEqualTo(new int[] {0});
fpk = new ExpressionKeys<>(1, typeInfo);
- Assert.assertArrayEquals(new int[] {1, 2, 3}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(1, 2, 3);
fpk = new ExpressionKeys<>(2, typeInfo);
- Assert.assertArrayEquals(new int[] {4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).isEqualTo(new int[] {4});
fpk = new ExpressionKeys<>(new int[] {0, 1, 2}, typeInfo);
- Assert.assertArrayEquals(new int[] {0, 1, 2, 3, 4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4);
fpk = new ExpressionKeys<>(null, typeInfo, true); // empty case
- Assert.assertArrayEquals(new int[] {0, 1, 2, 3, 4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4);
fpk = new ExpressionKeys<>("*", typeInfo);
- Assert.assertArrayEquals(new int[] {0, 1, 2, 3, 4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4);
// scala style "select all"
fpk = new ExpressionKeys<>("_", typeInfo);
- Assert.assertArrayEquals(new int[] {0, 1, 2, 3, 4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4);
// this was a bug:
fpk = new ExpressionKeys<>("f2", typeInfo);
- Assert.assertArrayEquals(new int[] {4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(4);
fpk = new ExpressionKeys<>(new String[] {"f0", "f1.f0", "f1.f1", "f1.f2", "f2"}, typeInfo);
- Assert.assertArrayEquals(new int[] {0, 1, 2, 3, 4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4);
fpk = new ExpressionKeys<>(new String[] {"f0", "f1.f0", "f1.f1", "f2"}, typeInfo);
- Assert.assertArrayEquals(new int[] {0, 1, 2, 4}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 4);
fpk = new ExpressionKeys<>(new String[] {"f2", "f0"}, typeInfo);
- Assert.assertArrayEquals(new int[] {4, 0}, fpk.computeLogicalKeyPositions());
+ assertThat(fpk.computeLogicalKeyPositions()).containsExactly(4, 0);
TupleTypeInfo<
Tuple3<
@@ -234,57 +226,54 @@ public class ExpressionKeysTest {
Tuple3<Tuple3<String, String, String>, String, String>,
String>>
complexFpk = new ExpressionKeys<>(0, complexTypeInfo);
- Assert.assertArrayEquals(new int[] {0}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).isEqualTo(new int[] {0});
complexFpk = new ExpressionKeys<>(new int[] {0, 1, 2}, complexTypeInfo);
- Assert.assertArrayEquals(
- new int[] {0, 1, 2, 3, 4, 5, 6}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4, 5, 6);
complexFpk = new ExpressionKeys<>("*", complexTypeInfo);
- Assert.assertArrayEquals(
- new int[] {0, 1, 2, 3, 4, 5, 6}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4, 5, 6);
// scala style select all
complexFpk = new ExpressionKeys<>("_", complexTypeInfo);
- Assert.assertArrayEquals(
- new int[] {0, 1, 2, 3, 4, 5, 6}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4, 5, 6);
complexFpk = new ExpressionKeys<>("f1.f0.*", complexTypeInfo);
- Assert.assertArrayEquals(new int[] {1, 2, 3}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).containsExactly(1, 2, 3);
complexFpk = new ExpressionKeys<>("f1.f0", complexTypeInfo);
- Assert.assertArrayEquals(new int[] {1, 2, 3}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).containsExactly(1, 2, 3);
complexFpk = new ExpressionKeys<>("f2", complexTypeInfo);
- Assert.assertArrayEquals(new int[] {6}, complexFpk.computeLogicalKeyPositions());
+ assertThat(complexFpk.computeLogicalKeyPositions()).isEqualTo(new int[] {6});
}
@Test
- public void testPojoKeys() {
+ void testPojoKeys() {
TypeInformation<PojoWithMultiplePojos> ti =
TypeExtractor.getForClass(PojoWithMultiplePojos.class);
ExpressionKeys<PojoWithMultiplePojos> ek;
ek = new ExpressionKeys<>("*", ti);
- Assert.assertArrayEquals(new int[] {0, 1, 2, 3, 4}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4);
ek = new ExpressionKeys<>("p1.*", ti);
- Assert.assertArrayEquals(new int[] {1, 2}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(1, 2);
ek = new ExpressionKeys<>("p2.*", ti);
- Assert.assertArrayEquals(new int[] {3, 4}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(3, 4);
ek = new ExpressionKeys<>("p1", ti);
- Assert.assertArrayEquals(new int[] {1, 2}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(1, 2);
ek = new ExpressionKeys<>("p2", ti);
- Assert.assertArrayEquals(new int[] {3, 4}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(3, 4);
ek = new ExpressionKeys<>("i0", ti);
- Assert.assertArrayEquals(new int[] {0}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).isEqualTo(new int[] {0});
}
@Test
- public void testTupleWithNestedPojo() {
+ void testTupleWithNestedPojo() {
TypeInformation<Tuple3<Integer, Pojo1, PojoWithMultiplePojos>> ti =
new TupleTypeInfo<>(
@@ -295,28 +284,26 @@ public class ExpressionKeysTest {
ExpressionKeys<Tuple3<Integer, Pojo1, PojoWithMultiplePojos>> ek;
ek = new ExpressionKeys<>(0, ti);
- Assert.assertArrayEquals(new int[] {0}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).isEqualTo(new int[] {0});
ek = new ExpressionKeys<>(1, ti);
- Assert.assertArrayEquals(new int[] {1, 2}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(1, 2);
ek = new ExpressionKeys<>(2, ti);
- Assert.assertArrayEquals(new int[] {3, 4, 5, 6, 7}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(3, 4, 5, 6, 7);
ek = new ExpressionKeys<>(new int[] {}, ti, true);
- Assert.assertArrayEquals(
- new int[] {0, 1, 2, 3, 4, 5, 6, 7}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4, 5, 6, 7);
ek = new ExpressionKeys<>("*", ti);
- Assert.assertArrayEquals(
- new int[] {0, 1, 2, 3, 4, 5, 6, 7}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(0, 1, 2, 3, 4, 5, 6, 7);
ek = new ExpressionKeys<>("f2.p1.*", ti);
- Assert.assertArrayEquals(new int[] {4, 5}, ek.computeLogicalKeyPositions());
+ assertThat(ek.computeLogicalKeyPositions()).containsExactly(4, 5);
}
@Test
- public void testOriginalTypes() {
+ void testOriginalTypes() {
TypeInformation<Tuple3<Integer, Pojo1, PojoWithMultiplePojos>> ti =
new TupleTypeInfo<>(
@@ -327,72 +314,62 @@ public class ExpressionKeysTest {
ExpressionKeys<Tuple3<Integer, Pojo1, PojoWithMultiplePojos>> ek;
ek = new ExpressionKeys<>(0, ti);
- Assert.assertArrayEquals(
- new TypeInformation[] {BasicTypeInfo.INT_TYPE_INFO}, ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes()).containsExactly(BasicTypeInfo.INT_TYPE_INFO);
ek = new ExpressionKeys<>(1, ti);
- Assert.assertArrayEquals(
- new TypeInformation[] {TypeExtractor.getForClass(Pojo1.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(Pojo1.class));
ek = new ExpressionKeys<>(2, ti);
- Assert.assertArrayEquals(
- new TypeInformation[] {TypeExtractor.getForClass(PojoWithMultiplePojos.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(PojoWithMultiplePojos.class));
ek = new ExpressionKeys<>(new int[] {}, ti, true);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {
- BasicTypeInfo.INT_TYPE_INFO,
- TypeExtractor.getForClass(Pojo1.class),
- TypeExtractor.getForClass(PojoWithMultiplePojos.class)
- },
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(
+ BasicTypeInfo.INT_TYPE_INFO,
+ TypeExtractor.getForClass(Pojo1.class),
+ TypeExtractor.getForClass(PojoWithMultiplePojos.class));
ek = new ExpressionKeys<>("*", ti);
- Assert.assertArrayEquals(new TypeInformation<?>[] {ti}, ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes()).isEqualTo(new TypeInformation<?>[] {ti});
ek = new ExpressionKeys<>("f1", ti);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {TypeExtractor.getForClass(Pojo1.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(Pojo1.class));
ek = new ExpressionKeys<>("f1.*", ti);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {TypeExtractor.getForClass(Pojo1.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(Pojo1.class));
ek = new ExpressionKeys<>("f2.*", ti);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {TypeExtractor.getForClass(PojoWithMultiplePojos.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(PojoWithMultiplePojos.class));
ek = new ExpressionKeys<>("f2.p2", ti);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {TypeExtractor.getForClass(Pojo2.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(Pojo2.class));
ek = new ExpressionKeys<>("f2.p2.*", ti);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {TypeExtractor.getForClass(Pojo2.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(Pojo2.class));
ek = new ExpressionKeys<>("f2.p2._", ti);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {TypeExtractor.getForClass(Pojo2.class)},
- ek.getOriginalKeyFieldTypes());
+ assertThat(ek.getOriginalKeyFieldTypes())
+ .containsExactly(TypeExtractor.getForClass(Pojo2.class));
}
- @Test(expected = InvalidProgramException.class)
- public void testNonKeyPojoField() {
+ @Test
+ void testNonKeyPojoField() {
// selected field is not a key type
TypeInformation<PojoWithNonKeyField> ti =
TypeExtractor.getForClass(PojoWithNonKeyField.class);
- new ExpressionKeys<>("b", ti);
+ assertThatThrownBy(() -> new ExpressionKeys<>("b", ti))
+ .isInstanceOf(InvalidProgramException.class);
}
@Test
- public void testInvalidPojo() throws Throwable {
+ void testInvalidPojo() {
TypeInformation<ComplexNestedClass> ti =
TypeExtractor.getForClass(ComplexNestedClass.class);
@@ -401,29 +378,23 @@ public class ExpressionKeysTest {
new String[] {"nonexistent"}, new String[] {"date.abc"} // nesting into unnested
};
for (String[] test : tests) {
- Throwable e = null;
- try {
- new ExpressionKeys<>(test, ti);
- } catch (Throwable t) {
- e = t;
- }
- Assert.assertNotNull(e);
+ assertThatThrownBy(() -> new ExpressionKeys<>(test, ti));
}
}
@Test
- public void testAreCompatible1() throws Keys.IncompatibleKeysException {
+ void testAreCompatible1() throws Keys.IncompatibleKeysException {
TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class);
ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>("a", t1);
ExpressionKeys<Pojo1> ek2 = new ExpressionKeys<>("b", t1);
- Assert.assertTrue(ek1.areCompatible(ek2));
- Assert.assertTrue(ek2.areCompatible(ek1));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
+ assertThat(ek2.areCompatible(ek1)).isTrue();
}
@Test
- public void testAreCompatible2() throws Keys.IncompatibleKeysException {
+ void testAreCompatible2() throws Keys.IncompatibleKeysException {
TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class);
TypeInformation<Tuple2<String, Long>> t2 =
new TupleTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
@@ -431,12 +402,12 @@ public class ExpressionKeysTest {
ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>("a", t1);
ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(0, t2);
- Assert.assertTrue(ek1.areCompatible(ek2));
- Assert.assertTrue(ek2.areCompatible(ek1));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
+ assertThat(ek2.areCompatible(ek1)).isTrue();
}
@Test
- public void testAreCompatible3() throws Keys.IncompatibleKeysException {
+ void testAreCompatible3() throws Keys.IncompatibleKeysException {
TypeInformation<String> t1 = BasicTypeInfo.STRING_TYPE_INFO;
TypeInformation<Tuple2<String, Long>> t2 =
new TupleTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
@@ -444,12 +415,12 @@ public class ExpressionKeysTest {
ExpressionKeys<String> ek1 = new ExpressionKeys<>("*", t1);
ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(0, t2);
- Assert.assertTrue(ek1.areCompatible(ek2));
- Assert.assertTrue(ek2.areCompatible(ek1));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
+ assertThat(ek2.areCompatible(ek1)).isTrue();
}
@Test
- public void testAreCompatible4() throws Keys.IncompatibleKeysException {
+ void testAreCompatible4() throws Keys.IncompatibleKeysException {
TypeInformation<PojoWithMultiplePojos> t1 =
TypeExtractor.getForClass(PojoWithMultiplePojos.class);
TypeInformation<Tuple3<String, Long, Integer>> t2 =
@@ -463,12 +434,12 @@ public class ExpressionKeysTest {
ExpressionKeys<Tuple3<String, Long, Integer>> ek2 =
new ExpressionKeys<>(new int[] {0, 0, 2}, t2);
- Assert.assertTrue(ek1.areCompatible(ek2));
- Assert.assertTrue(ek2.areCompatible(ek1));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
+ assertThat(ek2.areCompatible(ek1)).isTrue();
}
@Test
- public void testAreCompatible5() throws Keys.IncompatibleKeysException {
+ void testAreCompatible5() throws Keys.IncompatibleKeysException {
TypeInformation<PojoWithMultiplePojos> t1 =
TypeExtractor.getForClass(PojoWithMultiplePojos.class);
TypeInformation<Tuple2<String, String>> t2 =
@@ -478,12 +449,12 @@ public class ExpressionKeysTest {
new ExpressionKeys<>(new String[] {"p1.b", "p2.a2"}, t1);
ExpressionKeys<Tuple2<String, String>> ek2 = new ExpressionKeys<>("*", t2);
- Assert.assertTrue(ek1.areCompatible(ek2));
- Assert.assertTrue(ek2.areCompatible(ek1));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
+ assertThat(ek2.areCompatible(ek1)).isTrue();
}
- @Test(expected = Keys.IncompatibleKeysException.class)
- public void testAreCompatible6() throws Keys.IncompatibleKeysException {
+ @Test
+ void testAreCompatible6() throws Keys.IncompatibleKeysException {
TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class);
TypeInformation<Tuple2<String, Long>> t2 =
new TupleTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
@@ -491,11 +462,12 @@ public class ExpressionKeysTest {
ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>("a", t1);
ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(1, t2);
- ek1.areCompatible(ek2);
+ assertThatExceptionOfType(Keys.IncompatibleKeysException.class)
+ .isThrownBy(() -> ek1.areCompatible(ek2));
}
- @Test(expected = Keys.IncompatibleKeysException.class)
- public void testAreCompatible7() throws Keys.IncompatibleKeysException {
+ @Test
+ void testAreCompatible7() throws Keys.IncompatibleKeysException {
TypeInformation<Pojo1> t1 = TypeExtractor.getForClass(Pojo1.class);
TypeInformation<Tuple2<String, Long>> t2 =
new TupleTypeInfo<>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO);
@@ -503,11 +475,12 @@ public class ExpressionKeysTest {
ExpressionKeys<Pojo1> ek1 = new ExpressionKeys<>(new String[] {"a", "b"}, t1);
ExpressionKeys<Tuple2<String, Long>> ek2 = new ExpressionKeys<>(0, t2);
- ek1.areCompatible(ek2);
+ assertThatExceptionOfType(Keys.IncompatibleKeysException.class)
+ .isThrownBy(() -> ek1.areCompatible(ek2));
}
@Test
- public void testAreCompatible8() throws Keys.IncompatibleKeysException {
+ void testAreCompatible8() throws Keys.IncompatibleKeysException {
TypeInformation<String> t1 = BasicTypeInfo.STRING_TYPE_INFO;
TypeInformation<Pojo2> t2 = TypeExtractor.getForClass(Pojo2.class);
@@ -516,11 +489,11 @@ public class ExpressionKeysTest {
new Keys.SelectorFunctionKeys<>(
new KeySelector1(), t2, BasicTypeInfo.STRING_TYPE_INFO);
- Assert.assertTrue(ek1.areCompatible(ek2));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
}
@Test
- public void testAreCompatible9() throws Keys.IncompatibleKeysException {
+ void testAreCompatible9() throws Keys.IncompatibleKeysException {
TypeInformation<Tuple3<String, Long, Integer>> t1 =
new TupleTypeInfo<>(
BasicTypeInfo.STRING_TYPE_INFO,
@@ -535,10 +508,10 @@ public class ExpressionKeysTest {
new Keys.SelectorFunctionKeys<>(
new KeySelector3(),
t2,
- new TupleTypeInfo<Tuple2<Integer, String>>(
+ new TupleTypeInfo<>(
BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO));
- Assert.assertTrue(ek1.areCompatible(ek2));
+ assertThat(ek1.areCompatible(ek2)).isTrue();
}
public static class Pojo1 {
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSinkBaseTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSinkBaseTest.java
index 7994ae90c43..6bfae5fe63a 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSinkBaseTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSinkBaseTest.java
@@ -32,108 +32,93 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
import org.apache.flink.types.Nothing;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.concurrent.Future;
import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
/** Checks the GenericDataSinkBase operator for both Rich and non-Rich output formats. */
-@SuppressWarnings("serial")
-public class GenericDataSinkBaseTest implements java.io.Serializable {
+class GenericDataSinkBaseTest implements java.io.Serializable {
- private static TestNonRichInputFormat in = new TestNonRichInputFormat();
- GenericDataSourceBase<String, TestNonRichInputFormat> source =
- new GenericDataSourceBase<String, TestNonRichInputFormat>(
- in,
- new OperatorInformation<String>(BasicTypeInfo.STRING_TYPE_INFO),
- "testSource");
+ private static final TestNonRichInputFormat in = new TestNonRichInputFormat();
+ final GenericDataSourceBase<String, TestNonRichInputFormat> source =
+ new GenericDataSourceBase<>(
+ in, new OperatorInformation<>(BasicTypeInfo.STRING_TYPE_INFO), "testSource");
@Test
- public void testDataSourcePlain() {
- try {
- TestNonRichOutputFormat out = new TestNonRichOutputFormat();
- GenericDataSinkBase<String> sink =
- new GenericDataSinkBase<String>(
- out,
- new UnaryOperatorInformation<String, Nothing>(
- BasicTypeInfo.STRING_TYPE_INFO,
- BasicTypeInfo.getInfoFor(Nothing.class)),
- "test_sink");
- sink.setInput(source);
-
- ExecutionConfig executionConfig = new ExecutionConfig();
- executionConfig.disableObjectReuse();
- in.reset();
- sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig);
- assertEquals(out.output, asList(TestIOData.NAMES));
-
- executionConfig.enableObjectReuse();
- out.clear();
- in.reset();
- sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig);
- assertEquals(out.output, asList(TestIOData.NAMES));
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testDataSourcePlain() throws Exception {
+ TestNonRichOutputFormat out = new TestNonRichOutputFormat();
+ GenericDataSinkBase<String> sink =
+ new GenericDataSinkBase<>(
+ out,
+ new UnaryOperatorInformation<>(
+ BasicTypeInfo.STRING_TYPE_INFO,
+ BasicTypeInfo.getInfoFor(Nothing.class)),
+ "test_sink");
+ sink.setInput(source);
+
+ ExecutionConfig executionConfig = new ExecutionConfig();
+ executionConfig.disableObjectReuse();
+ in.reset();
+ sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig);
+ assertThat(asList(TestIOData.NAMES)).isEqualTo(out.output);
+
+ executionConfig.enableObjectReuse();
+ out.clear();
+ in.reset();
+ sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig);
+ assertThat(asList(TestIOData.NAMES)).isEqualTo(out.output);
}
@Test
- public void testDataSourceWithRuntimeContext() {
- try {
- TestRichOutputFormat out = new TestRichOutputFormat();
- GenericDataSinkBase<String> sink =
- new GenericDataSinkBase<String>(
- out,
- new UnaryOperatorInformation<String, Nothing>(
- BasicTypeInfo.STRING_TYPE_INFO,
- BasicTypeInfo.getInfoFor(Nothing.class)),
- "test_sink");
- sink.setInput(source);
-
- ExecutionConfig executionConfig = new ExecutionConfig();
- final HashMap<String, Accumulator<?, ?>> accumulatorMap =
- new HashMap<String, Accumulator<?, ?>>();
- final HashMap<String, Future<Path>> cpTasks = new HashMap<>();
- final TaskInfo taskInfo = new TaskInfoImpl("test_sink", 1, 0, 1, 0);
- executionConfig.disableObjectReuse();
- in.reset();
-
- sink.executeOnCollections(
- asList(TestIOData.NAMES),
- new RuntimeUDFContext(
- taskInfo,
- null,
- executionConfig,
- cpTasks,
- accumulatorMap,
- UnregisteredMetricsGroup.createOperatorMetricGroup()),
- executionConfig);
-
- assertEquals(out.output, asList(TestIOData.RICH_NAMES));
-
- executionConfig.enableObjectReuse();
- out.clear();
- in.reset();
-
- sink.executeOnCollections(
- asList(TestIOData.NAMES),
- new RuntimeUDFContext(
- taskInfo,
- null,
- executionConfig,
- cpTasks,
- accumulatorMap,
- UnregisteredMetricsGroup.createOperatorMetricGroup()),
- executionConfig);
- assertEquals(out.output, asList(TestIOData.RICH_NAMES));
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testDataSourceWithRuntimeContext() throws Exception {
+ TestRichOutputFormat out = new TestRichOutputFormat();
+ GenericDataSinkBase<String> sink =
+ new GenericDataSinkBase<>(
+ out,
+ new UnaryOperatorInformation<>(
+ BasicTypeInfo.STRING_TYPE_INFO,
+ BasicTypeInfo.getInfoFor(Nothing.class)),
+ "test_sink");
+ sink.setInput(source);
+
+ ExecutionConfig executionConfig = new ExecutionConfig();
+ final HashMap<String, Accumulator<?, ?>> accumulatorMap = new HashMap<>();
+ final HashMap<String, Future<Path>> cpTasks = new HashMap<>();
+ final TaskInfo taskInfo = new TaskInfoImpl("test_sink", 1, 0, 1, 0);
+ executionConfig.disableObjectReuse();
+ in.reset();
+
+ sink.executeOnCollections(
+ asList(TestIOData.NAMES),
+ new RuntimeUDFContext(
+ taskInfo,
+ null,
+ executionConfig,
+ cpTasks,
+ accumulatorMap,
+ UnregisteredMetricsGroup.createOperatorMetricGroup()),
+ executionConfig);
+
+ assertThat(asList(TestIOData.RICH_NAMES)).isEqualTo(out.output);
+
+ executionConfig.enableObjectReuse();
+ out.clear();
+ in.reset();
+
+ sink.executeOnCollections(
+ asList(TestIOData.NAMES),
+ new RuntimeUDFContext(
+ taskInfo,
+ null,
+ executionConfig,
+ cpTasks,
+ accumulatorMap,
+ UnregisteredMetricsGroup.createOperatorMetricGroup()),
+ executionConfig);
+ assertThat(asList(TestIOData.RICH_NAMES)).isEqualTo(out.output);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSourceBaseTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSourceBaseTest.java
index 0bdff3e02df..92c26a69f63 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSourceBaseTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/GenericDataSourceBaseTest.java
@@ -30,103 +30,90 @@ import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Future;
import static java.util.Arrays.asList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
/** Checks the GenericDataSourceBase operator for both Rich and non-Rich input formats. */
-@SuppressWarnings("serial")
-public class GenericDataSourceBaseTest implements java.io.Serializable {
+class GenericDataSourceBaseTest implements java.io.Serializable {
@Test
- public void testDataSourcePlain() {
- try {
- TestNonRichInputFormat in = new TestNonRichInputFormat();
- GenericDataSourceBase<String, TestNonRichInputFormat> source =
- new GenericDataSourceBase<String, TestNonRichInputFormat>(
- in,
- new OperatorInformation<String>(BasicTypeInfo.STRING_TYPE_INFO),
- "testSource");
-
- ExecutionConfig executionConfig = new ExecutionConfig();
- executionConfig.disableObjectReuse();
- List<String> resultMutableSafe = source.executeOnCollections(null, executionConfig);
-
- in.reset();
- executionConfig.enableObjectReuse();
- List<String> resultRegular = source.executeOnCollections(null, executionConfig);
- assertEquals(asList(TestIOData.NAMES), resultMutableSafe);
- assertEquals(asList(TestIOData.NAMES), resultRegular);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testDataSourcePlain() throws Exception {
+ TestNonRichInputFormat in = new TestNonRichInputFormat();
+ GenericDataSourceBase<String, TestNonRichInputFormat> source =
+ new GenericDataSourceBase<>(
+ in,
+ new OperatorInformation<>(BasicTypeInfo.STRING_TYPE_INFO),
+ "testSource");
+
+ ExecutionConfig executionConfig = new ExecutionConfig();
+ executionConfig.disableObjectReuse();
+ List<String> resultMutableSafe = source.executeOnCollections(null, executionConfig);
+
+ in.reset();
+ executionConfig.enableObjectReuse();
+ List<String> resultRegular = source.executeOnCollections(null, executionConfig);
+ assertThat(resultMutableSafe).isEqualTo(asList(TestIOData.NAMES));
+ assertThat(resultRegular).isEqualTo(asList(TestIOData.NAMES));
}
@Test
- public void testDataSourceWithRuntimeContext() {
- try {
- TestRichInputFormat in = new TestRichInputFormat();
- GenericDataSourceBase<String, TestRichInputFormat> source =
- new GenericDataSourceBase<String, TestRichInputFormat>(
- in,
- new OperatorInformation<String>(BasicTypeInfo.STRING_TYPE_INFO),
- "testSource");
-
- final HashMap<String, Accumulator<?, ?>> accumulatorMap =
- new HashMap<String, Accumulator<?, ?>>();
- final HashMap<String, Future<Path>> cpTasks = new HashMap<>();
- final TaskInfo taskInfo = new TaskInfoImpl("test_source", 1, 0, 1, 0);
-
- ExecutionConfig executionConfig = new ExecutionConfig();
- executionConfig.disableObjectReuse();
- assertEquals(false, in.hasBeenClosed());
- assertEquals(false, in.hasBeenOpened());
-
- List<String> resultMutableSafe =
- source.executeOnCollections(
- new RuntimeUDFContext(
- taskInfo,
- null,
- executionConfig,
- cpTasks,
- accumulatorMap,
- UnregisteredMetricsGroup.createOperatorMetricGroup()),
- executionConfig);
-
- assertEquals(true, in.hasBeenClosed());
- assertEquals(true, in.hasBeenOpened());
-
- in.reset();
- executionConfig.enableObjectReuse();
- assertEquals(false, in.hasBeenClosed());
- assertEquals(false, in.hasBeenOpened());
-
- List<String> resultRegular =
- source.executeOnCollections(
- new RuntimeUDFContext(
- taskInfo,
- null,
- executionConfig,
- cpTasks,
- accumulatorMap,
- UnregisteredMetricsGroup.createOperatorMetricGroup()),
- executionConfig);
-
- assertEquals(true, in.hasBeenClosed());
- assertEquals(true, in.hasBeenOpened());
-
- assertEquals(asList(TestIOData.RICH_NAMES), resultMutableSafe);
- assertEquals(asList(TestIOData.RICH_NAMES), resultRegular);
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ void testDataSourceWithRuntimeContext() throws Exception {
+ TestRichInputFormat in = new TestRichInputFormat();
+ GenericDataSourceBase<String, TestRichInputFormat> source =
+ new GenericDataSourceBase<>(
+ in,
+ new OperatorInformation<>(BasicTypeInfo.STRING_TYPE_INFO),
+ "testSource");
+
+ final HashMap<String, Accumulator<?, ?>> accumulatorMap = new HashMap<>();
+ final HashMap<String, Future<Path>> cpTasks = new HashMap<>();
+ final TaskInfo taskInfo = new TaskInfoImpl("test_source", 1, 0, 1, 0);
+
+ ExecutionConfig executionConfig = new ExecutionConfig();
+ executionConfig.disableObjectReuse();
+ assertThat(in.hasBeenClosed()).isFalse();
+ assertThat(in.hasBeenOpened()).isFalse();
+
+ List<String> resultMutableSafe =
+ source.executeOnCollections(
+ new RuntimeUDFContext(
+ taskInfo,
+ null,
+ executionConfig,
+ cpTasks,
+ accumulatorMap,
+ UnregisteredMetricsGroup.createOperatorMetricGroup()),
+ executionConfig);
+
+ assertThat(in.hasBeenClosed()).isTrue();
+ assertThat(in.hasBeenOpened()).isTrue();
+
+ in.reset();
+ executionConfig.enableObjectReuse();
+ assertThat(in.hasBeenClosed()).isFalse();
+ assertThat(in.hasBeenOpened()).isFalse();
+
+ List<String> resultRegular =
+ source.executeOnCollections(
+ new RuntimeUDFContext(
+ taskInfo,
+ null,
+ executionConfig,
+ cpTasks,
+ accumulatorMap,
+ UnregisteredMetricsGroup.createOperatorMetricGroup()),
+ executionConfig);
+
+ assertThat(in.hasBeenClosed()).isTrue();
+ assertThat(in.hasBeenOpened()).isTrue();
+
+ assertThat(resultMutableSafe).isEqualTo(asList(TestIOData.RICH_NAMES));
+ assertThat(resultRegular).isEqualTo(asList(TestIOData.RICH_NAMES));
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/OrderingTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/OrderingTest.java
index babf002dfc6..28e81fc0c3e 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/OrderingTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/OrderingTest.java
@@ -18,32 +18,31 @@
package org.apache.flink.api.common.operators;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
public class OrderingTest {
@Test
- public void testNewOrdering() {
+ void testNewOrdering() {
Ordering ordering = new Ordering();
// add a field
ordering.appendOrdering(3, Integer.class, Order.ASCENDING);
- assertEquals(1, ordering.getNumberOfFields());
+ assertThat(ordering.getNumberOfFields()).isOne();
// add a second field
ordering.appendOrdering(1, Long.class, Order.DESCENDING);
- assertEquals(2, ordering.getNumberOfFields());
+ assertThat(ordering.getNumberOfFields()).isEqualTo(2);
// duplicate field index does not change Ordering
ordering.appendOrdering(1, String.class, Order.ASCENDING);
- assertEquals(2, ordering.getNumberOfFields());
+ assertThat(ordering.getNumberOfFields()).isEqualTo(2);
// verify field positions, types, and orderings
- assertArrayEquals(new int[] {3, 1}, ordering.getFieldPositions());
- assertArrayEquals(new Class[] {Integer.class, Long.class}, ordering.getTypes());
- assertArrayEquals(new boolean[] {true, false}, ordering.getFieldSortDirections());
+ assertThat(ordering.getFieldPositions()).containsExactly(3, 1);
+ assertThat(ordering.getTypes()).containsExactly(Integer.class, Long.class);
+ assertThat(ordering.getFieldSortDirections()).containsExactly(true, false);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/ResourceSpecTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/ResourceSpecTest.java
index cfc4e755f14..2d8de569f3e 100755
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/ResourceSpecTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/ResourceSpecTest.java
@@ -21,68 +21,74 @@ package org.apache.flink.api.common.operators;
import org.apache.flink.api.common.resources.CPUResource;
import org.apache.flink.api.common.resources.ExternalResource;
import org.apache.flink.core.testutils.CommonTestUtils;
-import org.apache.flink.util.TestLogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests for ResourceSpec class, including its all public api: isValid, lessThanOrEqual, equals,
* hashCode and merge.
*/
-public class ResourceSpecTest extends TestLogger {
+class ResourceSpecTest {
private static final String EXTERNAL_RESOURCE_NAME = "gpu";
@Test
- public void testLessThanOrEqualWhenBothSpecified() {
+ void testLessThanOrEqualWhenBothSpecified() {
ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
- assertTrue(rs1.lessThanOrEqual(rs2));
- assertTrue(rs2.lessThanOrEqual(rs1));
+ assertThat(rs1.lessThanOrEqual(rs2)).isTrue();
+ assertThat(rs2.lessThanOrEqual(rs1)).isTrue();
ResourceSpec rs3 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1))
.build();
- assertTrue(rs1.lessThanOrEqual(rs3));
- assertFalse(rs3.lessThanOrEqual(rs1));
+ assertThat(rs1.lessThanOrEqual(rs3)).isTrue();
+ assertThat(rs3.lessThanOrEqual(rs1)).isFalse();
ResourceSpec rs4 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2))
.build();
- assertFalse(rs4.lessThanOrEqual(rs3));
- assertTrue(rs3.lessThanOrEqual(rs4));
+ assertThat(rs4.lessThanOrEqual(rs3)).isFalse();
+ assertThat(rs3.lessThanOrEqual(rs4)).isTrue();
}
@Test
- public void testLessThanOrEqualWhenBothUnknown() {
- assertTrue(ResourceSpec.UNKNOWN.lessThanOrEqual(ResourceSpec.UNKNOWN));
+ void testLessThanOrEqualWhenBothUnknown() {
+ assertThat(ResourceSpec.UNKNOWN.lessThanOrEqual(ResourceSpec.UNKNOWN)).isTrue();
}
- @Test(expected = IllegalArgumentException.class)
- public void testLessThanOrEqualWhenUnknownWithSpecified() {
- final ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
- assertTrue(ResourceSpec.UNKNOWN.lessThanOrEqual(rs1));
+ @Test
+ void testLessThanOrEqualWhenUnknownWithSpecified() {
+ assertThatThrownBy(
+ () ->
+ ResourceSpec.UNKNOWN.lessThanOrEqual(
+ ResourceSpec.newBuilder(1.0, 100).build()))
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testLessThanOrEqualWhenSpecifiedWithUnknown() {
- final ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
- assertTrue(rs1.lessThanOrEqual(ResourceSpec.UNKNOWN));
+ @Test
+ void testLessThanOrEqualWhenSpecifiedWithUnknown() {
+ // final ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
+ // assertThat(rs1.lessThanOrEqual(ResourceSpec.UNKNOWN)).isTrue();
+
+ assertThatThrownBy(
+ () ->
+ ResourceSpec.newBuilder(1.0, 100)
+ .build()
+ .lessThanOrEqual(ResourceSpec.UNKNOWN))
+ .isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testEquals() throws Exception {
+ void testEquals() {
ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
- assertEquals(rs1, rs2);
- assertEquals(rs2, rs1);
+ assertThat(rs2).isEqualTo(rs1);
+ assertThat(rs1).isEqualTo(rs2);
ResourceSpec rs3 =
ResourceSpec.newBuilder(1.0, 100)
@@ -92,20 +98,20 @@ public class ResourceSpecTest extends TestLogger {
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1))
.build();
- assertNotEquals(rs3, rs4);
+ assertThat(rs4).isNotEqualTo(rs3);
ResourceSpec rs5 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2))
.build();
- assertEquals(rs3, rs5);
+ assertThat(rs5).isEqualTo(rs3);
}
@Test
- public void testHashCode() throws Exception {
+ void testHashCode() {
ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
- assertEquals(rs1.hashCode(), rs2.hashCode());
+ assertThat(rs2).hasSameHashCodeAs(rs1);
ResourceSpec rs3 =
ResourceSpec.newBuilder(1.0, 100)
@@ -115,17 +121,17 @@ public class ResourceSpecTest extends TestLogger {
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1))
.build();
- assertNotEquals(rs3.hashCode(), rs4.hashCode());
+ assertThat(rs4.hashCode()).isNotEqualTo(rs3.hashCode());
ResourceSpec rs5 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2))
.build();
- assertEquals(rs3.hashCode(), rs5.hashCode());
+ assertThat(rs5).hasSameHashCodeAs(rs3);
}
@Test
- public void testMerge() throws Exception {
+ void testMerge() {
ResourceSpec rs1 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1))
@@ -133,31 +139,29 @@ public class ResourceSpecTest extends TestLogger {
ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
ResourceSpec rs3 = rs1.merge(rs2);
- assertEquals(new CPUResource(2.0), rs3.getCpuCores());
- assertEquals(200, rs3.getTaskHeapMemory().getMebiBytes());
- assertEquals(
- new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1),
- rs3.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
+ assertThat(rs3.getCpuCores()).isEqualTo(new CPUResource(2.0));
+ assertThat(rs3.getTaskHeapMemory().getMebiBytes()).isEqualTo(200);
+ assertThat(rs3.getExtendedResource(EXTERNAL_RESOURCE_NAME).get())
+ .isEqualTo(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1));
ResourceSpec rs4 = rs1.merge(rs3);
- assertEquals(
- new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2),
- rs4.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
+ assertThat(rs4.getExtendedResource(EXTERNAL_RESOURCE_NAME).get())
+ .isEqualTo(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2));
}
@Test
- public void testSerializable() throws Exception {
+ void testSerializable() throws Exception {
ResourceSpec rs1 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1))
.build();
ResourceSpec rs2 = CommonTestUtils.createCopySerializable(rs1);
- assertEquals(rs1, rs2);
+ assertThat(rs2).isEqualTo(rs1);
}
@Test
- public void testMergeThisUnknown() throws Exception {
+ void testMergeThisUnknown() {
final ResourceSpec spec1 = ResourceSpec.UNKNOWN;
final ResourceSpec spec2 =
ResourceSpec.newBuilder(1.0, 100)
@@ -166,11 +170,11 @@ public class ResourceSpecTest extends TestLogger {
final ResourceSpec merged = spec1.merge(spec2);
- assertEquals(ResourceSpec.UNKNOWN, merged);
+ assertThat(merged).isEqualTo(ResourceSpec.UNKNOWN);
}
@Test
- public void testMergeOtherUnknown() throws Exception {
+ void testMergeOtherUnknown() {
final ResourceSpec spec1 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1))
@@ -179,39 +183,39 @@ public class ResourceSpecTest extends TestLogger {
final ResourceSpec merged = spec1.merge(spec2);
- assertEquals(ResourceSpec.UNKNOWN, merged);
+ assertThat(merged).isEqualTo(ResourceSpec.UNKNOWN);
}
@Test
- public void testMergeBothUnknown() throws Exception {
+ void testMergeBothUnknown() {
final ResourceSpec spec1 = ResourceSpec.UNKNOWN;
final ResourceSpec spec2 = ResourceSpec.UNKNOWN;
final ResourceSpec merged = spec1.merge(spec2);
- assertEquals(ResourceSpec.UNKNOWN, merged);
+ assertThat(merged).isEqualTo(ResourceSpec.UNKNOWN);
}
@Test
- public void testMergeWithSerializationCopy() throws Exception {
+ void testMergeWithSerializationCopy() throws Exception {
final ResourceSpec spec1 = CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN);
final ResourceSpec spec2 = CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN);
final ResourceSpec merged = spec1.merge(spec2);
- assertEquals(ResourceSpec.UNKNOWN, merged);
+ assertThat(merged).isEqualTo(ResourceSpec.UNKNOWN);
}
@Test
- public void testSingletonPropertyOfUnknown() throws Exception {
+ void testSingletonPropertyOfUnknown() throws Exception {
final ResourceSpec copiedSpec =
CommonTestUtils.createCopySerializable(ResourceSpec.UNKNOWN);
- assertSame(ResourceSpec.UNKNOWN, copiedSpec);
+ assertThat(copiedSpec).isSameAs(ResourceSpec.UNKNOWN);
}
@Test
- public void testSubtract() {
+ void testSubtract() {
final ResourceSpec rs1 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1))
@@ -222,23 +226,22 @@ public class ResourceSpecTest extends TestLogger {
.build();
final ResourceSpec subtracted = rs1.subtract(rs2);
- assertEquals(new CPUResource(0.8), subtracted.getCpuCores());
- assertEquals(0, subtracted.getTaskHeapMemory().getMebiBytes());
- assertEquals(
- new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.6),
- subtracted.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
+ assertThat(subtracted.getCpuCores()).isEqualTo(new CPUResource(0.8));
+ assertThat(subtracted.getTaskHeapMemory().getMebiBytes()).isZero();
+ assertThat(subtracted.getExtendedResource(EXTERNAL_RESOURCE_NAME).get())
+ .isEqualTo(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.6));
}
- @Test(expected = IllegalArgumentException.class)
- public void testSubtractOtherHasLargerResources() {
+ @Test
+ void testSubtractOtherHasLargerResources() {
final ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
final ResourceSpec rs2 = ResourceSpec.newBuilder(0.2, 200).build();
- rs1.subtract(rs2);
+ assertThatThrownBy(() -> rs1.subtract(rs2)).isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void testSubtractThisUnknown() {
+ void testSubtractThisUnknown() {
final ResourceSpec rs1 = ResourceSpec.UNKNOWN;
final ResourceSpec rs2 =
ResourceSpec.newBuilder(0.2, 100)
@@ -246,11 +249,11 @@ public class ResourceSpecTest extends TestLogger {
.build();
final ResourceSpec subtracted = rs1.subtract(rs2);
- assertEquals(ResourceSpec.UNKNOWN, subtracted);
+ assertThat(subtracted).isEqualTo(ResourceSpec.UNKNOWN);
}
@Test
- public void testSubtractOtherUnknown() {
+ void testSubtractOtherUnknown() {
final ResourceSpec rs1 =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1))
@@ -258,25 +261,25 @@ public class ResourceSpecTest extends TestLogger {
final ResourceSpec rs2 = ResourceSpec.UNKNOWN;
final ResourceSpec subtracted = rs1.subtract(rs2);
- assertEquals(ResourceSpec.UNKNOWN, subtracted);
+ assertThat(subtracted).isEqualTo(ResourceSpec.UNKNOWN);
}
@Test
- public void testZeroExtendedResourceFromConstructor() {
+ void testZeroExtendedResourceFromConstructor() {
final ResourceSpec resourceSpec =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0))
.build();
- assertEquals(resourceSpec.getExtendedResources().size(), 0);
+ assertThat(resourceSpec.getExtendedResources()).isEmpty();
}
@Test
- public void testZeroExtendedResourceFromSubtract() {
+ void testZeroExtendedResourceFromSubtract() {
final ResourceSpec resourceSpec =
ResourceSpec.newBuilder(1.0, 100)
.setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.0))
.build();
- assertEquals(resourceSpec.subtract(resourceSpec).getExtendedResources().size(), 0);
+ assertThat(resourceSpec.subtract(resourceSpec).getExtendedResources()).isEmpty();
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/SelectorFunctionKeysTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/SelectorFunctionKeysTest.java
index 0cfacfc1ebb..fb5f29ae9cb 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/SelectorFunctionKeysTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/SelectorFunctionKeysTest.java
@@ -29,13 +29,14 @@ import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.api.java.typeutils.TupleTypeInfo;
import org.apache.flink.api.java.typeutils.TypeExtractor;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class SelectorFunctionKeysTest {
+import static org.assertj.core.api.Assertions.assertThat;
+
+class SelectorFunctionKeysTest {
@Test
- public void testAreCompatible1() throws Keys.IncompatibleKeysException {
+ void testAreCompatible1() throws Keys.IncompatibleKeysException {
TypeInformation<Pojo2> t1 = TypeExtractor.getForClass(Pojo2.class);
TypeInformation<Tuple2<Integer, String>> t2 =
new TupleTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
@@ -47,12 +48,12 @@ public class SelectorFunctionKeysTest {
new Keys.SelectorFunctionKeys<>(
new KeySelector2(), t2, BasicTypeInfo.STRING_TYPE_INFO);
- Assert.assertTrue(k1.areCompatible(k2));
- Assert.assertTrue(k2.areCompatible(k1));
+ assertThat(k1.areCompatible(k2)).isTrue();
+ assertThat(k2.areCompatible(k1)).isTrue();
}
@Test
- public void testAreCompatible2() throws Keys.IncompatibleKeysException {
+ void testAreCompatible2() throws Keys.IncompatibleKeysException {
TypeInformation<PojoWithMultiplePojos> t1 =
TypeExtractor.getForClass(PojoWithMultiplePojos.class);
TypeInformation<Tuple3<Long, Pojo1, Integer>> t2 =
@@ -68,12 +69,12 @@ public class SelectorFunctionKeysTest {
Keys<Tuple3<Long, Pojo1, Integer>> k2 =
new Keys.SelectorFunctionKeys<>(new KeySelector4(), t2, kt);
- Assert.assertTrue(k1.areCompatible(k2));
- Assert.assertTrue(k2.areCompatible(k1));
+ assertThat(k1.areCompatible(k2)).isTrue();
+ assertThat(k2.areCompatible(k1)).isTrue();
}
@Test
- public void testAreCompatible3() throws Keys.IncompatibleKeysException {
+ void testAreCompatible3() throws Keys.IncompatibleKeysException {
TypeInformation<String> t1 = BasicTypeInfo.STRING_TYPE_INFO;
TypeInformation<Pojo2> t2 = TypeExtractor.getForClass(Pojo2.class);
@@ -82,11 +83,11 @@ public class SelectorFunctionKeysTest {
new Keys.SelectorFunctionKeys<>(
new KeySelector1(), t2, BasicTypeInfo.STRING_TYPE_INFO);
- Assert.assertTrue(sk2.areCompatible(ek1));
+ assertThat(sk2.areCompatible(ek1)).isTrue();
}
@Test
- public void testAreCompatible4() throws Keys.IncompatibleKeysException {
+ void testAreCompatible4() throws Keys.IncompatibleKeysException {
TypeInformation<Tuple3<String, Long, Integer>> t1 =
new TupleTypeInfo<>(
BasicTypeInfo.STRING_TYPE_INFO,
@@ -101,14 +102,14 @@ public class SelectorFunctionKeysTest {
new Keys.SelectorFunctionKeys<>(
new KeySelector3(),
t2,
- new TupleTypeInfo<Tuple2<Integer, String>>(
+ new TupleTypeInfo<>(
BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO));
- Assert.assertTrue(sk2.areCompatible(ek1));
+ assertThat(sk2.areCompatible(ek1)).isTrue();
}
@Test
- public void testOriginalTypes1() throws Keys.IncompatibleKeysException {
+ void testOriginalTypes1() {
TypeInformation<Tuple2<Integer, String>> t2 =
new TupleTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
@@ -116,13 +117,11 @@ public class SelectorFunctionKeysTest {
new Keys.SelectorFunctionKeys<>(
new KeySelector2(), t2, BasicTypeInfo.STRING_TYPE_INFO);
- Assert.assertArrayEquals(
- new TypeInformation<?>[] {BasicTypeInfo.STRING_TYPE_INFO},
- k.getOriginalKeyFieldTypes());
+ assertThat(k.getOriginalKeyFieldTypes()).containsExactly(BasicTypeInfo.STRING_TYPE_INFO);
}
@Test
- public void testOriginalTypes2() throws Exception {
+ void testOriginalTypes2() {
final TupleTypeInfo<Tuple2<Integer, String>> t1 =
new TupleTypeInfo<>(BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
TypeInformation<PojoWithMultiplePojos> t2 =
@@ -131,43 +130,39 @@ public class SelectorFunctionKeysTest {
Keys<PojoWithMultiplePojos> sk =
new Keys.SelectorFunctionKeys<>(new KeySelector3(), t2, t1);
- Assert.assertArrayEquals(new TypeInformation<?>[] {t1}, sk.getOriginalKeyFieldTypes());
+ assertThat(sk.getOriginalKeyFieldTypes()).isEqualTo(new TypeInformation<?>[] {t1});
}
- @SuppressWarnings("serial")
public static class KeySelector1 implements KeySelector<Pojo2, String> {
@Override
- public String getKey(Pojo2 v) throws Exception {
+ public String getKey(Pojo2 v) {
return v.b2;
}
}
- @SuppressWarnings("serial")
public static class KeySelector2 implements KeySelector<Tuple2<Integer, String>, String> {
@Override
- public String getKey(Tuple2<Integer, String> v) throws Exception {
+ public String getKey(Tuple2<Integer, String> v) {
return v.f1;
}
}
- @SuppressWarnings("serial")
public static class KeySelector3
implements KeySelector<PojoWithMultiplePojos, Tuple2<Integer, String>> {
@Override
- public Tuple2<Integer, String> getKey(PojoWithMultiplePojos v) throws Exception {
+ public Tuple2<Integer, String> getKey(PojoWithMultiplePojos v) {
return new Tuple2<>(v.i0, v.p1.b);
}
}
- @SuppressWarnings("serial")
public static class KeySelector4
implements KeySelector<Tuple3<Long, Pojo1, Integer>, Tuple2<Integer, String>> {
@Override
- public Tuple2<Integer, String> getKey(Tuple3<Long, Pojo1, Integer> v) throws Exception {
+ public Tuple2<Integer, String> getKey(Tuple3<Long, Pojo1, Integer> v) {
return new Tuple2<>(v.f2, v.f1.a);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/SingleInputSemanticPropertiesTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/SingleInputSemanticPropertiesTest.java
index e127f092101..93e339f9265 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/SingleInputSemanticPropertiesTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/SingleInputSemanticPropertiesTest.java
@@ -21,14 +21,15 @@ package org.apache.flink.api.common.operators;
import org.apache.flink.api.common.operators.SemanticProperties.InvalidSemanticAnnotationException;
import org.apache.flink.api.common.operators.util.FieldSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class SingleInputSemanticPropertiesTest {
+class SingleInputSemanticPropertiesTest {
@Test
- public void testGetTargetFields() {
+ void testGetTargetFields() {
SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
sp.addForwardedField(0, 1);
@@ -36,16 +37,16 @@ public class SingleInputSemanticPropertiesTest {
sp.addForwardedField(2, 3);
sp.addForwardedField(3, 2);
- assertEquals(1, sp.getForwardingTargetFields(0, 0).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 1).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 2).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 3).size());
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(1));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(4));
- assertTrue(sp.getForwardingTargetFields(0, 2).contains(3));
- assertTrue(sp.getForwardingTargetFields(0, 3).contains(2));
- assertNotNull(sp.getForwardingTargetFields(0, 4));
- assertEquals(0, sp.getForwardingTargetFields(0, 4).size());
+ assertThat(sp.getForwardingTargetFields(0, 0)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 1)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 2)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 3)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 2).contains(3)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 3).contains(2)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 4)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(0, 4)).isEmpty();
sp = new SingleInputSemanticProperties();
sp.addForwardedField(0, 0);
@@ -54,19 +55,19 @@ public class SingleInputSemanticPropertiesTest {
sp.addForwardedField(1, 2);
sp.addForwardedField(1, 3);
- assertEquals(2, sp.getForwardingTargetFields(0, 0).size());
- assertEquals(3, sp.getForwardingTargetFields(0, 1).size());
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(0));
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(4));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(1));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(2));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(3));
- assertNotNull(sp.getForwardingTargetFields(0, 2));
- assertEquals(0, sp.getForwardingTargetFields(0, 2).size());
+ assertThat(sp.getForwardingTargetFields(0, 0)).hasSize(2);
+ assertThat(sp.getForwardingTargetFields(0, 1)).hasSize(3);
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(0)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(4)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(2)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(3)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 2)).isNotNull();
+ assertThat(sp.getForwardingTargetFields(0, 2)).isEmpty();
}
@Test
- public void testGetSourceField() {
+ void testGetSourceField() {
SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
sp.addForwardedField(0, 1);
@@ -74,12 +75,12 @@ public class SingleInputSemanticPropertiesTest {
sp.addForwardedField(2, 3);
sp.addForwardedField(3, 2);
- assertEquals(0, sp.getForwardingSourceField(0, 1));
- assertEquals(1, sp.getForwardingSourceField(0, 4));
- assertEquals(2, sp.getForwardingSourceField(0, 3));
- assertEquals(3, sp.getForwardingSourceField(0, 2));
- assertTrue(sp.getForwardingSourceField(0, 0) < 0);
- assertTrue(sp.getForwardingSourceField(0, 5) < 0);
+ assertThat(sp.getForwardingSourceField(0, 1)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 4)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 3)).isEqualTo(2);
+ assertThat(sp.getForwardingSourceField(0, 2)).isEqualTo(3);
+ assertThat(sp.getForwardingSourceField(0, 0)).isNegative();
+ assertThat(sp.getForwardingSourceField(0, 5)).isNegative();
sp = new SingleInputSemanticProperties();
sp.addForwardedField(0, 0);
@@ -88,98 +89,113 @@ public class SingleInputSemanticPropertiesTest {
sp.addForwardedField(1, 2);
sp.addForwardedField(1, 3);
- assertEquals(0, sp.getForwardingSourceField(0, 0));
- assertEquals(0, sp.getForwardingSourceField(0, 4));
- assertEquals(1, sp.getForwardingSourceField(0, 1));
- assertEquals(1, sp.getForwardingSourceField(0, 2));
- assertEquals(1, sp.getForwardingSourceField(0, 3));
- assertTrue(sp.getForwardingSourceField(0, 5) < 0);
+ assertThat(sp.getForwardingSourceField(0, 0)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 4)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 1)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 2)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 3)).isOne();
+ assertThat(sp.getForwardingSourceField(0, 5)).isNegative();
}
@Test
- public void testGetReadSet() {
+ void testGetReadSet() {
SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
sp.addReadFields(new FieldSet(0, 1));
- assertEquals(2, sp.getReadFields(0).size());
- assertTrue(sp.getReadFields(0).contains(0));
- assertTrue(sp.getReadFields(0).contains(1));
+ assertThat(sp.getReadFields(0)).hasSize(2);
+ assertThat(sp.getReadFields(0).contains(0)).isTrue();
+ assertThat(sp.getReadFields(0).contains(1)).isTrue();
sp.addReadFields(new FieldSet(3));
- assertEquals(3, sp.getReadFields(0).size());
- assertTrue(sp.getReadFields(0).contains(0));
- assertTrue(sp.getReadFields(0).contains(1));
- assertTrue(sp.getReadFields(0).contains(3));
+ assertThat(sp.getReadFields(0)).hasSize(3);
+ assertThat(sp.getReadFields(0).contains(0)).isTrue();
+ assertThat(sp.getReadFields(0).contains(1)).isTrue();
+ assertThat(sp.getReadFields(0).contains(3)).isTrue();
}
- @Test(expected = InvalidSemanticAnnotationException.class)
- public void testAddForwardedFieldsTargetTwice() {
-
- SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
- sp.addForwardedField(0, 2);
- sp.addForwardedField(1, 2);
+ @Test
+ void testAddForwardedFieldsTargetTwice() {
+ assertThatThrownBy(
+ () -> {
+ SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
+ sp.addForwardedField(0, 2);
+ sp.addForwardedField(1, 2);
+ })
+ .isInstanceOf(InvalidSemanticAnnotationException.class);
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetTargetFieldInvalidIndex() {
+ @Test
+ void testGetTargetFieldInvalidIndex() {
SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
sp.addForwardedField(0, 0);
- sp.getForwardingTargetFields(1, 0);
+ assertThatThrownBy(() -> sp.getForwardingTargetFields(1, 0))
+ .isInstanceOf(IndexOutOfBoundsException.class);
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetSourceFieldInvalidIndex() {
+ @Test
+ void testGetSourceFieldInvalidIndex() {
SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
sp.addForwardedField(0, 0);
- sp.getForwardingSourceField(1, 0);
+ assertThatThrownBy(() -> sp.getForwardingSourceField(1, 0))
+ .isInstanceOf(IndexOutOfBoundsException.class);
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testGetReadFieldsInvalidIndex() {
+ @Test
+ void testGetReadFieldsInvalidIndex() {
SingleInputSemanticProperties sp = new SingleInputSemanticProperties();
sp.addReadFields(new FieldSet(0, 1));
- sp.getReadFields(1);
+ assertThatThrownBy(() -> sp.getReadFields(1)).isInstanceOf(IndexOutOfBoundsException.class);
}
@Test
- public void testAllForwardedSingleInputSemProps() {
+ void testAllForwardedSingleInputSemProps() {
SingleInputSemanticProperties sp =
new SingleInputSemanticProperties.AllFieldsForwardedProperties();
- assertEquals(1, sp.getForwardingTargetFields(0, 0).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 1).size());
- assertEquals(1, sp.getForwardingTargetFields(0, 123).size());
- assertTrue(sp.getForwardingTargetFields(0, 0).contains(0));
- assertTrue(sp.getForwardingTargetFields(0, 1).contains(1));
- assertTrue(sp.getForwardingTargetFields(0, 123).contains(123));
+ assertThat(sp.getForwardingTargetFields(0, 0)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 1)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 123)).hasSize(1);
+ assertThat(sp.getForwardingTargetFields(0, 0).contains(0)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 1).contains(1)).isTrue();
+ assertThat(sp.getForwardingTargetFields(0, 123).contains(123)).isTrue();
- assertEquals(0, sp.getForwardingSourceField(0, 0));
- assertEquals(2, sp.getForwardingSourceField(0, 2));
- assertEquals(123, sp.getForwardingSourceField(0, 123));
+ assertThat(sp.getForwardingSourceField(0, 0)).isZero();
+ assertThat(sp.getForwardingSourceField(0, 2)).isEqualTo(2);
+ assertThat(sp.getForwardingSourceField(0, 123)).isEqualTo(123);
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testAllForwardedSingleInputSemPropsInvalidIndex1() {
-
- SingleInputSemanticProperties sp =
- new SingleInputSemanticProperties.AllFieldsForwardedProperties();
- sp.getForwardingSourceField(1, 0);
+ @Test
+ void testAllForwardedSingleInputSemPropsInvalidIndex1() {
+
+ assertThatThrownBy(
+ () -> {
+ SingleInputSemanticProperties sp =
+ new SingleInputSemanticProperties
+ .AllFieldsForwardedProperties();
+ sp.getForwardingSourceField(1, 0);
+ })
+ .isInstanceOf(IndexOutOfBoundsException.class);
}
- @Test(expected = IndexOutOfBoundsException.class)
- public void testAllForwardedSingleInputSemPropsInvalidIndex2() {
-
- SingleInputSemanticProperties sp =
- new SingleInputSemanticProperties.AllFieldsForwardedProperties();
- sp.getForwardingTargetFields(1, 0);
+ @Test
+ void testAllForwardedSingleInputSemPropsInvalidIndex2() {
+
+ assertThatThrownBy(
+ () -> {
+ SingleInputSemanticProperties sp =
+ new SingleInputSemanticProperties
+ .AllFieldsForwardedProperties();
+ sp.getForwardingTargetFields(1, 0);
+ })
+ .isInstanceOf(IndexOutOfBoundsException.class);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/SlotSharingGroupTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/SlotSharingGroupTest.java
index e48920da348..64d89229b5c 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/SlotSharingGroupTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/SlotSharingGroupTest.java
@@ -20,19 +20,17 @@ package org.apache.flink.api.common.operators;
import org.apache.flink.configuration.MemorySize;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Collections;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Tests for {@link SlotSharingGroup}. */
-public class SlotSharingGroupTest {
+class SlotSharingGroupTest {
@Test
- public void testBuildSlotSharingGroupWithSpecificResource() {
+ void testBuildSlotSharingGroupWithSpecificResource() {
final String name = "ssg";
final MemorySize heap = MemorySize.ofMebiBytes(100);
final MemorySize offHeap = MemorySize.ofMebiBytes(200);
@@ -46,39 +44,48 @@ public class SlotSharingGroupTest {
.setExternalResource("gpu", 1)
.build();
- assertThat(slotSharingGroup.getName(), is(name));
- assertThat(slotSharingGroup.getCpuCores().get(), is(1.0));
- assertThat(slotSharingGroup.getTaskHeapMemory().get(), is(heap));
- assertThat(slotSharingGroup.getTaskOffHeapMemory().get(), is(offHeap));
- assertThat(slotSharingGroup.getManagedMemory().get(), is(managed));
- assertThat(
- slotSharingGroup.getExternalResources(), is(Collections.singletonMap("gpu", 1.0)));
+ assertThat(slotSharingGroup.getName()).isEqualTo(name);
+ assertThat(slotSharingGroup.getCpuCores()).contains(1.0);
+ assertThat(slotSharingGroup.getTaskHeapMemory()).contains(heap);
+ assertThat(slotSharingGroup.getTaskOffHeapMemory()).contains(offHeap);
+ assertThat(slotSharingGroup.getManagedMemory()).contains(managed);
+ assertThat(slotSharingGroup.getExternalResources())
+ .isEqualTo(Collections.singletonMap("gpu", 1.0));
}
@Test
- public void testBuildSlotSharingGroupWithUnknownResource() {
+ void testBuildSlotSharingGroupWithUnknownResource() {
final String name = "ssg";
final SlotSharingGroup slotSharingGroup = SlotSharingGroup.newBuilder(name).build();
- assertThat(slotSharingGroup.getName(), is(name));
- assertFalse(slotSharingGroup.getCpuCores().isPresent());
- assertFalse(slotSharingGroup.getTaskHeapMemory().isPresent());
- assertFalse(slotSharingGroup.getManagedMemory().isPresent());
- assertFalse(slotSharingGroup.getTaskOffHeapMemory().isPresent());
- assertTrue(slotSharingGroup.getExternalResources().isEmpty());
+ assertThat(slotSharingGroup.getName()).isEqualTo(name);
+ assertThat(slotSharingGroup.getCpuCores()).isNotPresent();
+ assertThat(slotSharingGroup.getTaskHeapMemory()).isNotPresent();
+ assertThat(slotSharingGroup.getManagedMemory()).isNotPresent();
+ assertThat(slotSharingGroup.getTaskOffHeapMemory()).isNotPresent();
+ assertThat(slotSharingGroup.getExternalResources()).isEmpty();
}
- @Test(expected = IllegalArgumentException.class)
- public void testBuildSlotSharingGroupWithIllegalConfig() {
- SlotSharingGroup.newBuilder("ssg")
- .setCpuCores(1)
- .setTaskHeapMemory(MemorySize.ZERO)
- .setTaskOffHeapMemoryMB(10)
- .build();
+ @Test
+ void testBuildSlotSharingGroupWithIllegalConfig() {
+ assertThatThrownBy(
+ () ->
+ SlotSharingGroup.newBuilder("ssg")
+ .setCpuCores(1)
+ .setTaskHeapMemory(MemorySize.ZERO)
+ .setTaskOffHeapMemoryMB(10)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class);
}
- @Test(expected = IllegalArgumentException.class)
- public void testBuildSlotSharingGroupWithoutAllRequiredConfig() {
- SlotSharingGroup.newBuilder("ssg").setCpuCores(1).setTaskOffHeapMemoryMB(10).build();
+ @Test
+ void testBuildSlotSharingGroupWithoutAllRequiredConfig() {
+ assertThatThrownBy(
+ () ->
+ SlotSharingGroup.newBuilder("ssg")
+ .setCpuCores(1)
+ .setTaskOffHeapMemoryMB(10)
+ .build())
+ .isInstanceOf(IllegalArgumentException.class);
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/base/FlatMapOperatorCollectionTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/base/FlatMapOperatorCollectionTest.java
index 055f1fc866d..41d1db230aa 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/base/FlatMapOperatorCollectionTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/base/FlatMapOperatorCollectionTest.java
@@ -21,7 +21,6 @@ package org.apache.flink.api.common.operators.base;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.TaskInfo;
import org.apache.flink.api.common.TaskInfoImpl;
-import org.apache.flink.api.common.accumulators.Accumulator;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.OpenContext;
import org.apache.flink.api.common.functions.RichFlatMapFunction;
@@ -29,46 +28,39 @@ import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.api.common.functions.util.RuntimeUDFContext;
import org.apache.flink.api.common.operators.UnaryOperatorInformation;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
-import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.concurrent.Future;
+
+import static org.assertj.core.api.Assertions.assertThat;
/** The test for flat map operator. */
-@SuppressWarnings("serial")
public class FlatMapOperatorCollectionTest implements Serializable {
@Test
- public void testExecuteOnCollection() {
- try {
- IdRichFlatMap<String> udf = new IdRichFlatMap<String>();
- testExecuteOnCollection(udf, Arrays.asList("f", "l", "i", "n", "k"), true);
- Assert.assertTrue(udf.isClosed);
-
- udf = new IdRichFlatMap<String>();
- testExecuteOnCollection(udf, Arrays.asList("f", "l", "i", "n", "k"), false);
- Assert.assertTrue(udf.isClosed);
-
- udf = new IdRichFlatMap<String>();
- testExecuteOnCollection(udf, Collections.<String>emptyList(), true);
- Assert.assertTrue(udf.isClosed);
-
- udf = new IdRichFlatMap<String>();
- testExecuteOnCollection(udf, Collections.<String>emptyList(), false);
- Assert.assertTrue(udf.isClosed);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.getMessage());
- }
+ void testExecuteOnCollection() throws Exception {
+ IdRichFlatMap<String> udf = new IdRichFlatMap<>();
+ testExecuteOnCollection(udf, Arrays.asList("f", "l", "i", "n", "k"), true);
+ assertThat(udf.isClosed).isTrue();
+
+ udf = new IdRichFlatMap<>();
+ testExecuteOnCollection(udf, Arrays.asList("f", "l", "i", "n", "k"), false);
+ assertThat(udf.isClosed).isTrue();
+
+ udf = new IdRichFlatMap<>();
+ testExecuteOnCollection(udf, Collections.emptyList(), true);
+ assertThat(udf.isClosed).isTrue();
+
+ udf = new IdRichFlatMap<>();
+ testExecuteOnCollection(udf, Collections.emptyList(), false);
+ assertThat(udf.isClosed).isTrue();
}
private void testExecuteOnCollection(
@@ -90,13 +82,13 @@ public class FlatMapOperatorCollectionTest implements Serializable {
taskInfo,
null,
executionConfig,
- new HashMap<String, Future<Path>>(),
- new HashMap<String, Accumulator<?, ?>>(),
+ new HashMap<>(),
+ new HashMap<>(),
UnregisteredMetricsGroup.createOperatorMetricGroup()),
executionConfig);
- Assert.assertEquals(input.size(), result.size());
- Assert.assertEquals(input, result);
+ assertThat(result).hasSameSizeAs(input);
+ assertThat(result).isEqualTo(input);
}
/** The test flat map function. */
@@ -106,25 +98,25 @@ public class FlatMapOperatorCollectionTest implements Serializable {
private boolean isClosed = false;
@Override
- public void open(OpenContext openContext) throws Exception {
+ public void open(OpenContext openContext) {
isOpened = true;
RuntimeContext ctx = getRuntimeContext();
- Assert.assertEquals("Test UDF", ctx.getTaskInfo().getTaskName());
- Assert.assertEquals(4, ctx.getTaskInfo().getNumberOfParallelSubtasks());
- Assert.assertEquals(0, ctx.getTaskInfo().getIndexOfThisSubtask());
+ assertThat(ctx.getTaskInfo().getTaskName()).isEqualTo("Test UDF");
+ assertThat(ctx.getTaskInfo().getNumberOfParallelSubtasks()).isEqualTo(4);
+ assertThat(ctx.getTaskInfo().getIndexOfThisSubtask()).isZero();
}
@Override
- public void flatMap(IN value, Collector<IN> out) throws Exception {
- Assert.assertTrue(isOpened);
- Assert.assertFalse(isClosed);
+ public void flatMap(IN value, Collector<IN> out) {
+ assertThat(isOpened).isTrue();
+ assertThat(isClosed).isFalse();
out.collect(value);
}
@Override
- public void close() throws Exception {
+ public void close() {
isClosed = true;
}
}
@@ -133,10 +125,9 @@ public class FlatMapOperatorCollectionTest implements Serializable {
getTestFlatMapOperator(FlatMapFunction<String, String> udf) {
UnaryOperatorInformation<String, String> typeInfo =
- new UnaryOperatorInformation<String, String>(
+ new UnaryOperatorInformation<>(
BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
- return new FlatMapOperatorBase<String, String, FlatMapFunction<String, String>>(
- udf, typeInfo, "flatMap on Collections");
+ return new FlatMapOperatorBase<>(udf, typeInfo, "flatMap on Collections");
}
}
diff --git a/flink-core/src/test/java/org/apache/flink/api/common/operators/base/InnerJoinOperatorBaseTest.java b/flink-core/src/test/java/org/apache/flink/api/common/operators/base/InnerJoinOperatorBaseTest.java
index 9ac67a19970..3ca873ca975 100644
--- a/flink-core/src/test/java/org/apache/flink/api/common/operators/base/InnerJoinOperatorBaseTest.java
+++ b/flink-core/src/test/java/org/apache/flink/api/common/operators/base/InnerJoinOperatorBaseTest.java
@@ -32,7 +32,7 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.metrics.groups.UnregisteredMetricsGroup;
import org.apache.flink.util.Collector;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.util.ArrayList;
@@ -42,25 +42,17 @@ import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
/** The test for inner join operator. */
-@SuppressWarnings("serial")
public class InnerJoinOperatorBaseTest implements Serializable {
... 5185 lines suppressed ...