You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by fa...@apache.org on 2023/08/27 03:53:38 UTC
[flink] branch master updated: [FLINK-32847][flink-runtime][JUnit5 Migration] Module: The operators package of flink-runtime (#23233)
This is an automated email from the ASF dual-hosted git repository.
fanrui 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 ac61e83dad8 [FLINK-32847][flink-runtime][JUnit5 Migration] Module: The operators package of flink-runtime (#23233)
ac61e83dad8 is described below
commit ac61e83dad8ea7d0fc91ad98315b2987275586dd
Author: Jiabao Sun <ji...@xtransfer.cn>
AuthorDate: Sun Aug 27 11:53:28 2023 +0800
[FLINK-32847][flink-runtime][JUnit5 Migration] Module: The operators package of flink-runtime (#23233)
---
.../AbstractOuterJoinTaskExternalITCase.java | 17 +-
.../operators/AbstractOuterJoinTaskTest.java | 119 ++++---
.../runtime/operators/CachedMatchTaskTest.java | 134 ++++----
.../operators/CoGroupTaskExternalITCase.java | 21 +-
.../flink/runtime/operators/CoGroupTaskTest.java | 113 ++++---
.../operators/CombineTaskExternalITCase.java | 88 ++---
.../flink/runtime/operators/CombineTaskTest.java | 38 +--
.../operators/CombinerOversizedRecordsTest.java | 17 +-
.../runtime/operators/CrossTaskExternalITCase.java | 30 +-
.../flink/runtime/operators/CrossTaskTest.java | 191 ++++++-----
.../flink/runtime/operators/DataSinkTaskTest.java | 143 ++++----
.../runtime/operators/DataSourceTaskTest.java | 107 +++---
.../flink/runtime/operators/FlatMapTaskTest.java | 44 ++-
.../operators/FullOuterJoinTaskExternalITCase.java | 4 +-
.../runtime/operators/FullOuterJoinTaskTest.java | 4 +-
.../operators/InvokableClassConstructorTest.java | 21 +-
.../runtime/operators/JoinTaskExternalITCase.java | 41 ++-
.../flink/runtime/operators/JoinTaskTest.java | 291 ++++++++--------
.../operators/LeftOuterJoinTaskExternalITCase.java | 17 +-
.../runtime/operators/LeftOuterJoinTaskTest.java | 76 ++---
.../operators/ReduceTaskExternalITCase.java | 87 +++--
.../flink/runtime/operators/ReduceTaskTest.java | 100 +++---
.../RightOuterJoinTaskExternalITCase.java | 17 +-
.../runtime/operators/RightOuterJoinTaskTest.java | 76 ++---
.../runtime/operators/chaining/ChainTaskTest.java | 40 +--
.../chaining/ChainedAllReduceDriverTest.java | 13 +-
.../chaining/ChainedOperatorsMetricTest.java | 20 +-
.../coordination/ComponentClosingUtilsTest.java | 38 +--
.../CoordinatorEventsExactlyOnceITCase.java | 17 +-
.../coordination/EventReceivingTasks.java | 2 +-
.../OperatorCoordinatorHolderTest.java | 51 ++-
.../OperatorCoordinatorSchedulerTest.java | 103 +++---
.../RecreateOnResetOperatorCoordinatorTest.java | 24 +-
.../coordination/SubtaskGatewayImplTest.java | 18 +-
.../util/IncompleteFuturesTrackerTest.java | 38 +--
.../drivers/AllGroupReduceDriverTest.java | 32 +-
.../operators/drivers/AllReduceDriverTest.java | 38 ++-
.../runtime/operators/drivers/DriverTestData.java | 10 +-
.../operators/drivers/GroupReduceDriverTest.java | 33 +-
.../operators/drivers/ReduceCombineDriverTest.java | 20 +-
.../operators/drivers/ReduceDriverTest.java | 22 +-
.../operators/hash/CompactingHashTableTest.java | 150 ++++-----
.../runtime/operators/hash/HashTableITCase.java | 375 ++++++++++-----------
.../hash/HashTablePerformanceComparison.java | 49 +--
.../runtime/operators/hash/HashTableTest.java | 46 +--
.../hash/InPlaceMutableHashTableTest.java | 90 +++--
.../operators/hash/MutableHashTableTestBase.java | 108 +++---
.../hash/NonReusingHashJoinIteratorITCase.java | 180 +++++-----
.../hash/NonReusingReOpenableHashTableITCase.java | 17 +-
.../operators/hash/ReOpenableHashTableITCase.java | 63 ++--
.../hash/ReOpenableHashTableTestBase.java | 46 +--
.../hash/ReusingHashJoinIteratorITCase.java | 177 +++++-----
.../hash/ReusingReOpenableHashTableITCase.java | 17 +-
.../BlockResettableMutableObjectIteratorTest.java | 64 ++--
.../NonReusingBlockResettableIteratorTest.java | 57 ++--
.../ReusingBlockResettableIteratorTest.java | 57 ++--
.../resettable/SpillingResettableIteratorTest.java | 133 ++++----
...pillingResettableMutableObjectIteratorTest.java | 106 +++---
.../AbstractSortMergeOuterJoinIteratorITCase.java | 55 ++-
.../sort/CombiningExternalSorterITCase.java | 61 ++--
.../runtime/operators/sort/ExternalSortITCase.java | 82 ++---
.../sort/ExternalSortLargeRecordsITCase.java | 72 ++--
.../runtime/operators/sort/ExternalSorterTest.java | 29 +-
.../sort/FixedLengthRecordSorterTest.java | 90 +++--
.../operators/sort/LargeRecordHandlerITCase.java | 67 ++--
.../operators/sort/LargeRecordHandlerTest.java | 82 ++---
.../runtime/operators/sort/MergeIteratorTest.java | 41 ++-
.../NonReusingSortMergeCoGroupIteratorITCase.java | 45 ++-
...NonReusingSortMergeInnerJoinIteratorITCase.java | 48 +--
...NonReusingSortMergeOuterJoinIteratorITCase.java | 21 +-
.../operators/sort/NormalizedKeySorterTest.java | 88 ++---
.../ReusingSortMergeCoGroupIteratorITCase.java | 46 +--
.../ReusingSortMergeInnerJoinIteratorITCase.java | 48 +--
.../ReusingSortMergeOuterJoinIteratorITCase.java | 21 +-
.../testutils/BinaryOperatorTestBase.java | 51 +--
.../operators/testutils/DriverTestBase.java | 52 +--
.../operators/testutils/MatchRemovingJoiner.java | 18 +-
.../operators/testutils/MockEnvironment.java | 2 +-
.../operators/testutils/TaskCancelThread.java | 6 +-
.../runtime/operators/testutils/TaskTestBase.java | 34 +-
.../operators/testutils/UnaryOperatorTestBase.java | 68 ++--
.../flink/runtime/operators/util/BitSetTest.java | 79 +++--
.../runtime/operators/util/BloomFilterTest.java | 56 +--
.../operators/util/HashVsSortMiniBenchmark.java | 41 +--
.../runtime/operators/util/OutputEmitterTest.java | 96 +++---
...ToStreamOperatorRecipientExactlyOnceITCase.java | 16 +-
86 files changed, 2678 insertions(+), 2787 deletions(-)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskExternalITCase.java
index dd06cf66138..125cd07905f 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskExternalITCase.java
@@ -32,10 +32,11 @@ import org.apache.flink.runtime.operators.testutils.BinaryOperatorTestBase;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
-public abstract class AbstractOuterJoinTaskExternalITCase
+import static org.assertj.core.api.Assertions.assertThat;
+
+abstract class AbstractOuterJoinTaskExternalITCase
extends BinaryOperatorTestBase<
FlatJoinFunction<
Tuple2<Integer, Integer>,
@@ -75,13 +76,13 @@ public abstract class AbstractOuterJoinTaskExternalITCase
protected final CountingOutputCollector<Tuple2<Integer, Integer>> output =
new CountingOutputCollector<>();
- public AbstractOuterJoinTaskExternalITCase(ExecutionConfig config) {
+ AbstractOuterJoinTaskExternalITCase(ExecutionConfig config) {
super(config, HASH_MEM, 2, SORT_MEM);
bnljn_frac = (double) BNLJN_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testExternalSortOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testExternalSortOuterJoinTask() throws Exception {
final int keyCnt1 = 16384 * 4;
final int valCnt1 = 2;
@@ -114,7 +115,9 @@ public abstract class AbstractOuterJoinTaskExternalITCase
this.comparator2.duplicate());
testDriver(testTask, MockJoinStub.class);
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
protected abstract int calculateExpectedCount(
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskTest.java
index 66e289eb4b3..7808d856a13 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/AbstractOuterJoinTaskTest.java
@@ -36,19 +36,16 @@ import org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
import org.apache.flink.util.Collector;
-import org.apache.flink.shaded.guava31.com.google.common.base.Throwables;
-
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public abstract class AbstractOuterJoinTaskTest
+abstract class AbstractOuterJoinTaskTest
extends BinaryOperatorTestBase<
FlatJoinFunction<
Tuple2<Integer, Integer>,
@@ -89,13 +86,13 @@ public abstract class AbstractOuterJoinTaskTest
(Class<Tuple2<Integer, Integer>>) (Class<?>) Tuple2.class,
new TypeSerializer<?>[] {IntSerializer.INSTANCE, IntSerializer.INSTANCE});
- public AbstractOuterJoinTaskTest(ExecutionConfig config) {
+ AbstractOuterJoinTaskTest(ExecutionConfig config) {
super(config, HASH_MEM, NUM_SORTER, SORT_MEM);
bnljn_frac = (double) BNLJN_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testSortBoth1OuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortBoth1OuterJoinTask() throws Exception {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -105,8 +102,8 @@ public abstract class AbstractOuterJoinTaskTest
testSortBothOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testSortBoth2OuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortBoth2OuterJoinTask() throws Exception {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -116,8 +113,8 @@ public abstract class AbstractOuterJoinTaskTest
testSortBothOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testSortBoth3OuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortBoth3OuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -127,8 +124,8 @@ public abstract class AbstractOuterJoinTaskTest
testSortBothOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testSortBoth4OuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortBoth4OuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -138,8 +135,8 @@ public abstract class AbstractOuterJoinTaskTest
testSortBothOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testSortBoth5OuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortBoth5OuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -149,8 +146,8 @@ public abstract class AbstractOuterJoinTaskTest
testSortBothOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testSortBoth6OuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortBoth6OuterJoinTask() throws Exception {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -188,15 +185,15 @@ public abstract class AbstractOuterJoinTaskTest
final int expCnt = calculateExpectedCount(keyCnt1, valCnt1, keyCnt2, valCnt2);
- Assert.assertTrue(
- "Result set size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Result set size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortFirstOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortFirstOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -226,15 +223,15 @@ public abstract class AbstractOuterJoinTaskTest
final int expCnt = calculateExpectedCount(keyCnt1, valCnt1, keyCnt2, valCnt2);
- Assert.assertTrue(
- "Result set size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Result set size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortSecondOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testSortSecondOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -264,15 +261,15 @@ public abstract class AbstractOuterJoinTaskTest
final int expCnt = calculateExpectedCount(keyCnt1, valCnt1, keyCnt2, valCnt2);
- Assert.assertTrue(
- "Result set size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Result set size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testMergeOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testMergeOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -300,15 +297,15 @@ public abstract class AbstractOuterJoinTaskTest
final int expCnt = calculateExpectedCount(keyCnt1, valCnt1, keyCnt2, valCnt2);
- Assert.assertTrue(
- "Result set size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Result set size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test(expected = ExpectedTestException.class)
- public void testFailingOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testFailingOuterJoinTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -332,11 +329,12 @@ public abstract class AbstractOuterJoinTaskTest
addInput(new UniformIntTupleGenerator(keyCnt1, valCnt1, true), this.serializer);
addInput(new UniformIntTupleGenerator(keyCnt2, valCnt2, true), this.serializer);
- testDriver(testTask, MockFailingJoinStub.class);
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingJoinStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelOuterJoinTaskWhileSort1() throws Exception {
+ @TestTemplate
+ void testCancelOuterJoinTaskWhileSort1() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -379,16 +377,15 @@ public abstract class AbstractOuterJoinTaskTest
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
- @Test
- public void testCancelOuterJoinTaskWhileSort2() throws Exception {
+ @TestTemplate
+ void testCancelOuterJoinTaskWhileSort2() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -431,16 +428,15 @@ public abstract class AbstractOuterJoinTaskTest
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
- @Test
- public void testCancelOuterJoinTaskWhileRunning() throws Exception {
+ @TestTemplate
+ void testCancelOuterJoinTaskWhileRunning() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -480,12 +476,11 @@ public abstract class AbstractOuterJoinTaskTest
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
protected abstract AbstractOuterJoinDriver<
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
index 9f67d2d2997..d39f176a80a 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CachedMatchTaskTest.java
@@ -34,13 +34,16 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record, Record>> {
private static final long HASH_MEM = 6 * 1024 * 1024;
@@ -63,8 +66,8 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
super(config, HASH_MEM, 2, SORT_MEM);
}
- @Test
- public void testHash1MatchTask() {
+ @TestTemplate
+ void testHash1MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -87,16 +90,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
testResettableDriver(testTask, MockMatchStub.class, 3);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash2MatchTask() {
+ @TestTemplate
+ void testHash2MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -119,16 +122,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
testResettableDriver(testTask, MockMatchStub.class, 3);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash3MatchTask() {
+ @TestTemplate
+ void testHash3MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -151,16 +154,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
testResettableDriver(testTask, MockMatchStub.class, 3);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash4MatchTask() {
+ @TestTemplate
+ void testHash4MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -183,16 +186,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
testResettableDriver(testTask, MockMatchStub.class, 3);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash5MatchTask() {
+ @TestTemplate
+ void testHash5MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -215,16 +218,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
testResettableDriver(testTask, MockMatchStub.class, 3);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testFailingHashFirstMatchTask() {
+ @TestTemplate
+ void testFailingHashFirstMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -243,19 +246,12 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
BuildFirstCachedJoinDriver<Record, Record, Record> testTask =
new BuildFirstCachedJoinDriver<Record, Record, Record>();
- try {
- testResettableDriver(testTask, MockFailingMatchStub.class, 3);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test caused an exception.");
- }
+ assertThatThrownBy(() -> testResettableDriver(testTask, MockFailingMatchStub.class, 3))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testFailingHashSecondMatchTask() {
+ @TestTemplate
+ void testFailingHashSecondMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -274,19 +270,12 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
BuildSecondCachedJoinDriver<Record, Record, Record> testTask =
new BuildSecondCachedJoinDriver<Record, Record, Record>();
- try {
- testResettableDriver(testTask, MockFailingMatchStub.class, 3);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test caused an exception.");
- }
+ assertThatThrownBy(() -> testResettableDriver(testTask, MockFailingMatchStub.class, 3))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelHashMatchTaskWhileBuildFirst() {
+ @TestTemplate
+ void testCancelHashMatchTaskWhileBuildFirst() {
int keyCnt = 20;
int valCnt = 20;
@@ -329,15 +318,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
- @Test
- public void testHashCancelMatchTaskWhileBuildSecond() {
+ @TestTemplate
+ void testHashCancelMatchTaskWhileBuildSecond() {
int keyCnt = 20;
int valCnt = 20;
@@ -376,15 +366,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
- @Test
- public void testHashFirstCancelMatchTaskWhileMatching() {
+ @TestTemplate
+ void testHashFirstCancelMatchTaskWhileMatching() {
int keyCnt = 20;
int valCnt = 20;
@@ -423,15 +414,16 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
- @Test
- public void testHashSecondCancelMatchTaskWhileMatching() {
+ @TestTemplate
+ void testHashSecondCancelMatchTaskWhileMatching() {
int keyCnt = 20;
int valCnt = 20;
@@ -470,11 +462,12 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
// =================================================================================================
@@ -503,17 +496,4 @@ public class CachedMatchTaskTest extends DriverTestBase<FlatJoinFunction<Record,
out.collect(record1);
}
}
-
- public static final class MockDelayingMatchStub
- extends RichFlatJoinFunction<Record, Record, Record> {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void join(Record record1, Record record2, Collector<Record> out) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- }
- }
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
index 16989545887..2a818b6fe02 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskExternalITCase.java
@@ -30,11 +30,12 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
-public class CoGroupTaskExternalITCase
- extends DriverTestBase<CoGroupFunction<Record, Record, Record>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class CoGroupTaskExternalITCase extends DriverTestBase<CoGroupFunction<Record, Record, Record>> {
private static final long SORT_MEM = 3 * 1024 * 1024;
@SuppressWarnings("unchecked")
@@ -49,12 +50,12 @@ public class CoGroupTaskExternalITCase
private final CountingOutputCollector output = new CountingOutputCollector();
- public CoGroupTaskExternalITCase(ExecutionConfig config) {
+ CoGroupTaskExternalITCase(ExecutionConfig config) {
super(config, 0, 2, SORT_MEM);
}
- @Test
- public void testExternalSortCoGroupTask() {
+ @TestTemplate
+ void testExternalSortCoGroupTask() {
int keyCnt1 = 16384 * 8;
int valCnt1 = 32;
@@ -87,10 +88,12 @@ public class CoGroupTaskExternalITCase
testDriver(testTask, MockCoGroupStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
public static final class MockCoGroupStub extends RichCoGroupFunction<Record, Record, Record> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
index fb771b7dacd..7dc0d9493c6 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CoGroupTaskTest.java
@@ -34,12 +34,15 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.concurrent.atomic.AtomicBoolean;
-public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Record, Record>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
+class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Record, Record>> {
private static final long SORT_MEM = 3 * 1024 * 1024;
@SuppressWarnings("unchecked")
@@ -54,12 +57,12 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
private final CountingOutputCollector output = new CountingOutputCollector();
- public CoGroupTaskTest(ExecutionConfig config) {
+ CoGroupTaskTest(ExecutionConfig config) {
super(config, 0, 2, SORT_MEM);
}
- @Test
- public void testSortBoth1CoGroupTask() {
+ @TestTemplate
+ void testSortBoth1CoGroupTask() {
int keyCnt1 = 100;
int valCnt1 = 2;
@@ -91,14 +94,16 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
testDriver(testTask, MockCoGroupStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testSortBoth2CoGroupTask() {
+ @TestTemplate
+ void testSortBoth2CoGroupTask() {
int keyCnt1 = 200;
int valCnt1 = 2;
@@ -130,14 +135,16 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
testDriver(testTask, MockCoGroupStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testSortFirstCoGroupTask() {
+ @TestTemplate
+ void testSortFirstCoGroupTask() {
int keyCnt1 = 200;
int valCnt1 = 2;
@@ -167,14 +174,16 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
testDriver(testTask, MockCoGroupStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testSortSecondCoGroupTask() {
+ @TestTemplate
+ void testSortSecondCoGroupTask() {
int keyCnt1 = 200;
int valCnt1 = 2;
@@ -204,14 +213,16 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
testDriver(testTask, MockCoGroupStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testMergeCoGroupTask() {
+ @TestTemplate
+ void testMergeCoGroupTask() {
int keyCnt1 = 200;
int valCnt1 = 2;
@@ -241,14 +252,16 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
testDriver(testTask, MockCoGroupStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testFailingSortCoGroupTask() {
+ @TestTemplate
+ void testFailingSortCoGroupTask() {
int keyCnt1 = 100;
int valCnt1 = 2;
@@ -268,19 +281,12 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
final CoGroupDriver<Record, Record, Record> testTask =
new CoGroupDriver<Record, Record, Record>();
- try {
- testDriver(testTask, MockFailingCoGroupStub.class);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("The test caused an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingCoGroupStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelCoGroupTaskWhileSorting1() {
+ @TestTemplate
+ void testCancelCoGroupTaskWhileSorting1() {
int keyCnt = 10;
int valCnt = 2;
@@ -300,7 +306,7 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
final AtomicBoolean success = new AtomicBoolean(false);
@@ -326,15 +332,14 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success).withFailMessage("The test task was not properly canceled.").isTrue();
}
- @Test
- public void testCancelCoGroupTaskWhileSorting2() {
+ @TestTemplate
+ void testCancelCoGroupTaskWhileSorting2() {
int keyCnt = 10;
int valCnt = 2;
@@ -354,7 +359,7 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
addInputSorted(new DelayingInfinitiveInputIterator(1000), this.comparator2.duplicate());
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
final AtomicBoolean success = new AtomicBoolean(false);
@@ -380,15 +385,16 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
- @Test
- public void testCancelCoGroupTaskWhileCoGrouping() {
+ @TestTemplate
+ void testCancelCoGroupTaskWhileCoGrouping() {
int keyCnt = 100;
int valCnt = 5;
@@ -408,7 +414,7 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
final AtomicBoolean success = new AtomicBoolean(false);
@@ -434,11 +440,12 @@ public class CoGroupTaskTest extends DriverTestBase<CoGroupFunction<Record, Reco
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
public static class MockFailingCoGroupStub extends RichCoGroupFunction<Record, Record, Record> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
index a31d30e3418..2b7bd639f6d 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskExternalITCase.java
@@ -23,7 +23,6 @@ import org.apache.flink.api.common.functions.GroupCombineFunction;
import org.apache.flink.api.common.functions.GroupReduceFunction;
import org.apache.flink.api.common.functions.RichGroupReduceFunction;
import org.apache.flink.runtime.operators.testutils.DriverTestBase;
-import org.apache.flink.runtime.operators.testutils.ExpectedTestException;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.runtime.testutils.recordutils.RecordComparator;
import org.apache.flink.types.IntValue;
@@ -31,13 +30,15 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
-public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFunction<Record, ?>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFunction<Record, ?>> {
private static final long COMBINE_MEM = 3 * 1024 * 1024;
@@ -50,14 +51,14 @@ public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFun
new RecordComparator(
new int[] {0}, (Class<? extends Value>[]) new Class<?>[] {IntValue.class});
- public CombineTaskExternalITCase(ExecutionConfig config) {
+ CombineTaskExternalITCase(ExecutionConfig config) {
super(config, COMBINE_MEM, 0);
combine_frac = (double) COMBINE_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testSingleLevelMergeCombineTask() {
+ @TestTemplate
+ void testSingleLevelMergeCombineTask() {
final int keyCnt = 40000;
final int valCnt = 8;
@@ -76,7 +77,7 @@ public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFun
testDriver(testTask, MockCombiningReduceStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
int expSum = 0;
@@ -100,19 +101,19 @@ public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFun
}
}
- Assert.assertTrue(
- "Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
- aggMap.size() == keyCnt);
+ assertThat(aggMap)
+ .withFailMessage("Resultset size was %d. Expected was %d", aggMap.size(), keyCnt)
+ .hasSize(keyCnt);
for (IntValue integer : aggMap.values()) {
- Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
+ assertThat(integer.getValue()).withFailMessage("Incorrect result").isEqualTo(expSum);
}
this.outList.clear();
}
- @Test
- public void testMultiLevelMergeCombineTask() throws Exception {
+ @TestTemplate
+ void testMultiLevelMergeCombineTask() {
final int keyCnt = 100000;
final int valCnt = 8;
@@ -131,7 +132,7 @@ public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFun
testDriver(testTask, MockCombiningReduceStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
int expSum = 0;
@@ -155,12 +156,12 @@ public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFun
}
}
- Assert.assertTrue(
- "Resultset size was " + aggMap.size() + ". Expected was " + keyCnt,
- aggMap.size() == keyCnt);
+ assertThat(aggMap)
+ .withFailMessage("Resultset size was %d. Expected was %d", aggMap.size(), keyCnt)
+ .hasSize(keyCnt);
for (IntValue integer : aggMap.values()) {
- Assert.assertTrue("Incorrect result", integer.getValue() == expSum);
+ assertThat(integer.getValue()).withFailMessage("Incorrect result").isEqualTo(expSum);
}
this.outList.clear();
@@ -196,53 +197,4 @@ public class CombineTaskExternalITCase extends DriverTestBase<RichGroupReduceFun
reduce(records, out);
}
}
-
- public static final class MockFailingCombiningReduceStub
- implements GroupReduceFunction<Record, Record>, GroupCombineFunction<Record, Record> {
- private static final long serialVersionUID = 1L;
-
- private int cnt = 0;
-
- private final IntValue key = new IntValue();
- private final IntValue value = new IntValue();
- private final IntValue combineValue = new IntValue();
-
- @Override
- public void reduce(Iterable<Record> records, Collector<Record> out) {
- Record element = null;
- int sum = 0;
-
- for (Record next : records) {
- element = next;
- element.getField(1, this.value);
-
- sum += this.value.getValue();
- }
- element.getField(0, this.key);
- this.value.setValue(sum - this.key.getValue());
- element.setField(1, this.value);
- out.collect(element);
- }
-
- @Override
- public void combine(Iterable<Record> records, Collector<Record> out) {
- Record element = null;
- int sum = 0;
-
- for (Record next : records) {
- element = next;
- element.getField(1, this.combineValue);
-
- sum += this.combineValue.getValue();
- }
-
- if (++this.cnt >= 10) {
- throw new ExpectedTestException();
- }
-
- this.combineValue.setValue(sum);
- element.setField(1, this.combineValue);
- out.collect(element);
- }
- }
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskTest.java
index 37aa9904620..fc4a7caf2cd 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombineTaskTest.java
@@ -38,13 +38,15 @@ import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.ArrayList;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
-public class CombineTaskTest
+class CombineTaskTest
extends UnaryOperatorTestBase<
RichGroupReduceFunction<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>>,
Tuple2<Integer, Integer>,
@@ -68,14 +70,14 @@ public class CombineTaskTest
new TypeComparator<?>[] {new IntComparator(true)},
new TypeSerializer<?>[] {IntSerializer.INSTANCE});
- public CombineTaskTest(ExecutionConfig config) {
+ CombineTaskTest(ExecutionConfig config) {
super(config, COMBINE_MEM, 0);
combine_frac = (double) COMBINE_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testCombineTask() {
+ @TestTemplate
+ void testCombineTask() {
try {
int keyCnt = 100;
int valCnt = 20;
@@ -99,10 +101,10 @@ public class CombineTaskTest
expSum += i;
}
- assertTrue(this.outList.size() == keyCnt);
+ assertThat(this.outList).hasSize(keyCnt);
for (Tuple2<Integer, Integer> record : this.outList) {
- assertTrue(record.f1 == expSum);
+ assertThat(record.f1).isEqualTo(expSum);
}
this.outList.clear();
@@ -112,8 +114,8 @@ public class CombineTaskTest
}
}
- @Test
- public void testFailingCombineTask() {
+ @TestTemplate
+ void testFailingCombineTask() {
try {
int keyCnt = 100;
int valCnt = 20;
@@ -130,20 +132,16 @@ public class CombineTaskTest
final GroupReduceCombineDriver<Tuple2<Integer, Integer>, Tuple2<Integer, Integer>>
testTask = new GroupReduceCombineDriver<>();
- try {
- testDriver(testTask, MockFailingCombiningReduceStub.class);
- fail("Exception not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingCombiningReduceStub.class))
+ .isInstanceOf(ExpectedTestException.class);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
- @Test
- public void testCancelCombineTaskSorting() {
+ @TestTemplate
+ void testCancelCombineTaskSorting() {
try {
MutableObjectIterator<Tuple2<Integer, Integer>> slowInfiniteInput =
new DelayingIterator<>(new InfiniteIntTupleIterator(), 1);
@@ -186,7 +184,9 @@ public class CombineTaskTest
taskRunner.join(5000);
} while (taskRunner.isAlive() && System.currentTimeMillis() < deadline);
- assertFalse("Task did not cancel properly within in 10 seconds.", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task did not cancel properly within in 10 seconds.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombinerOversizedRecordsTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombinerOversizedRecordsTest.java
index 6256a711ac6..44f8b6a9db1 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombinerOversizedRecordsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CombinerOversizedRecordsTest.java
@@ -36,19 +36,20 @@ import org.apache.flink.runtime.operators.testutils.UnionIterator;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
/**
* Test that checks how the combiner handles very large records that are too large to be written
* into a fresh sort buffer.
*/
-public class CombinerOversizedRecordsTest
+class CombinerOversizedRecordsTest
extends UnaryOperatorTestBase<
GroupCombineFunction<
Tuple3<Integer, Integer, String>, Tuple3<Integer, Double, String>>,
@@ -84,13 +85,13 @@ public class CombinerOversizedRecordsTest
// ------------------------------------------------------------------------
- public CombinerOversizedRecordsTest(ExecutionConfig config) {
+ CombinerOversizedRecordsTest(ExecutionConfig config) {
super(config, COMBINE_MEM, 0);
combine_frac = (double) COMBINE_MEM / getMemoryManager().getMemorySize();
}
- @Test
- public void testOversizedRecordCombineTask() {
+ @TestTemplate
+ void testOversizedRecordCombineTask() {
try {
final int keyCnt = 100;
final int valCnt = 20;
@@ -151,8 +152,8 @@ public class CombinerOversizedRecordsTest
testDriver(testTask, TestCombiner.class);
- assertEquals(3, testTask.getOversizedRecordCount());
- assertTrue(keyCnt + 3 == outList.size() || 2 * keyCnt + 3 == outList.size());
+ assertThat(testTask.getOversizedRecordCount()).isEqualTo(3);
+ assertThat(keyCnt + 3 == outList.size() || 2 * keyCnt + 3 == outList.size()).isTrue();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskExternalITCase.java
index 197ec53a4bb..7bd82571523 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskExternalITCase.java
@@ -25,23 +25,25 @@ import org.apache.flink.runtime.operators.testutils.DriverTestBase;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.types.Record;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
-public class CrossTaskExternalITCase extends DriverTestBase<CrossFunction<Record, Record, Record>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class CrossTaskExternalITCase extends DriverTestBase<CrossFunction<Record, Record, Record>> {
private static final long CROSS_MEM = 1024 * 1024;
private final double cross_frac;
private final CountingOutputCollector output = new CountingOutputCollector();
- public CrossTaskExternalITCase(ExecutionConfig config) {
+ CrossTaskExternalITCase(ExecutionConfig config) {
super(config, CROSS_MEM, 0);
cross_frac = (double) CROSS_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testExternalBlockCrossTask() {
+ @TestTemplate
+ void testExternalBlockCrossTask() {
int keyCnt1 = 2;
int valCnt1 = 1;
@@ -67,14 +69,16 @@ public class CrossTaskExternalITCase extends DriverTestBase<CrossFunction<Record
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testExternalStreamCrossTask() {
+ @TestTemplate
+ void testExternalStreamCrossTask() {
int keyCnt1 = 2;
int valCnt1 = 1;
@@ -100,9 +104,11 @@ public class CrossTaskExternalITCase extends DriverTestBase<CrossFunction<Record
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskTest.java
index 716c62c11c7..7c382d2db2d 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/CrossTaskTest.java
@@ -27,12 +27,15 @@ import org.apache.flink.runtime.operators.testutils.TaskCancelThread;
import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.types.Record;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.concurrent.atomic.AtomicBoolean;
-public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record, Record>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
+class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record, Record>> {
private static final long CROSS_MEM = 1024 * 1024;
@@ -40,14 +43,14 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
private final CountingOutputCollector output = new CountingOutputCollector();
- public CrossTaskTest(ExecutionConfig config) {
+ CrossTaskTest(ExecutionConfig config) {
super(config, CROSS_MEM, 0);
cross_frac = (double) CROSS_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testBlock1CrossTask() {
+ @TestTemplate
+ void testBlock1CrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -70,14 +73,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testBlock2CrossTask() {
+ @TestTemplate
+ void testBlock2CrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -100,14 +105,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testFailingBlockCrossTask() {
+ @TestTemplate
+ void testFailingBlockCrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -125,19 +132,12 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
- try {
- testDriver(testTask, MockFailingCrossStub.class);
- Assert.fail("Exception not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingCrossStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testFailingBlockCrossTask2() {
+ @TestTemplate
+ void testFailingBlockCrossTask2() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -155,19 +155,12 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
- try {
- testDriver(testTask, MockFailingCrossStub.class);
- Assert.fail("Exception not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingCrossStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testStream1CrossTask() {
+ @TestTemplate
+ void testStream1CrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -190,14 +183,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testStream2CrossTask() {
+ @TestTemplate
+ void testStream2CrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -220,14 +215,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testFailingStreamCrossTask() {
+ @TestTemplate
+ void testFailingStreamCrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -244,19 +241,12 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
- try {
- testDriver(testTask, MockFailingCrossStub.class);
- Assert.fail("Exception not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingCrossStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testFailingStreamCrossTask2() {
+ @TestTemplate
+ void testFailingStreamCrossTask2() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -273,19 +263,12 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
- try {
- testDriver(testTask, MockFailingCrossStub.class);
- Assert.fail("Exception not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingCrossStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testStreamEmptyInnerCrossTask() {
+ @TestTemplate
+ void testStreamEmptyInnerCrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -308,14 +291,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testStreamEmptyOuterCrossTask() {
+ @TestTemplate
+ void testStreamEmptyOuterCrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -338,14 +323,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testBlockEmptyInnerCrossTask() {
+ @TestTemplate
+ void testBlockEmptyInnerCrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -368,14 +355,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testBlockEmptyOuterCrossTask() {
+ @TestTemplate
+ void testBlockEmptyOuterCrossTask() {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -398,14 +387,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
testDriver(testTask, MockCrossStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test failed due to an exception.");
+ fail("Test failed due to an exception.");
}
- Assert.assertEquals("Wrong result size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testCancelBlockCrossTaskInit() {
+ @TestTemplate
+ void testCancelBlockCrossTaskInit() {
int keyCnt = 10;
int valCnt = 1;
@@ -442,14 +433,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue("Exception was thrown despite proper canceling.", success.get());
+ assertThat(success)
+ .withFailMessage("Exception was thrown despite proper canceling.")
+ .isTrue();
}
- @Test
- public void testCancelBlockCrossTaskCrossing() {
+ @TestTemplate
+ void testCancelBlockCrossTaskCrossing() {
int keyCnt = 10;
int valCnt = 1;
@@ -486,14 +479,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue("Exception was thrown despite proper canceling.", success.get());
+ assertThat(success)
+ .withFailMessage("Exception was thrown despite proper canceling.")
+ .isTrue();
}
- @Test
- public void testCancelStreamCrossTaskInit() {
+ @TestTemplate
+ void testCancelStreamCrossTaskInit() {
int keyCnt = 10;
int valCnt = 1;
@@ -530,14 +525,16 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue("Exception was thrown despite proper canceling.", success.get());
+ assertThat(success)
+ .withFailMessage("Exception was thrown despite proper canceling.")
+ .isTrue();
}
- @Test
- public void testCancelStreamCrossTaskCrossing() {
+ @TestTemplate
+ void testCancelStreamCrossTaskCrossing() {
int keyCnt = 10;
int valCnt = 1;
@@ -574,10 +571,12 @@ public class CrossTaskTest extends DriverTestBase<CrossFunction<Record, Record,
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue("Exception was thrown despite proper canceling.", success.get());
+ assertThat(success)
+ .withFailMessage("Exception was thrown despite proper canceling.")
+ .isTrue();
}
public static final class MockCrossStub implements CrossFunction<Record, Record, Record> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
index 7c57cdad37a..0a1cedcb74a 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSinkTaskTest.java
@@ -31,10 +31,7 @@ import org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
-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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,12 +45,10 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
-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.fail;
-public class DataSinkTaskTest extends TaskTestBase {
-
- @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+class DataSinkTaskTest extends TaskTestBase {
private static final Logger LOG = LoggerFactory.getLogger(DataSinkTaskTest.class);
@@ -62,7 +57,7 @@ public class DataSinkTaskTest extends TaskTestBase {
private static final int NETWORK_BUFFER_SIZE = 1024;
@Test
- public void testDataSinkTask() {
+ void testDataSinkTask() {
FileReader fr = null;
BufferedReader br = null;
try {
@@ -74,13 +69,13 @@ public class DataSinkTaskTest extends TaskTestBase {
DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockOutputFormat.class, tempTestFile.toURI().toString(), new Configuration());
testTask.invoke();
- Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
+ assertThat(tempTestFile).withFailMessage("Temp output file does not exist").exists();
fr = new FileReader(tempTestFile);
br = new BufferedReader(fr);
@@ -100,26 +95,22 @@ public class DataSinkTaskTest extends TaskTestBase {
keyValueCountMap.get(key).add(val);
}
- Assert.assertTrue(
- "Invalid key count in out file. Expected: "
- + keyCnt
- + " Actual: "
- + keyValueCountMap.keySet().size(),
- keyValueCountMap.keySet().size() == keyCnt);
+ assertThat(keyValueCountMap)
+ .withFailMessage(
+ "Invalid key count in out file. Expected: %d Actual: %d",
+ keyCnt, keyValueCountMap.size())
+ .hasSize(keyCnt);
for (Integer key : keyValueCountMap.keySet()) {
- Assert.assertTrue(
- "Invalid value count for key: "
- + key
- + ". Expected: "
- + valCnt
- + " Actual: "
- + keyValueCountMap.get(key).size(),
- keyValueCountMap.get(key).size() == valCnt);
+ assertThat(keyValueCountMap.get(key))
+ .withFailMessage(
+ "Invalid value count for key: %d. Expected: %d Actual: %d",
+ key, valCnt, keyValueCountMap.get(key).size())
+ .hasSize(valCnt);
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
} finally {
if (br != null) {
try {
@@ -137,7 +128,7 @@ public class DataSinkTaskTest extends TaskTestBase {
}
@Test
- public void testUnionDataSinkTask() {
+ void testUnionDataSinkTask() {
int keyCnt = 10;
int valCnt = 20;
@@ -159,7 +150,7 @@ public class DataSinkTaskTest extends TaskTestBase {
DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockOutputFormat.class, tempTestFile.toURI().toString(), new Configuration());
@@ -174,10 +165,10 @@ public class DataSinkTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception e) {
LOG.debug("Exception while invoking the test task.", e);
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
- Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
+ assertThat(tempTestFile).withFailMessage("Temp output file does not exist").exists();
FileReader fr = null;
BufferedReader br = null;
@@ -200,28 +191,24 @@ public class DataSinkTaskTest extends TaskTestBase {
keyValueCountMap.get(key).add(val);
}
- Assert.assertTrue(
- "Invalid key count in out file. Expected: "
- + keyCnt
- + " Actual: "
- + keyValueCountMap.keySet().size(),
- keyValueCountMap.keySet().size() == keyCnt * 4);
+ assertThat(keyValueCountMap)
+ .withFailMessage(
+ "Invalid key count in out file. Expected: %d Actual: %d",
+ keyCnt * 4, keyValueCountMap.size())
+ .hasSize(keyCnt * 4);
for (Integer key : keyValueCountMap.keySet()) {
- Assert.assertTrue(
- "Invalid value count for key: "
- + key
- + ". Expected: "
- + valCnt
- + " Actual: "
- + keyValueCountMap.get(key).size(),
- keyValueCountMap.get(key).size() == valCnt);
+ assertThat(keyValueCountMap.get(key))
+ .withFailMessage(
+ "Invalid value count for key: %d. Expected: %d Actual: %d",
+ key, valCnt, keyValueCountMap.get(key).size())
+ .hasSize(valCnt);
}
} catch (FileNotFoundException e) {
- Assert.fail("Out file got lost...");
+ fail("Out file got lost...");
} catch (IOException ioe) {
- Assert.fail("Caught IOE while reading out file");
+ fail("Caught IOE while reading out file");
} finally {
if (br != null) {
try {
@@ -240,7 +227,7 @@ public class DataSinkTaskTest extends TaskTestBase {
@Test
@SuppressWarnings("unchecked")
- public void testSortingDataSinkTask() {
+ void testSortingDataSinkTask() {
int keyCnt = 100;
int valCnt = 20;
@@ -262,7 +249,7 @@ public class DataSinkTaskTest extends TaskTestBase {
super.getTaskConfig().setFilehandlesInput(0, 8);
super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockOutputFormat.class, tempTestFile.toURI().toString(), new Configuration());
@@ -270,10 +257,10 @@ public class DataSinkTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception e) {
LOG.debug("Exception while invoking the test task.", e);
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
- Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
+ assertThat(tempTestFile).withFailMessage("Temp output file does not exist").exists();
FileReader fr = null;
BufferedReader br = null;
@@ -292,12 +279,14 @@ public class DataSinkTaskTest extends TaskTestBase {
Integer.parseInt(line.substring(line.indexOf("_") + 1, line.length()));
// check that values are in correct order
- Assert.assertTrue("Values not in ascending order", val >= curVal);
+ assertThat(val)
+ .withFailMessage("Values not in ascending order")
+ .isGreaterThanOrEqualTo(curVal);
// next value hit
if (val > curVal) {
if (curVal != -1) {
// check that we saw 100 distinct keys for this values
- Assert.assertTrue("Keys missing for value", keys.size() == 100);
+ assertThat(keys).withFailMessage("Keys missing for value").hasSize(100);
}
// empty keys set
keys.clear();
@@ -305,13 +294,13 @@ public class DataSinkTaskTest extends TaskTestBase {
curVal = val;
}
- Assert.assertTrue("Duplicate key for value", keys.add(key));
+ assertThat(keys.add(key)).withFailMessage("Duplicate key for value").isTrue();
}
} catch (FileNotFoundException e) {
- Assert.fail("Out file got lost...");
+ fail("Out file got lost...");
} catch (IOException ioe) {
- Assert.fail("Caught IOE while reading out file");
+ fail("Caught IOE while reading out file");
} finally {
if (br != null) {
try {
@@ -329,7 +318,7 @@ public class DataSinkTaskTest extends TaskTestBase {
}
@Test
- public void testFailingDataSinkTask() {
+ void testFailingDataSinkTask() {
int keyCnt = 100;
int valCnt = 20;
@@ -340,7 +329,7 @@ public class DataSinkTaskTest extends TaskTestBase {
DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
Configuration stubParams = new Configuration();
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockFailingOutputFormat.class, tempTestFile.toURI().toString(), stubParams);
@@ -351,15 +340,17 @@ public class DataSinkTaskTest extends TaskTestBase {
} catch (Exception e) {
stubFailed = true;
}
- Assert.assertTrue("Function exception was not forwarded.", stubFailed);
+ assertThat(stubFailed).withFailMessage("Function exception was not forwarded.").isTrue();
// assert that temp file was removed
- Assert.assertFalse("Temp output file has not been removed", tempTestFile.exists());
+ assertThat(tempTestFile)
+ .withFailMessage("Temp output file has not been removed")
+ .doesNotExist();
}
@Test
@SuppressWarnings("unchecked")
- public void testFailingSortingDataSinkTask() {
+ void testFailingSortingDataSinkTask() {
int keyCnt = 100;
int valCnt = 20;
@@ -381,7 +372,7 @@ public class DataSinkTaskTest extends TaskTestBase {
super.getTaskConfig().setFilehandlesInput(0, 8);
super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockFailingOutputFormat.class, tempTestFile.toURI().toString(), stubParams);
@@ -392,21 +383,23 @@ public class DataSinkTaskTest extends TaskTestBase {
} catch (Exception e) {
stubFailed = true;
}
- Assert.assertTrue("Function exception was not forwarded.", stubFailed);
+ assertThat(stubFailed).withFailMessage("Function exception was not forwarded.").isTrue();
// assert that temp file was removed
- Assert.assertFalse("Temp output file has not been removed", tempTestFile.exists());
+ assertThat(tempTestFile)
+ .withFailMessage("Temp output file has not been removed")
+ .doesNotExist();
}
@Test
- public void testCancelDataSinkTask() throws Exception {
+ void testCancelDataSinkTask() throws Exception {
super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
super.addInput(new InfiniteInputIterator(), 0);
final DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
Configuration stubParams = new Configuration();
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockOutputFormat.class, tempTestFile.toURI().toString(), stubParams);
@@ -419,7 +412,7 @@ public class DataSinkTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception ie) {
ie.printStackTrace();
- Assert.fail("Task threw exception although it was properly canceled");
+ fail("Task threw exception although it was properly canceled");
}
}
};
@@ -430,7 +423,9 @@ public class DataSinkTaskTest extends TaskTestBase {
while (!tempTestFile.exists() && System.currentTimeMillis() < deadline) {
Thread.sleep(10);
}
- assertTrue("Task did not create file within 60 seconds", tempTestFile.exists());
+ assertThat(tempTestFile)
+ .withFailMessage("Task did not create file within 60 seconds")
+ .exists();
// cancel the task
Thread.sleep(500);
@@ -441,12 +436,14 @@ public class DataSinkTaskTest extends TaskTestBase {
taskRunner.join();
// assert that temp file was created
- assertFalse("Temp output file has not been removed", tempTestFile.exists());
+ assertThat(tempTestFile)
+ .withFailMessage("Task did not create file within 60 seconds")
+ .doesNotExist();
}
@Test
@SuppressWarnings("unchecked")
- public void testCancelSortingDataSinkTask() {
+ void testCancelSortingDataSinkTask() {
double memoryFraction = 1.0;
super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
@@ -465,7 +462,7 @@ public class DataSinkTaskTest extends TaskTestBase {
super.getTaskConfig().setFilehandlesInput(0, 8);
super.getTaskConfig().setSpillingThresholdInput(0, 0.8f);
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
super.registerFileOutputTask(
MockOutputFormat.class, tempTestFile.toURI().toString(), stubParams);
@@ -477,7 +474,7 @@ public class DataSinkTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception ie) {
ie.printStackTrace();
- Assert.fail("Task threw exception although it was properly canceled");
+ fail("Task threw exception although it was properly canceled");
}
}
};
@@ -490,7 +487,7 @@ public class DataSinkTaskTest extends TaskTestBase {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSourceTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSourceTaskTest.java
index b46d1544824..bd7c84c97e7 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSourceTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/DataSourceTaskTest.java
@@ -28,10 +28,7 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
import java.io.BufferedWriter;
import java.io.File;
@@ -44,9 +41,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.UUID;
-public class DataSourceTaskTest extends TaskTestBase {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
- @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+public class DataSourceTaskTest extends TaskTestBase {
private static final int MEMORY_MANAGER_SIZE = 1024 * 1024;
@@ -55,12 +53,12 @@ public class DataSourceTaskTest extends TaskTestBase {
private List<Record> outList;
@Test
- public void testDataSourceTask() throws IOException {
+ void testDataSourceTask() throws IOException {
int keyCnt = 100;
int valCnt = 20;
this.outList = new ArrayList<Record>();
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
InputFilePreparator.prepareInputFile(
new UniformRecordGenerator(keyCnt, valCnt, false), tempTestFile, true);
@@ -76,32 +74,33 @@ public class DataSourceTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception e) {
System.err.println(e);
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
try {
Field formatField = DataSourceTask.class.getDeclaredField("format");
formatField.setAccessible(true);
MockInputFormat inputFormat = (MockInputFormat) formatField.get(testTask);
- Assert.assertTrue(
- "Invalid status of the input format. Expected for opened: true, Actual: "
- + inputFormat.opened,
- inputFormat.opened);
- Assert.assertTrue(
- "Invalid status of the input format. Expected for closed: true, Actual: "
- + inputFormat.closed,
- inputFormat.closed);
+ assertThat(inputFormat.opened)
+ .withFailMessage(
+ "Invalid status of the input format. Expected for opened: true, Actual: %b",
+ inputFormat.opened)
+ .isTrue();
+ assertThat(inputFormat.closed)
+ .withFailMessage(
+ "Invalid status of the input format. Expected for closed: true, Actual: %b",
+ inputFormat.closed)
+ .isTrue();
} catch (Exception e) {
System.err.println(e);
- Assert.fail("Reflection error while trying to validate inputFormat status.");
+ fail("Reflection error while trying to validate inputFormat status.");
}
- Assert.assertTrue(
- "Invalid output size. Expected: "
- + (keyCnt * valCnt)
- + " Actual: "
- + this.outList.size(),
- this.outList.size() == keyCnt * valCnt);
+ assertThat(this.outList)
+ .withFailMessage(
+ "Invalid output size. Expected: %d, Actual: %d",
+ keyCnt * valCnt, outList.size())
+ .hasSize(keyCnt * valCnt);
HashMap<Integer, HashSet<Integer>> keyValueCountMap = new HashMap<>(keyCnt);
@@ -116,32 +115,28 @@ public class DataSourceTaskTest extends TaskTestBase {
keyValueCountMap.get(key).add(val);
}
- Assert.assertTrue(
- "Invalid key count in out file. Expected: "
- + keyCnt
- + " Actual: "
- + keyValueCountMap.keySet().size(),
- keyValueCountMap.keySet().size() == keyCnt);
+ assertThat(keyValueCountMap)
+ .withFailMessage(
+ "Invalid key count in out file. Expected: %d, Actual: %d",
+ keyCnt, keyValueCountMap.size())
+ .hasSize(keyCnt);
for (Integer mapKey : keyValueCountMap.keySet()) {
- Assert.assertTrue(
- "Invalid value count for key: "
- + mapKey
- + ". Expected: "
- + valCnt
- + " Actual: "
- + keyValueCountMap.get(mapKey).size(),
- keyValueCountMap.get(mapKey).size() == valCnt);
+ assertThat(keyValueCountMap.get(mapKey))
+ .withFailMessage(
+ "Invalid value count for key: %d. Expected: %d, Actual: %d",
+ mapKey, valCnt, keyValueCountMap.get(mapKey).size())
+ .hasSize(valCnt);
}
}
@Test
- public void testFailingDataSourceTask() throws IOException {
+ void testFailingDataSourceTask() throws IOException {
int keyCnt = 20;
int valCnt = 10;
this.outList = new NirvanaOutputList();
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
InputFilePreparator.prepareInputFile(
new UniformRecordGenerator(keyCnt, valCnt, false), tempTestFile, false);
@@ -160,20 +155,20 @@ public class DataSourceTaskTest extends TaskTestBase {
} catch (Exception e) {
stubFailed = true;
}
- Assert.assertTrue("Function exception was not forwarded.", stubFailed);
+ assertThat(stubFailed).withFailMessage("Function exception was not forwarded.").isTrue();
// assert that temp file was created
- Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
+ assertThat(tempTestFile).withFailMessage("Temp output file does not exist").exists();
}
@Test
- public void testCancelDataSourceTask() throws IOException {
+ void testCancelDataSourceTask() throws IOException {
int keyCnt = 20;
int valCnt = 4;
super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
super.addOutput(new NirvanaOutputList());
- File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
InputFilePreparator.prepareInputFile(
new UniformRecordGenerator(keyCnt, valCnt, false), tempTestFile, false);
@@ -190,7 +185,7 @@ public class DataSourceTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception ie) {
ie.printStackTrace();
- Assert.fail("Task threw exception although it was properly canceled");
+ fail("Task threw exception although it was properly canceled");
}
}
};
@@ -203,11 +198,11 @@ public class DataSourceTaskTest extends TaskTestBase {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
// assert that temp file was created
- Assert.assertTrue("Temp output file does not exist", tempTestFile.exists());
+ assertThat(tempTestFile).withFailMessage("Temp output file does not exist").exists();
}
public static class InputFilePreparator {
@@ -265,19 +260,21 @@ public class DataSourceTaskTest extends TaskTestBase {
public void openInputFormat() {
// ensure this is called only once
- Assert.assertFalse(
- "Invalid status of the input format. Expected for opened: false, Actual: "
- + opened,
- opened);
+ assertThat(opened)
+ .withFailMessage(
+ "Invalid status of the input format. Expected for opened: false, Actual: %b",
+ opened)
+ .isFalse();
opened = true;
}
public void closeInputFormat() {
// ensure this is called only once
- Assert.assertFalse(
- "Invalid status of the input format. Expected for closed: false, Actual: "
- + closed,
- closed);
+ assertThat(closed)
+ .withFailMessage(
+ "Invalid status of the input format. Expected for closed: false, Actual: %b",
+ closed)
+ .isFalse();
closed = true;
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FlatMapTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FlatMapTaskTest.java
index c3094f27743..7c5121fee4e 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FlatMapTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FlatMapTaskTest.java
@@ -30,13 +30,16 @@ import org.apache.flink.runtime.operators.testutils.UniformRecordGenerator;
import org.apache.flink.types.Record;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.atomic.AtomicBoolean;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
public class FlatMapTaskTest extends DriverTestBase<FlatMapFunction<Record, Record>> {
private static final Logger LOG = LoggerFactory.getLogger(FlatMapTaskTest.class);
@@ -47,8 +50,8 @@ public class FlatMapTaskTest extends DriverTestBase<FlatMapFunction<Record, Reco
super(config, 0, 0);
}
- @Test
- public void testMapTask() {
+ @TestTemplate
+ void testMapTask() {
final int keyCnt = 100;
final int valCnt = 20;
@@ -61,15 +64,16 @@ public class FlatMapTaskTest extends DriverTestBase<FlatMapFunction<Record, Reco
testDriver(testDriver, MockMapStub.class);
} catch (Exception e) {
LOG.debug("Exception while running the test driver.", e);
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
- Assert.assertEquals(
- "Wrong result set size.", keyCnt * valCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(keyCnt * valCnt);
}
- @Test
- public void testFailingMapTask() {
+ @TestTemplate
+ void testFailingMapTask() {
final int keyCnt = 100;
final int valCnt = 20;
@@ -77,19 +81,12 @@ public class FlatMapTaskTest extends DriverTestBase<FlatMapFunction<Record, Reco
setOutput(new DiscardingOutputCollector<Record>());
final FlatMapDriver<Record, Record> testTask = new FlatMapDriver<>();
- try {
- testDriver(testTask, MockFailingMapStub.class);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException e) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Exception in test.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingMapStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelMapTask() {
+ @TestTemplate
+ void testCancelMapTask() {
addInput(new InfiniteInputIterator());
setOutput(new DiscardingOutputCollector<Record>());
@@ -118,11 +115,12 @@ public class FlatMapTaskTest extends DriverTestBase<FlatMapFunction<Record, Reco
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
public static class MockMapStub extends RichFlatMapFunction<Record, Record> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskExternalITCase.java
index a2c644ab53b..0159806923c 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskExternalITCase.java
@@ -21,9 +21,9 @@ package org.apache.flink.runtime.operators;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.java.tuple.Tuple2;
-public class FullOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExternalITCase {
+class FullOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExternalITCase {
- public FullOuterJoinTaskExternalITCase(ExecutionConfig config) {
+ FullOuterJoinTaskExternalITCase(ExecutionConfig config) {
super(config);
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskTest.java
index d44378658c6..354dbab1036 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/FullOuterJoinTaskTest.java
@@ -21,9 +21,9 @@ package org.apache.flink.runtime.operators;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.java.tuple.Tuple2;
-public class FullOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
+class FullOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
- public FullOuterJoinTaskTest(ExecutionConfig config) {
+ FullOuterJoinTaskTest(ExecutionConfig config) {
super(config);
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/InvokableClassConstructorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/InvokableClassConstructorTest.java
index dc22addd248..545b9295ef8 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/InvokableClassConstructorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/InvokableClassConstructorTest.java
@@ -25,15 +25,15 @@ import org.apache.flink.runtime.iterative.task.IterationIntermediateTask;
import org.apache.flink.runtime.iterative.task.IterationSynchronizationSinkTask;
import org.apache.flink.runtime.iterative.task.IterationTailTask;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests that validate that stateless/stateful task implementations have the corresponding
* constructors.
*/
-public class InvokableClassConstructorTest {
+class InvokableClassConstructorTest {
private static final Class<?>[] STATELESS_TASKS = {
IterationHeadTask.class,
@@ -49,19 +49,18 @@ public class InvokableClassConstructorTest {
// ------------------------------------------------------------------------
@Test
- public void testNoStatefulConstructor() throws Exception {
+ void testNoStatefulConstructor() throws Exception {
for (Class<?> clazz : STATELESS_TASKS) {
// check that there is a constructor for Environment only
clazz.getConstructor(Environment.class);
- try {
- // check that there is NO constructor for Environment and Task State
- clazz.getDeclaredConstructor(Environment.class, TaskStateSnapshot.class);
- fail("Should fail with an exception");
- } catch (NoSuchMethodException e) {
- // expected
- }
+ // check that there is NO constructor for Environment and Task State
+ assertThatThrownBy(
+ () ->
+ clazz.getDeclaredConstructor(
+ Environment.class, TaskStateSnapshot.class))
+ .isInstanceOf(NoSuchMethodException.class);
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
index 3696a0316ff..7ff1b351e26 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskExternalITCase.java
@@ -29,11 +29,12 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
-public class JoinTaskExternalITCase
- extends DriverTestBase<FlatJoinFunction<Record, Record, Record>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class JoinTaskExternalITCase extends DriverTestBase<FlatJoinFunction<Record, Record, Record>> {
private static final long HASH_MEM = 4 * 1024 * 1024;
@@ -57,14 +58,14 @@ public class JoinTaskExternalITCase
private final CountingOutputCollector output = new CountingOutputCollector();
- public JoinTaskExternalITCase(ExecutionConfig config) {
+ JoinTaskExternalITCase(ExecutionConfig config) {
super(config, HASH_MEM, 2, SORT_MEM);
bnljn_frac = (double) BNLJN_MEM / this.getMemoryManager().getMemorySize();
hash_frac = (double) HASH_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testExternalSort1MatchTask() {
+ @TestTemplate
+ void testExternalSort1MatchTask() {
final int keyCnt1 = 16384 * 4;
final int valCnt1 = 2;
@@ -93,14 +94,16 @@ public class JoinTaskExternalITCase
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testExternalHash1MatchTask() {
+ @TestTemplate
+ void testExternalHash1MatchTask() {
final int keyCnt1 = 32768;
final int valCnt1 = 8;
@@ -124,14 +127,16 @@ public class JoinTaskExternalITCase
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
- @Test
- public void testExternalHash2MatchTask() {
+ @TestTemplate
+ void testExternalHash2MatchTask() {
final int keyCnt1 = 32768;
final int valCnt1 = 8;
@@ -155,10 +160,12 @@ public class JoinTaskExternalITCase
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
public static final class MockMatchStub implements FlatJoinFunction<Record, Record, Record> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
index 5393faf892d..863dd0fda2c 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/JoinTaskTest.java
@@ -33,17 +33,18 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
-public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record, Record>> {
+class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record, Record>> {
private static final long HASH_MEM = 6 * 1024 * 1024;
@@ -69,14 +70,14 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
private final List<Record> outList = new ArrayList<>();
- public JoinTaskTest(ExecutionConfig config) {
+ JoinTaskTest(ExecutionConfig config) {
super(config, HASH_MEM, NUM_SORTER, SORT_MEM);
bnljn_frac = (double) BNLJN_MEM / this.getMemoryManager().getMemorySize();
hash_frac = (double) HASH_MEM / this.getMemoryManager().getMemorySize();
}
- @Test
- public void testSortBoth1MatchTask() {
+ @TestTemplate
+ void testSortBoth1MatchTask() {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -103,19 +104,19 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortBoth2MatchTask() {
+ @TestTemplate
+ void testSortBoth2MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -143,20 +144,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortBoth3MatchTask() {
+ @TestTemplate
+ void testSortBoth3MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -184,20 +185,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortBoth4MatchTask() {
+ @TestTemplate
+ void testSortBoth4MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -225,20 +226,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortBoth5MatchTask() {
+ @TestTemplate
+ void testSortBoth5MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -266,20 +267,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortFirstMatchTask() {
+ @TestTemplate
+ void testSortFirstMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -305,20 +306,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testSortSecondMatchTask() {
+ @TestTemplate
+ void testSortSecondMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -344,20 +345,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testMergeMatchTask() {
+ @TestTemplate
+ void testMergeMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -381,20 +382,20 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testFailingMatchTask() {
+ @TestTemplate
+ void testFailingMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -414,19 +415,12 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
addInput(new UniformRecordGenerator(keyCnt1, valCnt1, true));
addInput(new UniformRecordGenerator(keyCnt2, valCnt2, true));
- try {
- testDriver(testTask, MockFailingMatchStub.class);
- Assert.fail("Driver did not forward Exception.");
- } catch (ExpectedTestException e) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("The test caused an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingMatchStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelMatchTaskWhileSort1() {
+ @TestTemplate
+ void testCancelMatchTaskWhileSort1() {
final int keyCnt = 20;
final int valCnt = 20;
@@ -447,7 +441,7 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
addInput(new UniformRecordGenerator(keyCnt, valCnt, true));
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
final AtomicReference<Throwable> error = new AtomicReference<>();
@@ -472,21 +466,22 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
Throwable taskError = error.get();
- if (taskError != null) {
- taskError.printStackTrace();
- fail("Error in task while canceling: " + taskError.getMessage());
- }
+ assertThat(taskError)
+ .withFailMessage("Error in task while canceling: %s", taskError)
+ .isNull();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
- @Test
- public void testCancelMatchTaskWhileSort2() {
+ @TestTemplate
+ void testCancelMatchTaskWhileSort2() {
final int keyCnt = 20;
final int valCnt = 20;
@@ -507,7 +502,7 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
new DelayingInfinitiveInputIterator(100), this.comparator1.duplicate());
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test caused an exception.");
+ fail("The test caused an exception.");
}
final AtomicReference<Throwable> error = new AtomicReference<>();
@@ -532,21 +527,22 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
Throwable taskError = error.get();
- if (taskError != null) {
- taskError.printStackTrace();
- fail("Error in task while canceling: " + taskError.getMessage());
- }
+ assertThat(taskError)
+ .withFailMessage("Error in task while canceling: %s", taskError)
+ .isNull();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
- @Test
- public void testCancelMatchTaskWhileMatching() {
+ @TestTemplate
+ void testCancelMatchTaskWhileMatching() {
final int keyCnt = 20;
final int valCnt = 20;
@@ -586,21 +582,22 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
Throwable taskError = error.get();
- if (taskError != null) {
- taskError.printStackTrace();
- fail("Error in task while canceling: " + taskError.getMessage());
- }
+ assertThat(taskError)
+ .withFailMessage("Error in task while canceling:\n%s", taskError)
+ .isNull();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
- @Test
- public void testHash1MatchTask() {
+ @TestTemplate
+ void testHash1MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -622,16 +619,16 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash2MatchTask() {
+ @TestTemplate
+ void testHash2MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -653,16 +650,16 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash3MatchTask() {
+ @TestTemplate
+ void testHash3MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -684,16 +681,16 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash4MatchTask() {
+ @TestTemplate
+ void testHash4MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -715,16 +712,16 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testHash5MatchTask() {
+ @TestTemplate
+ void testHash5MatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -746,16 +743,16 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
testDriver(testTask, MockMatchStub.class);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Test caused an exception.");
+ fail("Test caused an exception.");
}
final int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2);
- Assert.assertEquals("Wrong result set size.", expCnt, this.outList.size());
+ assertThat(this.outList).withFailMessage("Wrong result set size.").hasSize(expCnt);
this.outList.clear();
}
- @Test
- public void testFailingHashFirstMatchTask() {
+ @TestTemplate
+ void testFailingHashFirstMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -773,19 +770,12 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
JoinDriver<Record, Record, Record> testTask = new JoinDriver<>();
- try {
- testDriver(testTask, MockFailingMatchStub.class);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test caused an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingMatchStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testFailingHashSecondMatchTask() {
+ @TestTemplate
+ void testFailingHashSecondMatchTask() {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -803,19 +793,12 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
JoinDriver<Record, Record, Record> testTask = new JoinDriver<>();
- try {
- testDriver(testTask, MockFailingMatchStub.class);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException etex) {
- // good!
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail("Test caused an exception.");
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingMatchStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelHashMatchTaskWhileBuildFirst() {
+ @TestTemplate
+ void testCancelHashMatchTaskWhileBuildFirst() {
final int keyCnt = 20;
final int valCnt = 20;
@@ -857,19 +840,21 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
try {
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage(
+ "Test threw an exception even though it was properly canceled.")
+ .isTrue();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
- @Test
- public void testHashCancelMatchTaskWhileBuildSecond() {
+ @TestTemplate
+ void testHashCancelMatchTaskWhileBuildSecond() {
final int keyCnt = 20;
final int valCnt = 20;
@@ -911,19 +896,21 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
try {
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage(
+ "Test threw an exception even though it was properly canceled.")
+ .isTrue();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
- @Test
- public void testHashFirstCancelMatchTaskWhileMatching() {
+ @TestTemplate
+ void testHashFirstCancelMatchTaskWhileMatching() {
int keyCnt = 20;
int valCnt = 20;
@@ -961,15 +948,16 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
- @Test
- public void testHashSecondCancelMatchTaskWhileMatching() {
+ @TestTemplate
+ void testHashSecondCancelMatchTaskWhileMatching() {
int keyCnt = 20;
int valCnt = 20;
@@ -1007,11 +995,12 @@ public class JoinTaskTest extends DriverTestBase<FlatJoinFunction<Record, Record
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
// =================================================================================================
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskExternalITCase.java
index 5970acbd772..816b8390f03 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskExternalITCase.java
@@ -23,14 +23,15 @@ import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
-public class LeftOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExternalITCase {
+import static org.assertj.core.api.Assertions.assertThat;
+
+class LeftOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExternalITCase {
private final double hash_frac;
- public LeftOuterJoinTaskExternalITCase(ExecutionConfig config) {
+ LeftOuterJoinTaskExternalITCase(ExecutionConfig config) {
super(config);
hash_frac = (double) HASH_MEM / this.getMemoryManager().getMemorySize();
}
@@ -53,8 +54,8 @@ public class LeftOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExtern
return DriverStrategy.LEFT_OUTER_MERGE;
}
- @Test
- public void testExternalHashLeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testExternalHashLeftOuterJoinTask() throws Exception {
final int keyCnt1 = 65536;
final int valCnt1 = 8;
@@ -87,6 +88,8 @@ public class LeftOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExtern
this.comparator2.duplicate());
testDriver(testTask, MockJoinStub.class);
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
index 2ff44c4bc25..6a9dd992d79 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/LeftOuterJoinTaskTest.java
@@ -27,23 +27,20 @@ import org.apache.flink.runtime.operators.testutils.ExpectedTestException;
import org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
-import org.apache.flink.shaded.guava31.com.google.common.base.Throwables;
-
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.concurrent.atomic.AtomicReference;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
+class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
private static final long HASH_MEM = 6 * 1024 * 1024;
private final double hash_frac;
- public LeftOuterJoinTaskTest(ExecutionConfig config) {
+ LeftOuterJoinTaskTest(ExecutionConfig config) {
super(config);
hash_frac = (double) HASH_MEM / this.getMemoryManager().getMemorySize();
}
@@ -66,8 +63,8 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
return new LeftOuterJoinDriver<>();
}
- @Test
- public void testHash1LeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash1LeftOuterJoinTask() throws Exception {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -77,8 +74,8 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashLeftOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash2LeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash2LeftOuterJoinTask() throws Exception {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -88,8 +85,8 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashLeftOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash3LeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash3LeftOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -99,8 +96,8 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashLeftOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash4LeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash4LeftOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -110,8 +107,8 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashLeftOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash5LeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash5LeftOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -121,8 +118,8 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashLeftOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash6LeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash6LeftOuterJoinTask() throws Exception {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -154,15 +151,15 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
final int expCnt = calculateExpectedCount(keyCnt1, valCnt1, keyCnt2, valCnt2);
- Assert.assertTrue(
- "Result set size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Result set size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test(expected = ExpectedTestException.class)
- public void testFailingHashLeftOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testFailingHashLeftOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -185,11 +182,12 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
addInput(new UniformIntTupleGenerator(keyCnt1, valCnt1, true), this.serializer);
addInput(new UniformIntTupleGenerator(keyCnt2, valCnt2, true), this.serializer);
- testDriver(testTask, MockFailingJoinStub.class);
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingJoinStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelLeftOuterJoinTaskWhileBuilding() throws Exception {
+ @TestTemplate
+ void testCancelLeftOuterJoinTaskWhileBuilding() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -226,16 +224,15 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
cancel();
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
- @Test
- public void testCancelLeftOuterJoinTaskWhileProbing() throws Exception {
+ @TestTemplate
+ void testCancelLeftOuterJoinTaskWhileProbing() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -272,11 +269,10 @@ public class LeftOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
cancel();
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
index 45b9fa72df0..4928e34718e 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskExternalITCase.java
@@ -33,8 +33,7 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,8 +41,10 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-public class ReduceTaskExternalITCase
- extends DriverTestBase<RichGroupReduceFunction<Record, Record>> {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class ReduceTaskExternalITCase extends DriverTestBase<RichGroupReduceFunction<Record, Record>> {
private static final Logger LOG = LoggerFactory.getLogger(ReduceTaskExternalITCase.class);
@SuppressWarnings("unchecked")
@@ -53,12 +54,12 @@ public class ReduceTaskExternalITCase
private final List<Record> outList = new ArrayList<>();
- public ReduceTaskExternalITCase(ExecutionConfig config) {
+ ReduceTaskExternalITCase(ExecutionConfig config) {
super(config, 0, 1, 3 * 1024 * 1024);
}
- @Test
- public void testSingleLevelMergeReduceTask() {
+ @TestTemplate
+ void testSingleLevelMergeReduceTask() {
final int keyCnt = 8192;
final int valCnt = 8;
@@ -77,25 +78,24 @@ public class ReduceTaskExternalITCase
testDriver(testTask, MockReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Exception in Test: " + e.getMessage());
+ fail("Exception in Test: " + e.getMessage());
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == valCnt - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(valCnt - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
}
- @Test
- public void testMultiLevelMergeReduceTask() {
+ @TestTemplate
+ void testMultiLevelMergeReduceTask() {
final int keyCnt = 32768;
final int valCnt = 8;
@@ -114,25 +114,24 @@ public class ReduceTaskExternalITCase
testDriver(testTask, MockReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Exception in Test: " + e.getMessage());
+ fail("Exception in Test: " + e.getMessage());
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == valCnt - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(valCnt - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
}
- @Test
- public void testSingleLevelMergeCombiningReduceTask() throws IOException {
+ @TestTemplate
+ void testSingleLevelMergeCombiningReduceTask() throws IOException {
final int keyCnt = 8192;
final int valCnt = 8;
@@ -162,7 +161,7 @@ public class ReduceTaskExternalITCase
testDriver(testTask, MockCombiningReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Invoke method caused exception: " + e.getMessage());
+ fail("Invoke method caused exception: " + e.getMessage());
} finally {
if (sorter != null) {
sorter.close();
@@ -174,22 +173,21 @@ public class ReduceTaskExternalITCase
expSum += i;
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == expSum - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(expSum - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
}
- @Test
- public void testMultiLevelMergeCombiningReduceTask() throws IOException {
+ @TestTemplate
+ void testMultiLevelMergeCombiningReduceTask() throws IOException {
int keyCnt = 32768;
int valCnt = 8;
@@ -220,7 +218,7 @@ public class ReduceTaskExternalITCase
testDriver(testTask, MockCombiningReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Invoke method caused exception: " + e.getMessage());
+ fail("Invoke method caused exception: " + e.getMessage());
} finally {
if (sorter != null) {
sorter.close();
@@ -232,15 +230,14 @@ public class ReduceTaskExternalITCase
expSum += i;
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == expSum - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(expSum - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
index 0e2daa501a2..12e6e05ec13 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/ReduceTaskTest.java
@@ -37,8 +37,7 @@ import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,6 +46,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Record, Record>> {
private static final Logger LOG = LoggerFactory.getLogger(ReduceTaskTest.class);
@@ -61,8 +64,8 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
super(config, 0, 1, 3 * 1024 * 1024);
}
- @Test
- public void testReduceTaskWithSortingInput() {
+ @TestTemplate
+ void testReduceTaskWithSortingInput() {
final int keyCnt = 100;
final int valCnt = 20;
@@ -79,25 +82,24 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
testDriver(testTask, MockReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Exception in Test: " + e.getMessage());
+ fail("Exception in Test: " + e.getMessage());
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == valCnt - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(valCnt - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
}
- @Test
- public void testReduceTaskOnPreSortedInput() {
+ @TestTemplate
+ void testReduceTaskOnPreSortedInput() {
final int keyCnt = 100;
final int valCnt = 20;
@@ -112,25 +114,24 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
testDriver(testTask, MockReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Invoke method caused exception: " + e.getMessage());
+ fail("Invoke method caused exception: " + e.getMessage());
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == valCnt - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(valCnt - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
}
- @Test
- public void testCombiningReduceTask() throws IOException {
+ @TestTemplate
+ void testCombiningReduceTask() throws IOException {
final int keyCnt = 100;
final int valCnt = 20;
@@ -161,7 +162,7 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
testDriver(testTask, MockCombiningReduceStub.class);
} catch (Exception e) {
LOG.info("Exception while running the test task.", e);
- Assert.fail("Invoke method caused exception: " + e.getMessage());
+ fail("Invoke method caused exception: " + e.getMessage());
} finally {
if (sorter != null) {
sorter.close();
@@ -173,22 +174,21 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
expSum += i;
}
- Assert.assertTrue(
- "Resultset size was " + this.outList.size() + ". Expected was " + keyCnt,
- this.outList.size() == keyCnt);
+ assertThat(this.outList)
+ .withFailMessage("Resultset size was %d. Expected was %d", outList.size(), keyCnt)
+ .hasSize(keyCnt);
for (Record record : this.outList) {
- Assert.assertTrue(
- "Incorrect result",
- record.getField(1, IntValue.class).getValue()
- == expSum - record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(1, IntValue.class).getValue())
+ .withFailMessage("Incorrect result")
+ .isEqualTo(expSum - record.getField(0, IntValue.class).getValue());
}
this.outList.clear();
}
- @Test
- public void testFailingReduceTask() {
+ @TestTemplate
+ void testFailingReduceTask() {
final int keyCnt = 100;
final int valCnt = 20;
@@ -199,23 +199,14 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
GroupReduceDriver<Record, Record> testTask = new GroupReduceDriver<>();
- try {
- testDriver(testTask, MockFailingReduceStub.class);
- Assert.fail("Function exception was not forwarded.");
- } catch (ExpectedTestException eetex) {
- // Good!
- } catch (Exception e) {
- LOG.info(
- "Exception which was not the ExpectedTestException while running the test task.",
- e);
- Assert.fail("Test caused exception: " + e.getMessage());
- }
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingReduceStub.class))
+ .isInstanceOf(ExpectedTestException.class);
this.outList.clear();
}
- @Test
- public void testCancelReduceTaskWhileSorting() {
+ @TestTemplate
+ void testCancelReduceTaskWhileSorting() {
addDriverComparator(this.comparator);
setOutput(new NirvanaOutputList());
getTaskConfig().setDriverStrategy(DriverStrategy.SORTED_GROUP_REDUCE);
@@ -226,7 +217,7 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
addInputSorted(new DelayingInfinitiveInputIterator(100), this.comparator.duplicate());
} catch (Exception e) {
e.printStackTrace();
- Assert.fail();
+ fail(e.getMessage());
}
final AtomicBoolean success = new AtomicBoolean(false);
@@ -252,15 +243,16 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
- Assert.assertTrue(
- "Test threw an exception even though it was properly canceled.", success.get());
+ assertThat(success)
+ .withFailMessage("Test threw an exception even though it was properly canceled.")
+ .isTrue();
}
- @Test
- public void testCancelReduceTaskWhileReducing() {
+ @TestTemplate
+ void testCancelReduceTaskWhileReducing() {
final int keyCnt = 1000;
final int valCnt = 2;
@@ -295,7 +287,7 @@ public class ReduceTaskTest extends DriverTestBase<RichGroupReduceFunction<Recor
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
- Assert.fail("Joining threads failed");
+ fail("Joining threads failed");
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskExternalITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskExternalITCase.java
index 32df50d386d..c8f2e49617d 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskExternalITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskExternalITCase.java
@@ -23,14 +23,15 @@ import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.api.java.typeutils.runtime.RuntimePairComparatorFactory;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
-public class RightOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExternalITCase {
+import static org.assertj.core.api.Assertions.assertThat;
+
+class RightOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExternalITCase {
private final double hash_frac;
- public RightOuterJoinTaskExternalITCase(ExecutionConfig config) {
+ RightOuterJoinTaskExternalITCase(ExecutionConfig config) {
super(config);
hash_frac = (double) HASH_MEM / this.getMemoryManager().getMemorySize();
}
@@ -53,8 +54,8 @@ public class RightOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExter
return DriverStrategy.RIGHT_OUTER_MERGE;
}
- @Test
- public void testExternalHashRightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testExternalHashRightOuterJoinTask() throws Exception {
final int keyCnt1 = 32768;
final int valCnt1 = 8;
@@ -87,6 +88,8 @@ public class RightOuterJoinTaskExternalITCase extends AbstractOuterJoinTaskExter
this.comparator2.duplicate());
testDriver(testTask, MockJoinStub.class);
- Assert.assertEquals("Wrong result set size.", expCnt, this.output.getNumberOfRecords());
+ assertThat(this.output.getNumberOfRecords())
+ .withFailMessage("Wrong result set size.")
+ .isEqualTo(expCnt);
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskTest.java
index 03c152a6ace..3a341c04816 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/RightOuterJoinTaskTest.java
@@ -27,23 +27,20 @@ import org.apache.flink.runtime.operators.testutils.ExpectedTestException;
import org.apache.flink.runtime.operators.testutils.InfiniteIntTupleIterator;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
-import org.apache.flink.shaded.guava31.com.google.common.base.Throwables;
-
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.TestTemplate;
import java.util.concurrent.atomic.AtomicReference;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
+class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
private static final long HASH_MEM = 6 * 1024 * 1024;
private final double hash_frac;
- public RightOuterJoinTaskTest(ExecutionConfig config) {
+ RightOuterJoinTaskTest(ExecutionConfig config) {
super(config);
hash_frac = (double) HASH_MEM / this.getMemoryManager().getMemorySize();
}
@@ -66,8 +63,8 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
return new RightOuterJoinDriver<>();
}
- @Test
- public void testHash1RightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash1RightOuterJoinTask() throws Exception {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -77,8 +74,8 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashRightOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash2RightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash2RightOuterJoinTask() throws Exception {
final int keyCnt1 = 20;
final int valCnt1 = 1;
@@ -88,8 +85,8 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashRightOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash3RightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash3RightOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 1;
@@ -99,8 +96,8 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashRightOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash4RightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash4RightOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -110,8 +107,8 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashRightOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash5RightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash5RightOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -121,8 +118,8 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
testHashRightOuterJoinTask(keyCnt1, valCnt1, keyCnt2, valCnt2);
}
- @Test
- public void testHash6RightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testHash6RightOuterJoinTask() throws Exception {
int keyCnt1 = 10;
int valCnt1 = 1;
@@ -156,15 +153,15 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
final int expCnt = calculateExpectedCount(keyCnt1, valCnt1, keyCnt2, valCnt2);
- Assert.assertTrue(
- "Result set size was " + this.outList.size() + ". Expected was " + expCnt,
- this.outList.size() == expCnt);
+ assertThat(this.outList)
+ .withFailMessage("Result set size was %d. Expected was %d", outList.size(), expCnt)
+ .hasSize(expCnt);
this.outList.clear();
}
- @Test(expected = ExpectedTestException.class)
- public void testFailingHashRightOuterJoinTask() throws Exception {
+ @TestTemplate
+ void testFailingHashRightOuterJoinTask() throws Exception {
int keyCnt1 = 20;
int valCnt1 = 20;
@@ -188,11 +185,12 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
addInput(new UniformIntTupleGenerator(keyCnt1, valCnt1, true), this.serializer);
addInput(new UniformIntTupleGenerator(keyCnt2, valCnt2, true), this.serializer);
- testDriver(testTask, MockFailingJoinStub.class);
+ assertThatThrownBy(() -> testDriver(testTask, MockFailingJoinStub.class))
+ .isInstanceOf(ExpectedTestException.class);
}
- @Test
- public void testCancelRightOuterJoinTaskWhileBuilding() throws Exception {
+ @TestTemplate
+ void testCancelRightOuterJoinTaskWhileBuilding() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -229,16 +227,15 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
cancel();
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
- @Test
- public void testCancelRightOuterJoinTaskWhileProbing() throws Exception {
+ @TestTemplate
+ void testCancelRightOuterJoinTaskWhileProbing() throws Exception {
setOutput(new DiscardingOutputCollector<Tuple2<Integer, Integer>>());
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
@@ -275,11 +272,10 @@ public class RightOuterJoinTaskTest extends AbstractOuterJoinTaskTest {
cancel();
taskRunner.join(60000);
- assertFalse("Task thread did not finish within 60 seconds", taskRunner.isAlive());
+ assertThat(taskRunner.isAlive())
+ .withFailMessage("Task thread did not finish within 60 seconds")
+ .isFalse();
- final Throwable taskError = error.get();
- if (taskError != null) {
- fail("Error in task while canceling:\n" + Throwables.getStackTraceAsString(taskError));
- }
+ assertThat(error.get()).isNull();
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
index 3c1f4ac4b31..e2700e0ba67 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainTaskTest.java
@@ -41,10 +41,7 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -52,9 +49,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-public class ChainTaskTest extends TaskTestBase {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
- @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
+class ChainTaskTest extends TaskTestBase {
private static final int MEMORY_MANAGER_SIZE = 1024 * 1024 * 3;
@@ -70,7 +68,7 @@ public class ChainTaskTest extends TaskTestBase {
private final RecordSerializerFactory serFact = RecordSerializerFactory.get();
@Test
- public void testMapTask() {
+ void testMapTask() {
final int keyCnt = 100;
final int valCnt = 20;
@@ -120,19 +118,19 @@ public class ChainTaskTest extends TaskTestBase {
testTask.invoke();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
}
- Assert.assertEquals(keyCnt, this.outList.size());
+ assertThat(this.outList).hasSize(keyCnt);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testFailingMapTask() {
+ void testFailingMapTask() {
int keyCnt = 100;
int valCnt = 20;
@@ -186,16 +184,18 @@ public class ChainTaskTest extends TaskTestBase {
stubFailed = true;
}
- Assert.assertTrue("Function exception was not forwarded.", stubFailed);
+ assertThat(stubFailed)
+ .withFailMessage("Function exception was not forwarded.")
+ .isTrue();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testBatchTaskOutputInCloseMethod() {
+ void testBatchTaskOutputInCloseMethod() {
final int numChainedTasks = 10;
final int keyCnt = 100;
final int valCnt = 10;
@@ -216,19 +216,19 @@ public class ChainTaskTest extends TaskTestBase {
final BatchTask<FlatMapFunction<Record, Record>, Record> testTask =
new BatchTask<>(mockEnv);
testTask.invoke();
- Assert.assertEquals(keyCnt * valCnt + numChainedTasks, outList.size());
+ assertThat(outList).hasSize(keyCnt * valCnt + numChainedTasks);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testDataSourceTaskOutputInCloseMethod() throws IOException {
+ void testDataSourceTaskOutputInCloseMethod() throws IOException {
final int numChainedTasks = 10;
final int keyCnt = 100;
final int valCnt = 10;
- final File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());
+ final File tempTestFile = new File(tempFolder.toFile(), UUID.randomUUID().toString());
DataSourceTaskTest.InputFilePreparator.prepareInputFile(
new UniformRecordGenerator(keyCnt, valCnt, false), tempTestFile, true);
initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
@@ -250,10 +250,10 @@ public class ChainTaskTest extends TaskTestBase {
}
try {
testTask.invoke();
- Assert.assertEquals(keyCnt * valCnt + numChainedTasks, outList.size());
+ assertThat(outList).hasSize(keyCnt * valCnt + numChainedTasks);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("Invoke method caused exception.");
+ fail("Invoke method caused exception.");
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedAllReduceDriverTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedAllReduceDriverTest.java
index ea641b46eb4..693b355d834 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedAllReduceDriverTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedAllReduceDriverTest.java
@@ -35,13 +35,14 @@ import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
-public class ChainedAllReduceDriverTest extends TaskTestBase {
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ChainedAllReduceDriverTest extends TaskTestBase {
private static final int MEMORY_MANAGER_SIZE = 1024 * 1024 * 3;
@@ -57,7 +58,7 @@ public class ChainedAllReduceDriverTest extends TaskTestBase {
private final RecordSerializerFactory serFact = RecordSerializerFactory.get();
@Test
- public void testMapTask() throws Exception {
+ void testMapTask() throws Exception {
final int keyCnt = 100;
final int valCnt = 20;
@@ -103,8 +104,8 @@ public class ChainedAllReduceDriverTest extends TaskTestBase {
int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;
- Assert.assertEquals(1, this.outList.size());
- Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
+ assertThat(this.outList).hasSize(1);
+ assertThat(this.outList.get(0).getField(0, IntValue.class).getValue()).isEqualTo(sumTotal);
}
public static class MockReduceStub implements ReduceFunction<Record> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedOperatorsMetricTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedOperatorsMetricTest.java
index 0913b7b6fe7..5602e7478a2 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedOperatorsMetricTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/chaining/ChainedOperatorsMetricTest.java
@@ -46,13 +46,13 @@ import org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory;
import org.apache.flink.types.Record;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.createExecutionAttemptId;
+import static org.assertj.core.api.Assertions.assertThat;
/** Metrics related tests for batch task chains. */
public class ChainedOperatorsMetricTest extends TaskTestBase {
@@ -69,7 +69,7 @@ public class ChainedOperatorsMetricTest extends TaskTestBase {
private static final String CHAINED_OPERATOR_NAME = "chainedoperator";
@Test
- public void testOperatorIOMetricReuse() throws Exception {
+ void testOperatorIOMetricReuse() throws Exception {
// environment
initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
@@ -104,7 +104,7 @@ public class ChainedOperatorsMetricTest extends TaskTestBase {
testTask.invoke();
- Assert.assertEquals(numRecords * 2 * 2, this.outList.size());
+ assertThat(this.outList).hasSize(numRecords * 2 * 2);
final TaskMetricGroup taskMetricGroup = mockEnv.getMetricGroup();
@@ -114,8 +114,8 @@ public class ChainedOperatorsMetricTest extends TaskTestBase {
final Counter numRecordsInCounter = ioMetricGroup.getNumRecordsInCounter();
final Counter numRecordsOutCounter = ioMetricGroup.getNumRecordsOutCounter();
- Assert.assertEquals(numRecords, numRecordsInCounter.getCount());
- Assert.assertEquals(numRecords * 2 * 2, numRecordsOutCounter.getCount());
+ assertThat(numRecordsInCounter.getCount()).isEqualTo(numRecords);
+ assertThat(numRecordsOutCounter.getCount()).isEqualTo(numRecords * 2 * 2);
}
// verify head operator metrics
@@ -127,8 +127,8 @@ public class ChainedOperatorsMetricTest extends TaskTestBase {
final Counter numRecordsInCounter = ioMetricGroup.getNumRecordsInCounter();
final Counter numRecordsOutCounter = ioMetricGroup.getNumRecordsOutCounter();
- Assert.assertEquals(numRecords, numRecordsInCounter.getCount());
- Assert.assertEquals(numRecords * 2, numRecordsOutCounter.getCount());
+ assertThat(numRecordsInCounter.getCount()).isEqualTo(numRecords);
+ assertThat(numRecordsOutCounter.getCount()).isEqualTo(numRecords * 2);
}
// verify chained operator metrics
@@ -141,8 +141,8 @@ public class ChainedOperatorsMetricTest extends TaskTestBase {
final Counter numRecordsInCounter = ioMetricGroup.getNumRecordsInCounter();
final Counter numRecordsOutCounter = ioMetricGroup.getNumRecordsOutCounter();
- Assert.assertEquals(numRecords * 2, numRecordsInCounter.getCount());
- Assert.assertEquals(numRecords * 2 * 2, numRecordsOutCounter.getCount());
+ assertThat(numRecordsInCounter.getCount()).isEqualTo(numRecords * 2);
+ assertThat(numRecordsOutCounter.getCount()).isEqualTo(numRecords * 2 * 2);
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/ComponentClosingUtilsTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/ComponentClosingUtilsTest.java
index 0be26eabd96..9219eb52602 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/ComponentClosingUtilsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/ComponentClosingUtilsTest.java
@@ -22,8 +22,8 @@ import org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService
import org.apache.flink.util.clock.ManualClock;
import org.jetbrains.annotations.NotNull;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.util.List;
@@ -32,51 +32,51 @@ import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
/** The unit test class for {@link ComponentClosingUtils}. */
-public class ComponentClosingUtilsTest {
+class ComponentClosingUtilsTest {
private ManualClock clock;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
clock = new ManualClock();
ComponentClosingUtils.setClock(clock);
}
@Test
- public void testTryShutdownExecutorElegantlyWithoutForcefulShutdown() {
+ void testTryShutdownExecutorElegantlyWithoutForcefulShutdown() {
MockExecutorService executor = new MockExecutorService(0);
assertThat(ComponentClosingUtils.tryShutdownExecutorElegantly(executor, Duration.ofDays(1)))
.isTrue();
- assertThat(executor.forcefullyShutdownCount).isEqualTo(0);
+ assertThat(executor.forcefullyShutdownCount).isZero();
}
@Test
- public void testTryShutdownExecutorElegantlyWithForcefulShutdown() {
+ void testTryShutdownExecutorElegantlyWithForcefulShutdown() {
MockExecutorService executor = new MockExecutorService(5);
assertThat(ComponentClosingUtils.tryShutdownExecutorElegantly(executor, Duration.ofDays(1)))
.isFalse();
- assertThat(executor.forcefullyShutdownCount).isEqualTo(1);
+ assertThat(executor.forcefullyShutdownCount).isOne();
}
@Test
- public void testTryShutdownExecutorElegantlyTimeoutWithForcefulShutdown() {
+ void testTryShutdownExecutorElegantlyTimeoutWithForcefulShutdown() {
MockExecutorService executor = new MockExecutorService(5);
executor.timeoutAfterNumForcefulShutdown(clock, 0);
assertThat(ComponentClosingUtils.tryShutdownExecutorElegantly(executor, Duration.ofDays(1)))
.isFalse();
- assertThat(executor.forcefullyShutdownCount).isEqualTo(1);
+ assertThat(executor.forcefullyShutdownCount).isOne();
}
@Test
- public void testTryShutdownExecutorElegantlyInterruptedWithForcefulShutdown() {
+ void testTryShutdownExecutorElegantlyInterruptedWithForcefulShutdown() {
MockExecutorService executor = new MockExecutorService(5);
executor.interruptAfterNumForcefulShutdown(0);
assertThat(ComponentClosingUtils.tryShutdownExecutorElegantly(executor, Duration.ofDays(1)))
.isFalse();
- assertThat(executor.forcefullyShutdownCount).isEqualTo(1);
+ assertThat(executor.forcefullyShutdownCount).isOne();
}
@Test
- public void testShutdownExecutorForcefully() {
+ void testShutdownExecutorForcefully() {
MockExecutorService executor = new MockExecutorService(5);
assertThat(
ComponentClosingUtils.shutdownExecutorForcefully(
@@ -86,18 +86,18 @@ public class ComponentClosingUtilsTest {
}
@Test
- public void testShutdownExecutorForcefullyReachesTimeout() {
+ void testShutdownExecutorForcefullyReachesTimeout() {
MockExecutorService executor = new MockExecutorService(5);
executor.timeoutAfterNumForcefulShutdown(clock, 1);
assertThat(
ComponentClosingUtils.shutdownExecutorForcefully(
executor, Duration.ofDays(1), false))
.isFalse();
- assertThat(executor.forcefullyShutdownCount).isEqualTo(1);
+ assertThat(executor.forcefullyShutdownCount).isOne();
}
@Test
- public void testShutdownExecutorForcefullyNotInterruptable() {
+ void testShutdownExecutorForcefullyNotInterruptable() {
MockExecutorService executor = new MockExecutorService(5);
executor.interruptAfterNumForcefulShutdown(1);
assertThat(
@@ -108,14 +108,14 @@ public class ComponentClosingUtilsTest {
}
@Test
- public void testShutdownExecutorForcefullyInterruptable() {
+ void testShutdownExecutorForcefullyInterruptable() {
MockExecutorService executor = new MockExecutorService(5);
executor.interruptAfterNumForcefulShutdown(1);
assertThat(
ComponentClosingUtils.shutdownExecutorForcefully(
executor, Duration.ofDays(1), true))
.isFalse();
- assertThat(executor.forcefullyShutdownCount).isEqualTo(1);
+ assertThat(executor.forcefullyShutdownCount).isOne();
}
// ============== private class for testing ===============
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/CoordinatorEventsExactlyOnceITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/CoordinatorEventsExactlyOnceITCase.java
index 52cd8981de2..5ec71af6144 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/CoordinatorEventsExactlyOnceITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/CoordinatorEventsExactlyOnceITCase.java
@@ -43,18 +43,17 @@ import org.apache.flink.runtime.state.StreamStateHandle;
import org.apache.flink.runtime.state.TaskStateManager;
import org.apache.flink.runtime.state.memory.ByteStreamStateHandle;
import org.apache.flink.runtime.taskmanager.DispatcherThreadFactory;
-import org.apache.flink.runtime.testutils.MiniClusterResource;
+import org.apache.flink.runtime.testutils.InternalMiniClusterExtension;
import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.util.FlinkException;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.SerializedValue;
-import org.apache.flink.util.TestLogger;
import org.apache.flink.shaded.guava31.com.google.common.collect.Iterators;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import javax.annotation.Nullable;
@@ -123,7 +122,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* different delays in which they complete their checkpoints. Both coordinators inject failures at
* different points.
*/
-public class CoordinatorEventsExactlyOnceITCase extends TestLogger {
+public class CoordinatorEventsExactlyOnceITCase {
private static final ConfigOption<String> ACC_NAME =
ConfigOptions.key("acc").stringType().noDefaultValue();
@@ -131,9 +130,9 @@ public class CoordinatorEventsExactlyOnceITCase extends TestLogger {
private static final String OPERATOR_1_NAME = "operator-1";
private static final String OPERATOR_2_NAME = "operator-2";
- @ClassRule
- public static final MiniClusterResource MINI_CLUSTER =
- new MiniClusterResource(
+ @RegisterExtension
+ protected static final InternalMiniClusterExtension MINI_CLUSTER =
+ new InternalMiniClusterExtension(
new MiniClusterResourceConfiguration.Builder()
.setNumberTaskManagers(2)
.setNumberSlotsPerTaskManager(1)
@@ -142,7 +141,7 @@ public class CoordinatorEventsExactlyOnceITCase extends TestLogger {
// ------------------------------------------------------------------------
@Test
- public void test() throws Exception {
+ void test() throws Exception {
// this captures variables communicated across instances, recoveries, etc.
TestScript.reset();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/EventReceivingTasks.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/EventReceivingTasks.java
index be23daf88ad..3d3df195856 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/EventReceivingTasks.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/EventReceivingTasks.java
@@ -135,7 +135,7 @@ public class EventReceivingTasks implements SubtaskAccess.SubtaskAccessFactory {
// ------------------------------------------------------------------------
/** A combination of an {@link OperatorEvent} and the target subtask it is sent to. */
- public static final class EventWithSubtask {
+ static final class EventWithSubtask {
public final OperatorEvent event;
public final int subtask;
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorHolderTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorHolderTest.java
index fb6a7267408..95841dcb634 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorHolderTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorHolderTest.java
@@ -32,10 +32,9 @@ import org.apache.flink.runtime.operators.coordination.EventReceivingTasks.Event
import org.apache.flink.runtime.scheduler.GlobalFailureHandler;
import org.apache.flink.runtime.testtasks.NoOpInvokable;
import org.apache.flink.util.ExceptionUtils;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -51,19 +50,20 @@ import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
import static org.assertj.core.api.Assertions.assertThat;
/**
* A test that ensures the before/after conditions around event sending and checkpoint are met.
* concurrency
*/
-public class OperatorCoordinatorHolderTest extends TestLogger {
+class OperatorCoordinatorHolderTest {
private final GlobalFailureHandler globalFailureHandler = (t) -> globalFailure = t;
private Throwable globalFailure;
- @After
- public void checkNoGlobalFailure() throws Exception {
+ @AfterEach
+ void checkNoGlobalFailure() throws Exception {
if (globalFailure != null) {
ExceptionUtils.rethrowException(globalFailure);
}
@@ -72,7 +72,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
// ------------------------------------------------------------------------
@Test
- public void checkpointFutureInitiallyNotDone() throws Exception {
+ void checkpointFutureInitiallyNotDone() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -84,7 +84,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void completedCheckpointFuture() throws Exception {
+ void completedCheckpointFuture() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -96,11 +96,11 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
getCoordinator(holder).getLastTriggeredCheckpoint().complete(testData);
assertThat(checkpointFuture).isDone();
- assertThat(checkpointFuture.get()).containsExactly(testData);
+ assertThatFuture(checkpointFuture).eventuallySucceeds().isEqualTo(testData);
}
@Test
- public void eventsBeforeCheckpointFutureCompletionPassThrough() throws Exception {
+ void eventsBeforeCheckpointFutureCompletionPassThrough() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -113,7 +113,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void eventsAreBlockedAfterCheckpointFutureCompletes() throws Exception {
+ void eventsAreBlockedAfterCheckpointFutureCompletes() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -121,11 +121,11 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
triggerAndCompleteCheckpoint(holder, 10L);
getCoordinator(holder).getSubtaskGateway(0).sendEvent(new TestOperatorEvent(1337));
- assertThat(tasks.getNumberOfSentEvents()).isEqualTo(0);
+ assertThat(tasks.getNumberOfSentEvents()).isZero();
}
@Test
- public void abortedCheckpointReleasesBlockedEvents() throws Exception {
+ void abortedCheckpointReleasesBlockedEvents() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -138,7 +138,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void acknowledgeCheckpointEventReleasesBlockedEvents() throws Exception {
+ void acknowledgeCheckpointEventReleasesBlockedEvents() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -151,7 +151,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void restoreOpensGatewayEvents() throws Exception {
+ void restoreOpensGatewayEvents() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -164,7 +164,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void lateCompleteCheckpointFutureDoesNotBlockEvents() throws Exception {
+ void lateCompleteCheckpointFutureDoesNotBlockEvents() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -188,7 +188,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void takeCheckpointAfterSuccessfulCheckpoint() throws Exception {
+ void takeCheckpointAfterSuccessfulCheckpoint() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -218,7 +218,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void takeCheckpointAfterAbortedCheckpoint() throws Exception {
+ void takeCheckpointAfterAbortedCheckpoint() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
@@ -244,7 +244,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void testFailingJobMultipleTimesNotCauseCascadingJobFailure() throws Exception {
+ void testFailingJobMultipleTimesNotCauseCascadingJobFailure() throws Exception {
Function<OperatorCoordinator.Context, OperatorCoordinator> coordinatorProvider =
context ->
new TestingOperatorCoordinator(context) {
@@ -279,7 +279,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void checkpointCompletionWaitsForEventFutures() throws Exception {
+ void checkpointCompletionWaitsForEventFutures() throws Exception {
final CompletableFuture<Acknowledge> ackFuture = new CompletableFuture<>();
final EventReceivingTasks tasks =
EventReceivingTasks.createForRunningTasksWithRpcResult(ackFuture);
@@ -303,8 +303,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
* event directly after that.
*/
@Test
- public void verifyCheckpointEventOrderWhenCheckpointFutureCompletedImmediately()
- throws Exception {
+ void verifyCheckpointEventOrderWhenCheckpointFutureCompletedImmediately() throws Exception {
checkpointEventValueAtomicity(FutureCompletedInstantlyTestCoordinator::new);
}
@@ -316,7 +315,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
* before completing the checkpoint future.
*/
@Test
- public void verifyCheckpointEventOrderWhenCheckpointFutureCompletesLate() throws Exception {
+ void verifyCheckpointEventOrderWhenCheckpointFutureCompletesLate() throws Exception {
checkpointEventValueAtomicity(FutureCompletedAfterSendingEventsCoordinator::new);
}
@@ -364,7 +363,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void testCheckpointFailsIfSendingEventFailedAfterTrigger() throws Exception {
+ void testCheckpointFailsIfSendingEventFailedAfterTrigger() throws Exception {
CompletableFuture<Acknowledge> eventSendingResult = new CompletableFuture<>();
final EventReceivingTasks tasks =
EventReceivingTasks.createForRunningTasksWithRpcResult(eventSendingResult);
@@ -386,7 +385,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void testCheckpointFailsIfSendingEventFailedBeforeTrigger() throws Exception {
+ void testCheckpointFailsIfSendingEventFailedBeforeTrigger() throws Exception {
final ReorderableManualExecutorService executor = new ReorderableManualExecutorService();
final ComponentMainThreadExecutor mainThreadExecutor =
new ComponentMainThreadExecutorServiceAdapter(
@@ -428,7 +427,7 @@ public class OperatorCoordinatorHolderTest extends TestLogger {
}
@Test
- public void testControlGatewayAtSubtaskGranularity() throws Exception {
+ void testControlGatewayAtSubtaskGranularity() throws Exception {
final EventReceivingTasks tasks = EventReceivingTasks.createForRunningTasks();
final OperatorCoordinatorHolder holder =
createCoordinatorHolder(tasks, TestingOperatorCoordinator::new);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorSchedulerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorSchedulerTest.java
index 020a584cc61..cf5b9048b22 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorSchedulerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/OperatorCoordinatorSchedulerTest.java
@@ -67,16 +67,15 @@ import org.apache.flink.runtime.state.ttl.TtlTimeProvider;
import org.apache.flink.runtime.taskexecutor.TaskExecutorOperatorEventGateway;
import org.apache.flink.runtime.testtasks.NoOpInvokable;
import org.apache.flink.testutils.TestingUtils;
-import org.apache.flink.testutils.executor.TestExecutorResource;
+import org.apache.flink.testutils.executor.TestExecutorExtension;
import org.apache.flink.util.FlinkException;
import org.apache.flink.util.SerializedValue;
-import org.apache.flink.util.TestLogger;
import org.apache.flink.util.concurrent.FutureUtils;
-import org.junit.After;
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -102,22 +101,22 @@ import static org.assertj.core.api.Assertions.fail;
* Tests for the integration of the {@link OperatorCoordinator} with the scheduler, to ensure the
* relevant actions are leading to the right method invocations on the coordinator.
*/
-public class OperatorCoordinatorSchedulerTest extends TestLogger {
+class OperatorCoordinatorSchedulerTest {
private final JobVertexID testVertexId = new JobVertexID();
private final OperatorID testOperatorId = new OperatorID();
- @ClassRule
- public static final TestExecutorResource<ScheduledExecutorService> EXECUTOR_RESOURCE =
- TestingUtils.defaultExecutorResource();
+ @RegisterExtension
+ private static final TestExecutorExtension<ScheduledExecutorService> EXECUTOR_EXTENSION =
+ TestingUtils.defaultExecutorExtension();
private final ManuallyTriggeredScheduledExecutorService executor =
new ManuallyTriggeredScheduledExecutorService();
private DefaultScheduler createdScheduler;
- @After
- public void shutdownScheduler() throws Exception {
+ @AfterEach
+ void shutdownScheduler() throws Exception {
if (createdScheduler != null) {
closeScheduler(createdScheduler);
}
@@ -128,7 +127,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
// ------------------------------------------------------------------------
@Test
- public void testCoordinatorStartedWhenSchedulerStarts() throws Exception {
+ void testCoordinatorStartedWhenSchedulerStarts() throws Exception {
final DefaultScheduler scheduler = createAndStartScheduler();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -136,7 +135,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testCoordinatorDisposedWhenSchedulerStops() throws Exception {
+ void testCoordinatorDisposedWhenSchedulerStops() throws Exception {
final DefaultScheduler scheduler = createAndStartScheduler();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -146,7 +145,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testFailureToStartPropagatesExceptions() throws Exception {
+ void testFailureToStartPropagatesExceptions() throws Exception {
final OperatorCoordinator.Provider failingCoordinatorProvider =
new TestingOperatorCoordinator.Provider(
testOperatorId, CoordinatorThatFailsInStart::new);
@@ -161,7 +160,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testFailureToStartClosesCoordinator() throws Exception {
+ void testFailureToStartClosesCoordinator() throws Exception {
final OperatorCoordinator.Provider failingCoordinatorProvider =
new TestingOperatorCoordinator.Provider(
testOperatorId, CoordinatorThatFailsInStart::new);
@@ -177,7 +176,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void deployingTaskFailureNotifiesCoordinator() throws Exception {
+ void deployingTaskFailureNotifiesCoordinator() throws Exception {
final DefaultScheduler scheduler = createAndStartScheduler();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -187,7 +186,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void runningTaskFailureNotifiesCoordinator() throws Exception {
+ void runningTaskFailureNotifiesCoordinator() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -197,7 +196,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void cancellationAsPartOfFailoverNotifiesCoordinator() throws Exception {
+ void cancellationAsPartOfFailoverNotifiesCoordinator() throws Exception {
final DefaultScheduler scheduler = createSchedulerWithAllRestartOnFailureAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -207,7 +206,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void taskRepeatedFailureNotifyCoordinator() throws Exception {
+ void taskRepeatedFailureNotifyCoordinator() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -218,7 +217,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void taskGatewayNotSetBeforeTasksRunning() throws Exception {
+ void taskGatewayNotSetBeforeTasksRunning() throws Exception {
final DefaultScheduler scheduler = createAndStartScheduler();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
final OperatorCoordinator.SubtaskGateway gateway = coordinator.getSubtaskGateway(0);
@@ -227,7 +226,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void taskGatewayAvailableWhenTasksRunning() throws Exception {
+ void taskGatewayAvailableWhenTasksRunning() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
final OperatorCoordinator.SubtaskGateway gateway = coordinator.getSubtaskGateway(0);
@@ -236,7 +235,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void taskTaskManagerFailuresAreReportedBack() throws Exception {
+ void taskTaskManagerFailuresAreReportedBack() throws Exception {
final DefaultScheduler scheduler =
createSchedulerAndDeployTasks(new FailingTaskExecutorOperatorEventGateway());
@@ -253,9 +252,9 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
// THIS SITUATION AT THE MOMENT
// WE KEEP THESE TESTS HERE TO ENABLE THEM ONCE THE SCHEDULER'S CONTRACT SUPPORTS THEM
- @Ignore
+ @Disabled
@Test
- public void deployingTaskCancellationNotifiesCoordinator() throws Exception {
+ void deployingTaskCancellationNotifiesCoordinator() throws Exception {
final DefaultScheduler scheduler = createAndStartScheduler();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -264,9 +263,9 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
assertThat(coordinator.getFailedTasks()).hasSize(1).containsExactly(1);
}
- @Ignore
+ @Disabled
@Test
- public void runningTaskCancellationNotifiesCoordinator() throws Exception {
+ void runningTaskCancellationNotifiesCoordinator() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -280,7 +279,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
// ------------------------------------------------------------------------
@Test
- public void testTakeCheckpoint() throws Exception {
+ void testTakeCheckpoint() throws Exception {
final byte[] checkpointData = new byte[656];
new Random().nextBytes(checkpointData);
@@ -305,7 +304,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testSnapshotSyncFailureFailsCheckpoint() throws Exception {
+ void testSnapshotSyncFailureFailsCheckpoint() throws Exception {
final OperatorCoordinator.Provider failingCoordinatorProvider =
new TestingOperatorCoordinator.Provider(
testOperatorId, CoordinatorThatFailsCheckpointing::new);
@@ -318,7 +317,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testSnapshotAsyncFailureFailsCheckpoint() throws Exception {
+ void testSnapshotAsyncFailureFailsCheckpoint() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -333,7 +332,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testSavepointRestoresCoordinator() throws Exception {
+ void testSavepointRestoresCoordinator() throws Exception {
final byte[] testCoordinatorState = new byte[123];
new Random().nextBytes(testCoordinatorState);
@@ -346,7 +345,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testGlobalFailureResetsToCheckpoint() throws Exception {
+ void testGlobalFailureResetsToCheckpoint() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -360,7 +359,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testGlobalFailureBeforeCheckpointResetsToEmptyState() throws Exception {
+ void testGlobalFailureBeforeCheckpointResetsToEmptyState() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -374,7 +373,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testGlobalFailureTwiceWillNotResetToCheckpointTwice() throws Exception {
+ void testGlobalFailureTwiceWillNotResetToCheckpointTwice() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
AtomicInteger resetToCheckpointCounter = new AtomicInteger(0);
@@ -385,7 +384,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
scheduler.handleGlobalFailure(new TestException());
failGlobalAndRestart(scheduler, new TestException());
- assertThat(resetToCheckpointCounter.get()).isEqualTo(1);
+ assertThat(resetToCheckpointCounter).hasValue(1);
assertThat(coordinator.getLastRestoredCheckpointState())
.as("coordinator should have null restored state")
.isEqualTo(TestingOperatorCoordinator.NULL_RESTORE_VALUE);
@@ -394,7 +393,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testGlobalFailoverDoesNotNotifyLocalRestore() throws Exception {
+ void testGlobalFailoverDoesNotNotifyLocalRestore() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -405,7 +404,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testLocalFailoverResetsTask() throws Exception {
+ void testLocalFailoverResetsTask() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -415,12 +414,12 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
assertThat(coordinator.getRestoredTasks()).hasSize(1);
final TestingOperatorCoordinator.SubtaskAndCheckpoint restoredTask =
coordinator.getRestoredTasks().get(0);
- assertThat(restoredTask.subtaskIndex).isEqualTo(1);
+ assertThat(restoredTask.subtaskIndex).isOne();
assertThat(restoredTask.checkpointId).isEqualTo(checkpointId);
}
@Test
- public void testLocalFailoverBeforeCheckpointResetsTask() throws Exception {
+ void testLocalFailoverBeforeCheckpointResetsTask() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -429,12 +428,12 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
assertThat(coordinator.getRestoredTasks()).hasSize(1);
final TestingOperatorCoordinator.SubtaskAndCheckpoint restoredTask =
coordinator.getRestoredTasks().get(0);
- assertThat(restoredTask.subtaskIndex).isEqualTo(1);
+ assertThat(restoredTask.subtaskIndex).isOne();
assertThat(restoredTask.checkpointId).isEqualTo(OperatorCoordinator.NO_CHECKPOINT);
}
@Test
- public void testLocalFailoverDoesNotResetToCheckpoint() throws Exception {
+ void testLocalFailoverDoesNotResetToCheckpoint() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -447,7 +446,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testConfirmCheckpointComplete() throws Exception {
+ void testConfirmCheckpointComplete() throws Exception {
final DefaultScheduler scheduler = createSchedulerAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -464,7 +463,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
// ------------------------------------------------------------------------
@Test
- public void testBatchGlobalFailureResetsToEmptyState() throws Exception {
+ void testBatchGlobalFailureResetsToEmptyState() throws Exception {
final DefaultScheduler scheduler = createSchedulerWithoutCheckpointingAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -478,7 +477,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testBatchGlobalFailoverDoesNotNotifyLocalRestore() throws Exception {
+ void testBatchGlobalFailoverDoesNotNotifyLocalRestore() throws Exception {
final DefaultScheduler scheduler = createSchedulerWithoutCheckpointingAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -488,7 +487,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testBatchLocalFailoverResetsTask() throws Exception {
+ void testBatchLocalFailoverResetsTask() throws Exception {
final DefaultScheduler scheduler = createSchedulerWithoutCheckpointingAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -497,12 +496,12 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
assertThat(coordinator.getRestoredTasks()).hasSize(1);
final TestingOperatorCoordinator.SubtaskAndCheckpoint restoredTask =
coordinator.getRestoredTasks().get(0);
- assertThat(restoredTask.subtaskIndex).isEqualTo(1);
+ assertThat(restoredTask.subtaskIndex).isOne();
assertThat(restoredTask.checkpointId).isEqualTo(OperatorCoordinator.NO_CHECKPOINT);
}
@Test
- public void testBatchLocalFailoverDoesNotResetToCheckpoint() throws Exception {
+ void testBatchLocalFailoverDoesNotResetToCheckpoint() throws Exception {
final DefaultScheduler scheduler = createSchedulerWithoutCheckpointingAndDeployTasks();
final TestingOperatorCoordinator coordinator = getCoordinator(scheduler);
@@ -519,7 +518,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
@Test
@SuppressWarnings("unchecked")
- public void testDeliveringClientRequestToRequestHandler() throws Exception {
+ void testDeliveringClientRequestToRequestHandler() throws Exception {
final OperatorCoordinator.Provider provider =
new TestingCoordinationRequestHandler.Provider(testOperatorId);
final DefaultScheduler scheduler = createScheduler(provider);
@@ -537,7 +536,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testDeliveringClientRequestToNonRequestHandler() throws Exception {
+ void testDeliveringClientRequestToNonRequestHandler() throws Exception {
final OperatorCoordinator.Provider provider =
new TestingOperatorCoordinator.Provider(testOperatorId);
final DefaultScheduler scheduler = createScheduler(provider);
@@ -553,7 +552,7 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
}
@Test
- public void testDeliveringClientRequestToNonExistingCoordinator() throws Exception {
+ void testDeliveringClientRequestToNonExistingCoordinator() throws Exception {
final OperatorCoordinator.Provider provider =
new TestingOperatorCoordinator.Provider(testOperatorId);
final DefaultScheduler scheduler = createScheduler(provider);
@@ -705,12 +704,12 @@ public class OperatorCoordinatorSchedulerTest extends TestLogger {
final DefaultSchedulerBuilder schedulerBuilder =
taskExecutorOperatorEventGateway == null
? createSchedulerBuilder(
- jobGraph, mainThreadExecutor, EXECUTOR_RESOURCE.getExecutor())
+ jobGraph, mainThreadExecutor, EXECUTOR_EXTENSION.getExecutor())
: createSchedulerBuilder(
jobGraph,
mainThreadExecutor,
taskExecutorOperatorEventGateway,
- EXECUTOR_RESOURCE.getExecutor());
+ EXECUTOR_EXTENSION.getExecutor());
if (restartAllOnFailover) {
schedulerBuilder.setFailoverStrategyFactory(new RestartAllFailoverStrategy.Factory());
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/RecreateOnResetOperatorCoordinatorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/RecreateOnResetOperatorCoordinatorTest.java
index e0115bd4ccb..bb0fedcf244 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/RecreateOnResetOperatorCoordinatorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/RecreateOnResetOperatorCoordinatorTest.java
@@ -21,7 +21,8 @@ package org.apache.flink.runtime.operators.coordination;
import org.apache.flink.core.testutils.CommonTestUtils;
import org.apache.flink.runtime.jobgraph.OperatorID;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import java.time.Duration;
import java.util.ArrayList;
@@ -33,13 +34,13 @@ import java.util.concurrent.CountDownLatch;
import static org.assertj.core.api.Assertions.assertThat;
/** Unit tests for {@link RecreateOnResetOperatorCoordinator}. */
-public class RecreateOnResetOperatorCoordinatorTest {
+class RecreateOnResetOperatorCoordinatorTest {
private static final OperatorID OPERATOR_ID = new OperatorID(1234L, 5678L);
private static final int NUM_SUBTASKS = 1;
@Test
- public void testQuiesceableContextForwardsProperties() {
+ void testQuiesceableContextForwardsProperties() {
MockOperatorCoordinatorContext context =
new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SUBTASKS);
RecreateOnResetOperatorCoordinator.QuiesceableContext quiesceableContext =
@@ -50,7 +51,7 @@ public class RecreateOnResetOperatorCoordinatorTest {
}
@Test
- public void testQuiesceableContextNotQuiesced() {
+ void testQuiesceableContextNotQuiesced() {
MockOperatorCoordinatorContext context =
new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SUBTASKS);
RecreateOnResetOperatorCoordinator.QuiesceableContext quiesceableContext =
@@ -64,7 +65,7 @@ public class RecreateOnResetOperatorCoordinatorTest {
}
@Test
- public void testQuiescedContext() {
+ void testQuiescedContext() {
MockOperatorCoordinatorContext context =
new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SUBTASKS);
RecreateOnResetOperatorCoordinator.QuiesceableContext quiesceableContext =
@@ -77,7 +78,7 @@ public class RecreateOnResetOperatorCoordinatorTest {
}
@Test
- public void testResetToCheckpoint() throws Exception {
+ void testResetToCheckpoint() throws Exception {
TestingCoordinatorProvider provider = new TestingCoordinatorProvider(null);
MockOperatorCoordinatorContext context =
new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SUBTASKS);
@@ -105,7 +106,7 @@ public class RecreateOnResetOperatorCoordinatorTest {
}
@Test
- public void testResetToCheckpointTimeout() throws Exception {
+ void testResetToCheckpointTimeout() throws Exception {
final long closingTimeoutMs = 1L;
// Let the user coordinator block on close.
TestingCoordinatorProvider provider = new TestingCoordinatorProvider(new CountDownLatch(1));
@@ -122,7 +123,7 @@ public class RecreateOnResetOperatorCoordinatorTest {
}
@Test
- public void testMethodCallsOnLongResetToCheckpoint() throws Exception {
+ void testMethodCallsOnLongResetToCheckpoint() throws Exception {
final long closingTimeoutMs = Long.MAX_VALUE;
final CountDownLatch blockOnCloseLatch = new CountDownLatch(1);
// Let the user coordinator block on close.
@@ -184,8 +185,9 @@ public class RecreateOnResetOperatorCoordinatorTest {
.isEqualTo(completedCheckpointId);
}
- @Test(timeout = 30000L)
- public void testConsecutiveResetToCheckpoint() throws Exception {
+ @Test
+ @Timeout(30)
+ void testConsecutiveResetToCheckpoint() throws Exception {
final long closingTimeoutMs = Long.MAX_VALUE;
final int numResets = 1000;
// Let the user coordinator block on close.
@@ -265,7 +267,7 @@ public class RecreateOnResetOperatorCoordinatorTest {
}
@Test
- public void testNotifyCheckpointAbortedSuccess() throws Exception {
+ void testNotifyCheckpointAbortedSuccess() throws Exception {
TestingCoordinatorProvider provider = new TestingCoordinatorProvider(null);
MockOperatorCoordinatorContext context =
new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SUBTASKS);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/SubtaskGatewayImplTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/SubtaskGatewayImplTest.java
index ad15f61eec6..cd19fcfd5d4 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/SubtaskGatewayImplTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/SubtaskGatewayImplTest.java
@@ -25,7 +25,7 @@ import org.apache.flink.runtime.operators.coordination.util.IncompleteFuturesTra
import org.apache.flink.util.FlinkException;
import org.apache.flink.util.Preconditions;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
@@ -36,10 +36,10 @@ import java.util.concurrent.CompletableFuture;
import static org.assertj.core.api.Assertions.assertThat;
/** Unit tests for the {@link SubtaskGatewayImpl}. */
-public class SubtaskGatewayImplTest {
+class SubtaskGatewayImplTest {
@Test
- public void eventsPassThroughOpenGateway() {
+ void eventsPassThroughOpenGateway() {
final EventReceivingTasks receiver = EventReceivingTasks.createForRunningTasks();
final SubtaskGatewayImpl gateway =
new SubtaskGatewayImpl(
@@ -55,7 +55,7 @@ public class SubtaskGatewayImplTest {
}
@Test
- public void closingMarkedGateway() {
+ void closingMarkedGateway() {
final EventReceivingTasks receiver = EventReceivingTasks.createForRunningTasks();
final SubtaskGatewayImpl gateway =
new SubtaskGatewayImpl(
@@ -70,7 +70,7 @@ public class SubtaskGatewayImplTest {
}
@Test
- public void notClosingUnmarkedGateway() {
+ void notClosingUnmarkedGateway() {
final EventReceivingTasks receiver = EventReceivingTasks.createForRunningTasks();
final SubtaskGatewayImpl gateway =
new SubtaskGatewayImpl(
@@ -84,7 +84,7 @@ public class SubtaskGatewayImplTest {
}
@Test
- public void notClosingGatewayForOtherMark() {
+ void notClosingGatewayForOtherMark() {
final EventReceivingTasks receiver = EventReceivingTasks.createForRunningTasks();
final SubtaskGatewayImpl gateway =
new SubtaskGatewayImpl(
@@ -99,7 +99,7 @@ public class SubtaskGatewayImplTest {
}
@Test
- public void eventsBlockedByClosedGateway() {
+ void eventsBlockedByClosedGateway() {
final EventReceivingTasks receiver = EventReceivingTasks.createForRunningTasks();
final SubtaskGatewayImpl gateway =
new SubtaskGatewayImpl(
@@ -117,7 +117,7 @@ public class SubtaskGatewayImplTest {
}
@Test
- public void eventsReleasedAfterOpeningGateway() {
+ void eventsReleasedAfterOpeningGateway() {
final EventReceivingTasks receiver = EventReceivingTasks.createForRunningTasks();
final SubtaskGatewayImpl gateway0 =
new SubtaskGatewayImpl(
@@ -148,7 +148,7 @@ public class SubtaskGatewayImplTest {
}
@Test
- public void releasedEventsForwardSendFailures() {
+ void releasedEventsForwardSendFailures() {
final EventReceivingTasks receiver =
EventReceivingTasks.createForRunningTasksFailingRpcs(new FlinkException("test"));
final SubtaskGatewayImpl gateway =
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/util/IncompleteFuturesTrackerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/util/IncompleteFuturesTrackerTest.java
index 8c76c99acb8..0ab7a3f08b9 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/util/IncompleteFuturesTrackerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/coordination/util/IncompleteFuturesTrackerTest.java
@@ -18,19 +18,19 @@
package org.apache.flink.runtime.operators.coordination.util;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
/** Unit tests for the {@link IncompleteFuturesTracker}. */
-public class IncompleteFuturesTrackerTest {
+class IncompleteFuturesTrackerTest {
@Test
- public void testFutureTracked() {
+ void testFutureTracked() {
final IncompleteFuturesTracker tracker = new IncompleteFuturesTracker();
final CompletableFuture<?> future = new CompletableFuture<>();
@@ -40,7 +40,7 @@ public class IncompleteFuturesTrackerTest {
}
@Test
- public void testFutureRemovedAfterCompletion() {
+ void testFutureRemovedAfterCompletion() {
final IncompleteFuturesTracker tracker = new IncompleteFuturesTracker();
final CompletableFuture<?> future = new CompletableFuture<>();
@@ -51,7 +51,7 @@ public class IncompleteFuturesTrackerTest {
}
@Test
- public void testFutureNotAddedIfAlreadyCompleted() {
+ void testFutureNotAddedIfAlreadyCompleted() {
final IncompleteFuturesTracker tracker = new IncompleteFuturesTracker();
final CompletableFuture<?> future = new CompletableFuture<>();
@@ -62,7 +62,7 @@ public class IncompleteFuturesTrackerTest {
}
@Test
- public void testFailFutures() throws Exception {
+ void testFailFutures() {
final IncompleteFuturesTracker tracker = new IncompleteFuturesTracker();
final CompletableFuture<?> future = new CompletableFuture<>();
@@ -71,17 +71,13 @@ public class IncompleteFuturesTrackerTest {
final Exception expectedException = new Exception();
tracker.failAllFutures(expectedException);
- assertThat(future).isCompletedExceptionally();
- try {
- future.get();
- fail(null);
- } catch (ExecutionException e) {
- assertThat(e.getCause()).isEqualTo(expectedException);
- }
+ assertThatFuture(future)
+ .eventuallyFailsWith(ExecutionException.class)
+ .withCause(expectedException);
}
@Test
- public void testFailFuturesImmediately() throws Exception {
+ void testFailFuturesImmediately() {
final IncompleteFuturesTracker tracker = new IncompleteFuturesTracker();
final CompletableFuture<?> future = new CompletableFuture<>();
@@ -90,17 +86,13 @@ public class IncompleteFuturesTrackerTest {
tracker.trackFutureWhileIncomplete(future);
- assertThat(future).isCompletedExceptionally();
- try {
- future.get();
- fail(null);
- } catch (ExecutionException e) {
- assertThat(e.getCause()).isEqualTo(expectedException);
- }
+ assertThatFuture(future)
+ .eventuallyFailsWith(ExecutionException.class)
+ .withCause(expectedException);
}
@Test
- public void testResetClearsTrackedFutures() {
+ void testResetClearsTrackedFutures() {
final IncompleteFuturesTracker tracker = new IncompleteFuturesTracker();
final CompletableFuture<?> future = new CompletableFuture<>();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllGroupReduceDriverTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllGroupReduceDriverTest.java
index 93ce7c450ac..cc55ccb1844 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllGroupReduceDriverTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllGroupReduceDriverTest.java
@@ -34,17 +34,19 @@ import org.apache.flink.types.StringValue;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
@SuppressWarnings("serial")
-public class AllGroupReduceDriverTest {
+class AllGroupReduceDriverTest {
@Test
- public void testAllReduceDriverImmutableEmpty() {
+ void testAllReduceDriverImmutableEmpty() {
try {
TestTaskContext<
GroupReduceFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>,
@@ -72,12 +74,12 @@ public class AllGroupReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverImmutable() {
+ void testAllReduceDriverImmutable() {
try {
TestTaskContext<
GroupReduceFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>,
@@ -118,17 +120,17 @@ public class AllGroupReduceDriverTest {
char[] expectedString = "abcddeeeffff".toCharArray();
Arrays.sort(expectedString);
- Assert.assertArrayEquals(expectedString, foundString);
- Assert.assertEquals(78, res.f1.intValue());
+ assertThat(foundString).isEqualTo(expectedString);
+ assertThat(res.f1).isEqualTo(78);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverMutable() {
+ void testAllReduceDriverMutable() {
try {
TestTaskContext<
GroupReduceFunction<
@@ -173,19 +175,19 @@ public class AllGroupReduceDriverTest {
char[] expectedString = "abcddeeeffff".toCharArray();
Arrays.sort(expectedString);
- Assert.assertArrayEquals(expectedString, foundString);
- Assert.assertEquals(78, res.f1.getValue());
+ assertThat(foundString).isEqualTo(expectedString);
+ assertThat(res.f1.getValue()).isEqualTo(78);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
// --------------------------------------------------------------------------------------------
// Test UDFs
// --------------------------------------------------------------------------------------------
- public static final class ConcatSumReducer
+ private static final class ConcatSumReducer
extends RichGroupReduceFunction<Tuple2<String, Integer>, Tuple2<String, Integer>> {
@Override
@@ -203,7 +205,7 @@ public class AllGroupReduceDriverTest {
}
}
- public static final class ConcatSumMutableReducer
+ private static final class ConcatSumMutableReducer
extends RichGroupReduceFunction<
Tuple2<StringValue, IntValue>, Tuple2<StringValue, IntValue>> {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllReduceDriverTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllReduceDriverTest.java
index 4f0880cdc8b..385f04331b1 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllReduceDriverTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/AllReduceDriverTest.java
@@ -33,17 +33,19 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.StringValue;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
@SuppressWarnings("serial")
-public class AllReduceDriverTest {
+class AllReduceDriverTest {
@Test
- public void testAllReduceDriverImmutableEmpty() {
+ void testAllReduceDriverImmutableEmpty() {
try {
TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>
context =
@@ -68,12 +70,12 @@ public class AllReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverImmutable() {
+ void testAllReduceDriverImmutable() {
try {
{
TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>
@@ -112,8 +114,8 @@ public class AllReduceDriverTest {
char[] expectedString = "abcddeeeffff".toCharArray();
Arrays.sort(expectedString);
- Assert.assertArrayEquals(expectedString, foundString);
- Assert.assertEquals(78, res.f1.intValue());
+ assertThat(foundString).isEqualTo(expectedString);
+ assertThat(res.f1).isEqualTo(78);
}
{
@@ -153,18 +155,18 @@ public class AllReduceDriverTest {
char[] expectedString = "abcddeeeffff".toCharArray();
Arrays.sort(expectedString);
- Assert.assertArrayEquals(expectedString, foundString);
- Assert.assertEquals(78, res.f1.intValue());
+ assertThat(foundString).isEqualTo(expectedString);
+ assertThat(res.f1).isEqualTo(78);
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverMutable() {
+ void testAllReduceDriverMutable() {
try {
{
TestTaskContext<
@@ -205,8 +207,8 @@ public class AllReduceDriverTest {
char[] expectedString = "abcddeeeffff".toCharArray();
Arrays.sort(expectedString);
- Assert.assertArrayEquals(expectedString, foundString);
- Assert.assertEquals(78, res.f1.getValue());
+ assertThat(foundString).isEqualTo(expectedString);
+ assertThat(res.f1.getValue()).isEqualTo(78);
}
{
TestTaskContext<
@@ -247,20 +249,20 @@ public class AllReduceDriverTest {
char[] expectedString = "abcddeeeffff".toCharArray();
Arrays.sort(expectedString);
- Assert.assertArrayEquals(expectedString, foundString);
- Assert.assertEquals(78, res.f1.getValue());
+ assertThat(foundString).isEqualTo(expectedString);
+ assertThat(res.f1.getValue()).isEqualTo(78);
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
// --------------------------------------------------------------------------------------------
// Test UDFs
// --------------------------------------------------------------------------------------------
- public static final class ConcatSumFirstReducer
+ private static final class ConcatSumFirstReducer
extends RichReduceFunction<Tuple2<String, Integer>> {
@Override
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/DriverTestData.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/DriverTestData.java
index 0d8968d699d..4ec11599704 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/DriverTestData.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/DriverTestData.java
@@ -23,11 +23,11 @@ import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.StringValue;
-import org.junit.Assert;
-
import java.util.ArrayList;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class DriverTestData {
public static List<Tuple2<String, Integer>> createReduceImmutableData() {
@@ -99,9 +99,7 @@ public class DriverTestData {
// --------------------------------------------------------------------------------------------
public static final void compareTupleArrays(Object[] expected, Object[] found) {
- if (expected.length != found.length) {
- Assert.assertEquals("Length of result is wrong", expected.length, found.length);
- }
+ assertThat(found).withFailMessage("Length of result is wrong").hasSameSizeAs(expected);
for (int i = 0; i < expected.length; i++) {
Tuple v1 = (Tuple) expected[i];
@@ -110,7 +108,7 @@ public class DriverTestData {
for (int k = 0; k < v1.getArity(); k++) {
Object o1 = v1.getField(k);
Object o2 = v2.getField(k);
- Assert.assertEquals(o1, o2);
+ assertThat(o2).isEqualTo(o1);
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/GroupReduceDriverTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/GroupReduceDriverTest.java
index d96cfa42d7d..7da3fd6c8c1 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/GroupReduceDriverTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/GroupReduceDriverTest.java
@@ -34,17 +34,19 @@ import org.apache.flink.types.StringValue;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
@SuppressWarnings("serial")
-public class GroupReduceDriverTest {
+class GroupReduceDriverTest {
@Test
- public void testAllReduceDriverImmutableEmpty() {
+ void testAllReduceDriverImmutableEmpty() {
try {
TestTaskContext<
GroupReduceFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>,
@@ -79,16 +81,16 @@ public class GroupReduceDriverTest {
driver.prepare();
driver.run();
- Assert.assertTrue(result.getList().isEmpty());
+ assertThat(result.getList()).isEmpty();
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverImmutable() {
+ void testAllReduceDriverImmutable() {
try {
TestTaskContext<
GroupReduceFunction<Tuple2<String, Integer>, Tuple2<String, Integer>>,
@@ -133,12 +135,12 @@ public class GroupReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverMutable() {
+ void testAllReduceDriverMutable() {
try {
TestTaskContext<
GroupReduceFunction<
@@ -186,12 +188,12 @@ public class GroupReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverIncorrectlyAccumulatingMutable() {
+ void testAllReduceDriverIncorrectlyAccumulatingMutable() {
try {
TestTaskContext<
GroupReduceFunction<
@@ -237,20 +239,19 @@ public class GroupReduceDriverTest {
try {
DriverTestData.compareTupleArrays(expected, res);
- Assert.fail(
- "Accumulationg mutable objects is expected to result in incorrect values.");
+ fail("Accumulationg mutable objects is expected to result in incorrect values.");
} catch (AssertionError e) {
// expected
}
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testAllReduceDriverAccumulatingImmutable() {
+ void testAllReduceDriverAccumulatingImmutable() {
try {
TestTaskContext<
GroupReduceFunction<
@@ -299,7 +300,7 @@ public class GroupReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceCombineDriverTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceCombineDriverTest.java
index 00b6ac11b02..b65b73e22e4 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceCombineDriverTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceCombineDriverTest.java
@@ -33,17 +33,19 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.StringValue;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
@SuppressWarnings("serial")
public class ReduceCombineDriverTest {
@Test
- public void testImmutableEmpty() {
+ void testImmutableEmpty() {
try {
TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>
context =
@@ -79,16 +81,16 @@ public class ReduceCombineDriverTest {
driver.prepare();
driver.run();
- Assert.assertEquals(0, result.getList().size());
+ assertThat(result.getList()).isEmpty();
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testReduceDriverImmutable() {
+ void testReduceDriverImmutable() {
try {
{
TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>
@@ -180,12 +182,12 @@ public class ReduceCombineDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testReduceDriverMutable() {
+ void testReduceDriverMutable() {
try {
{
TestTaskContext<
@@ -274,7 +276,7 @@ public class ReduceCombineDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceDriverTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceDriverTest.java
index 0968fe08ed5..f6abb4e3ad0 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceDriverTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/drivers/ReduceDriverTest.java
@@ -33,16 +33,18 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.StringValue;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
@SuppressWarnings("serial")
-public class ReduceDriverTest {
+class ReduceDriverTest {
@Test
- public void testReduceDriverImmutableEmpty() {
+ void testReduceDriverImmutableEmpty() {
try {
TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>
context =
@@ -74,16 +76,16 @@ public class ReduceDriverTest {
driver.prepare();
driver.run();
- Assert.assertEquals(0, result.getList().size());
+ assertThat(result.getList()).isEmpty();
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testReduceDriverImmutable() {
+ void testReduceDriverImmutable() {
try {
{
TestTaskContext<ReduceFunction<Tuple2<String, Integer>>, Tuple2<String, Integer>>
@@ -169,12 +171,12 @@ public class ReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
@Test
- public void testReduceDriverMutable() {
+ void testReduceDriverMutable() {
try {
{
TestTaskContext<
@@ -261,7 +263,7 @@ public class ReduceDriverTest {
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
- Assert.fail(e.getMessage());
+ fail(e.getMessage());
}
}
// --------------------------------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/CompactingHashTableTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/CompactingHashTableTest.java
index b7d29e61d9e..61846a8afe6 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/CompactingHashTableTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/CompactingHashTableTest.java
@@ -30,16 +30,17 @@ import org.apache.flink.runtime.operators.testutils.types.IntList;
import org.apache.flink.runtime.operators.testutils.types.IntPair;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Random;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class CompactingHashTableTest extends MutableHashTableTestBase {
+class CompactingHashTableTest extends MutableHashTableTestBase {
private final TypeComparator<Long> probeComparator;
@@ -91,7 +92,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
* of the different constructor calls.
*/
@Test
- public void testHashTableGrowthWithInsert() {
+ void testHashTableGrowthWithInsert() {
try {
final int numElements = 1000000;
@@ -117,14 +118,13 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
MutableObjectIterator<Tuple2<Long, String>> iter = table.getEntryIterator();
Tuple2<Long, String> next;
while ((next = iter.next()) != null) {
- assertNotNull(next.f0);
- assertNotNull(next.f1);
- assertEquals(next.f0.longValue(), Long.parseLong(next.f1));
+ assertThat(next.f1).isNotNull();
+ assertThat(next.f0).isNotNull().isEqualTo(Long.parseLong(next.f1));
bitSet.set(next.f0.intValue());
}
- assertEquals(numElements, bitSet.cardinality());
+ assertThat(bitSet.cardinality()).isEqualTo(numElements);
}
// make sure all entries are contained via the prober
@@ -133,8 +133,8 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
table.getProber(probeComparator, pairComparator);
for (long i = 0; i < numElements; i++) {
- assertNotNull(proper.getMatchFor(i));
- assertNull(proper.getMatchFor(i + numElements));
+ assertThat(proper.getMatchFor(i)).isNotNull();
+ assertThat(proper.getMatchFor(i + numElements)).isNull();
}
}
} catch (Exception e) {
@@ -150,7 +150,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
* because of the different constructor calls.
*/
@Test
- public void testHashTableGrowthWithInsertOrReplace() {
+ void testHashTableGrowthWithInsertOrReplace() {
try {
final int numElements = 1000000;
@@ -176,14 +176,13 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
MutableObjectIterator<Tuple2<Long, String>> iter = table.getEntryIterator();
Tuple2<Long, String> next;
while ((next = iter.next()) != null) {
- assertNotNull(next.f0);
- assertNotNull(next.f1);
- assertEquals(next.f0.longValue(), Long.parseLong(next.f1));
+ assertThat(next.f1).isNotNull();
+ assertThat(next.f0).isNotNull().isEqualTo(Long.parseLong(next.f1));
bitSet.set(next.f0.intValue());
}
- assertEquals(numElements, bitSet.cardinality());
+ assertThat(bitSet.cardinality()).isEqualTo(numElements);
}
// make sure all entries are contained via the prober
@@ -192,8 +191,8 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
table.getProber(probeComparator, pairComparator);
for (long i = 0; i < numElements; i++) {
- assertNotNull(proper.getMatchFor(i));
- assertNull(proper.getMatchFor(i + numElements));
+ assertThat(proper.getMatchFor(i)).isNotNull();
+ assertThat(proper.getMatchFor(i + numElements)).isNull();
}
}
@@ -208,7 +207,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
* react to out of memory conditions.
*/
@Test
- public void testInsertsWithInsertOrReplace() {
+ void testInsertsWithInsertOrReplace() {
try {
final int numElements = 1000;
@@ -249,8 +248,9 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
new SameTypePairComparator<>(tuple2LongStringComparator));
Tuple2<Long, String> reuse = new Tuple2<>();
for (long i = 0; i < numElements; i++) {
- assertNotNull(prober.getMatchFor(Tuple2.of(i, longString), reuse));
- assertNotNull(prober.getMatchFor(Tuple2.of(i + numElements, longString), reuse));
+ assertThat(prober.getMatchFor(Tuple2.of(i, longString), reuse)).isNotNull();
+ assertThat(prober.getMatchFor(Tuple2.of(i + numElements, longString), reuse))
+ .isNotNull();
}
} catch (Exception e) {
e.printStackTrace();
@@ -259,7 +259,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testResize() {
+ void testResize() {
// Only CompactingHashTable
try {
final int NUM_MEM_PAGES = 30 * NUM_PAIRS / PAGE_SIZE;
@@ -281,25 +281,24 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
IntPair target = new IntPair();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(ADDITIONAL_MEM));
Boolean b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(
- pairs[i].getKey() + " " + pairs[i].getValue(),
- prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals(
- "Memory lost", NUM_MEM_PAGES + ADDITIONAL_MEM, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory())
+ .withFailMessage("Memory lost")
+ .hasSize(NUM_MEM_PAGES + ADDITIONAL_MEM);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
@@ -307,7 +306,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testDoubleResize() {
+ void testDoubleResize() {
// Only CompactingHashTable
try {
final int NUM_MEM_PAGES = 30 * NUM_PAIRS / PAGE_SIZE;
@@ -329,39 +328,34 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
IntPair target = new IntPair();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(ADDITIONAL_MEM));
Boolean b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(
- pairs[i].getKey() + " " + pairs[i].getValue(),
- prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(ADDITIONAL_MEM));
b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(
- pairs[i].getKey() + " " + pairs[i].getValue(),
- prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals(
- "Memory lost",
- NUM_MEM_PAGES + ADDITIONAL_MEM + ADDITIONAL_MEM,
- table.getFreeMemory().size());
+ assertThat(table.getFreeMemory())
+ .withFailMessage("Memory lost")
+ .hasSize(NUM_MEM_PAGES + ADDITIONAL_MEM + ADDITIONAL_MEM);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
@@ -369,7 +363,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testTripleResize() {
+ void testTripleResize() {
// Only CompactingHashTable
try {
final int NUM_MEM_PAGES = 30 * NUM_PAIRS / PAGE_SIZE;
@@ -391,51 +385,44 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
IntPair target = new IntPair();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(ADDITIONAL_MEM));
Boolean b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(
- pairs[i].getKey() + " " + pairs[i].getValue(),
- prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(ADDITIONAL_MEM));
b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(
- pairs[i].getKey() + " " + pairs[i].getValue(),
- prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(2 * ADDITIONAL_MEM));
b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(
- pairs[i].getKey() + " " + pairs[i].getValue(),
- prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(pairs[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals(
- "Memory lost",
- NUM_MEM_PAGES + 4 * ADDITIONAL_MEM,
- table.getFreeMemory().size());
+ assertThat(table.getFreeMemory())
+ .withFailMessage("Memory lost")
+ .hasSize(NUM_MEM_PAGES + 4 * ADDITIONAL_MEM);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
@@ -443,7 +430,7 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testResizeWithCompaction() {
+ void testResizeWithCompaction() {
// Only CompactingHashTable
try {
final int NUM_MEM_PAGES = (SIZE * NUM_LISTS / PAGE_SIZE);
@@ -465,18 +452,18 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
// make sure there is enough memory for resize
memory.addAll(getMemory(ADDITIONAL_MEM));
Boolean b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
final IntList[] overwriteLists = getRandomizedIntLists(NUM_LISTS, rnd);
@@ -491,18 +478,17 @@ public class CompactingHashTableTest extends MutableHashTableTestBase {
// make sure there is enough memory for resize
memory.addAll(getMemory(2 * ADDITIONAL_MEM));
b = table.resizeHashTable();
- assertTrue(b);
+ assertThat(b).isTrue();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull("" + i, prober.getMatchFor(overwriteLists[i], target));
- assertArrayEquals(overwriteLists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(overwriteLists[i], target)).isNotNull();
+ assertThat(overwriteLists[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals(
- "Memory lost",
- NUM_MEM_PAGES + 3 * ADDITIONAL_MEM,
- table.getFreeMemory().size());
+ assertThat(table.getFreeMemory())
+ .withFailMessage("Memory lost")
+ .hasSize(NUM_MEM_PAGES + 3 * ADDITIONAL_MEM);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
index 410d2214c7c..7392bd0aefa 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableITCase.java
@@ -43,12 +43,10 @@ import org.apache.flink.types.NullKeyFieldException;
import org.apache.flink.types.Record;
import org.apache.flink.types.Value;
import org.apache.flink.util.MutableObjectIterator;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Assert;
-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.IOException;
import java.util.ArrayList;
@@ -56,10 +54,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class HashTableITCase extends TestLogger {
+class HashTableITCase {
private static final AbstractInvokable MEM_OWNER = new DummyInvokable();
@@ -78,8 +76,8 @@ public class HashTableITCase extends TestLogger {
private TypeComparator<IntPair> pairProbeSideComparator;
private TypePairComparator<IntPair, IntPair> pairComparator;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
final int[] keyPos = new int[] {0};
@SuppressWarnings("unchecked")
final Class<? extends Value>[] keyType =
@@ -101,40 +99,41 @@ public class HashTableITCase extends TestLogger {
this.ioManager = new IOManagerAsync();
}
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
// shut down I/O manager and Memory Manager and verify the correct shutdown
this.ioManager.close();
- if (!this.memManager.verifyEmpty()) {
- fail("Not all memory was properly released to the memory manager --> Memory Leak.");
- }
+ assertThat(this.memManager.verifyEmpty())
+ .withFailMessage(
+ "Not all memory was properly released to the memory manager --> Memory Leak.")
+ .isTrue();
}
@Test
- public void testIOBufferCountComputation() {
- assertEquals(1, MutableHashTable.getNumWriteBehindBuffers(32));
- assertEquals(1, MutableHashTable.getNumWriteBehindBuffers(33));
- assertEquals(1, MutableHashTable.getNumWriteBehindBuffers(40));
- assertEquals(1, MutableHashTable.getNumWriteBehindBuffers(64));
- assertEquals(1, MutableHashTable.getNumWriteBehindBuffers(127));
- assertEquals(2, MutableHashTable.getNumWriteBehindBuffers(128));
- assertEquals(2, MutableHashTable.getNumWriteBehindBuffers(129));
- assertEquals(2, MutableHashTable.getNumWriteBehindBuffers(511));
- assertEquals(3, MutableHashTable.getNumWriteBehindBuffers(512));
- assertEquals(3, MutableHashTable.getNumWriteBehindBuffers(513));
- assertEquals(3, MutableHashTable.getNumWriteBehindBuffers(2047));
- assertEquals(4, MutableHashTable.getNumWriteBehindBuffers(2048));
- assertEquals(4, MutableHashTable.getNumWriteBehindBuffers(2049));
- assertEquals(4, MutableHashTable.getNumWriteBehindBuffers(8191));
- assertEquals(5, MutableHashTable.getNumWriteBehindBuffers(8192));
- assertEquals(5, MutableHashTable.getNumWriteBehindBuffers(8193));
- assertEquals(5, MutableHashTable.getNumWriteBehindBuffers(32767));
- assertEquals(6, MutableHashTable.getNumWriteBehindBuffers(32768));
- assertEquals(6, MutableHashTable.getNumWriteBehindBuffers(Integer.MAX_VALUE));
+ void testIOBufferCountComputation() {
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(32)).isOne();
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(33)).isOne();
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(40)).isOne();
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(64)).isOne();
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(127)).isOne();
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(128)).isEqualTo(2);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(129)).isEqualTo(2);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(511)).isEqualTo(2);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(512)).isEqualTo(3);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(513)).isEqualTo(3);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(2047)).isEqualTo(3);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(2048)).isEqualTo(4);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(2049)).isEqualTo(4);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(8191)).isEqualTo(4);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(8192)).isEqualTo(5);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(8193)).isEqualTo(5);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(32767)).isEqualTo(5);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(32768)).isEqualTo(6);
+ assertThat(MutableHashTable.getNumWriteBehindBuffers(Integer.MAX_VALUE)).isEqualTo(6);
}
@Test
- public void testInMemoryMutableHashTable() throws IOException {
+ void testInMemoryMutableHashTable() throws IOException {
final int NUM_KEYS = 100000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -178,10 +177,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .describedAs("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -191,7 +189,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinOneRecursionPerformance() throws IOException {
+ void testSpillingHashJoinOneRecursionPerformance() throws IOException {
final int NUM_KEYS = 1000000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -235,10 +233,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .describedAs("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -248,7 +245,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinOneRecursionValidity() throws IOException {
+ void testSpillingHashJoinOneRecursionValidity() throws IOException {
final int NUM_KEYS = 1000000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -310,10 +307,9 @@ public class HashTableITCase extends TestLogger {
}
Record pr = join.getCurrentProbeRecord();
- Assert.assertEquals(
- "Probe-side key was different than build-side key.",
- key,
- pr.getField(0, IntValue.class).getValue());
+ assertThat(pr.getField(0, IntValue.class).getValue())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
Long contained = map.get(key);
if (contained == null) {
@@ -327,15 +323,15 @@ public class HashTableITCase extends TestLogger {
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY);
}
// ----------------------------------------------------------------------------------------
@@ -344,7 +340,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinWithMassiveCollisions() throws IOException {
+ void testSpillingHashJoinWithMassiveCollisions() throws IOException {
// the following two values are known to have a hash-code collision on the initial level.
// we use them to make sure one partition grows over-proportionally large
final int REPEATED_VALUE_1 = 40559;
@@ -422,19 +418,17 @@ public class HashTableITCase extends TestLogger {
MutableObjectIterator<Record> buildSide = join.getBuildSideIterator();
if ((record = buildSide.next(recordReuse)) != null) {
numBuildValues = 1;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.",
- key,
- record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(0, IntValue.class).getValue())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
} else {
fail("No build side values found for a probe key.");
}
while ((record = buildSide.next(recordReuse)) != null) {
numBuildValues++;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.",
- key,
- record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(0, IntValue.class).getValue())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
}
Long contained = map.get(key);
@@ -449,18 +443,19 @@ public class HashTableITCase extends TestLogger {
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
- ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
- * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
- : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(
+ (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
+ ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
+ * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
+ : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY);
}
// ----------------------------------------------------------------------------------------
@@ -474,7 +469,7 @@ public class HashTableITCase extends TestLogger {
* fits into memory by itself and needs to be repartitioned in the recursion again.
*/
@Test
- public void testSpillingHashJoinWithTwoRecursions() throws IOException {
+ void testSpillingHashJoinWithTwoRecursions() throws IOException {
// the following two values are known to have a hash-code collision on the first recursion
// level.
// we use them to make sure one partition grows over-proportionally large
@@ -553,19 +548,17 @@ public class HashTableITCase extends TestLogger {
MutableObjectIterator<Record> buildSide = join.getBuildSideIterator();
if ((record = buildSide.next(recordReuse)) != null) {
numBuildValues = 1;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.",
- key,
- record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(0, IntValue.class).getValue())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
} else {
fail("No build side values found for a probe key.");
}
while ((record = buildSide.next(recordReuse)) != null) {
numBuildValues++;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.",
- key,
- record.getField(0, IntValue.class).getValue());
+ assertThat(record.getField(0, IntValue.class).getValue())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
}
Long contained = map.get(key);
@@ -580,18 +573,19 @@ public class HashTableITCase extends TestLogger {
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
- ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
- * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
- : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key " + key)
+ .isEqualTo(
+ (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
+ ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
+ * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
+ : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY);
}
// ----------------------------------------------------------------------------------------
@@ -605,7 +599,7 @@ public class HashTableITCase extends TestLogger {
* fits into memory by itself and needs to be repartitioned in the recursion again.
*/
@Test
- public void testFailingHashJoinTooManyRecursions() throws IOException {
+ void testFailingHashJoinTooManyRecursions() throws IOException {
// the following two values are known to have a hash-code collision on the first recursion
// level.
// we use them to make sure one partition grows over-proportionally large
@@ -694,7 +688,7 @@ public class HashTableITCase extends TestLogger {
* few probe records are used that some partitions remain empty.
*/
@Test
- public void testSparseProbeSpilling() throws IOException, MemoryAllocationException {
+ void testSparseProbeSpilling() throws IOException {
final int NUM_BUILD_KEYS = 1000000;
final int NUM_BUILD_VALS = 1;
final int NUM_PROBE_KEYS = 20;
@@ -735,10 +729,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- expectedNumResults,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(expectedNumResults);
join.close();
@@ -750,8 +743,7 @@ public class HashTableITCase extends TestLogger {
* that requires spilled build-side records to be returned and counted.
*/
@Test
- public void testSparseProbeSpillingWithOuterJoin()
- throws IOException, MemoryAllocationException {
+ void testSparseProbeSpillingWithOuterJoin() throws IOException {
final int NUM_BUILD_KEYS = 1000000;
final int NUM_BUILD_VALS = 1;
final int NUM_PROBE_KEYS = 20;
@@ -793,10 +785,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- expectedNumResults,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(expectedNumResults);
join.close();
@@ -808,7 +799,7 @@ public class HashTableITCase extends TestLogger {
* during an insert into the same.
*/
@Test
- public void validateSpillingDuringInsertion() throws IOException, MemoryAllocationException {
+ void validateSpillingDuringInsertion() throws IOException {
final int NUM_BUILD_KEYS = 500000;
final int NUM_BUILD_VALS = 1;
final int NUM_PROBE_KEYS = 10;
@@ -849,10 +840,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- expectedNumResults,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(expectedNumResults);
join.close();
@@ -864,7 +854,7 @@ public class HashTableITCase extends TestLogger {
// ============================================================================================
@Test
- public void testInMemoryMutableHashTableIntPair() throws IOException {
+ void testInMemoryMutableHashTableIntPair() throws IOException {
final int NUM_KEYS = 100000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -908,10 +898,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -921,7 +910,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinOneRecursionPerformanceIntPair() throws IOException {
+ void testSpillingHashJoinOneRecursionPerformanceIntPair() throws IOException {
final int NUM_KEYS = 1000000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -965,10 +954,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -978,7 +966,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinOneRecursionValidityIntPair() throws IOException {
+ void testSpillingHashJoinOneRecursionValidityIntPair() throws IOException {
final int NUM_KEYS = 1000000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -1040,8 +1028,9 @@ public class HashTableITCase extends TestLogger {
}
IntPair pr = join.getCurrentProbeRecord();
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, pr.getKey());
+ assertThat(pr.getKey())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
Long contained = map.get(key);
if (contained == null) {
@@ -1055,15 +1044,15 @@ public class HashTableITCase extends TestLogger {
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY);
}
// ----------------------------------------------------------------------------------------
@@ -1072,7 +1061,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinWithMassiveCollisionsIntPair() throws IOException {
+ void testSpillingHashJoinWithMassiveCollisionsIntPair() throws IOException {
// the following two values are known to have a hash-code collision on the initial level.
// we use them to make sure one partition grows over-proportionally large
final int REPEATED_VALUE_1 = 40559;
@@ -1150,15 +1139,17 @@ public class HashTableITCase extends TestLogger {
MutableObjectIterator<IntPair> buildSide = join.getBuildSideIterator();
if ((record = buildSide.next(recordReuse)) != null) {
numBuildValues = 1;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, record.getKey());
+ assertThat(record.getKey())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
} else {
fail("No build side values found for a probe key.");
}
while ((record = buildSide.next(recordReuse)) != null) {
numBuildValues++;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, record.getKey());
+ assertThat(record.getKey())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
}
Long contained = map.get(key);
@@ -1173,18 +1164,19 @@ public class HashTableITCase extends TestLogger {
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
- ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
- * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
- : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(
+ (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
+ ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
+ * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
+ : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY);
}
// ----------------------------------------------------------------------------------------
@@ -1198,7 +1190,7 @@ public class HashTableITCase extends TestLogger {
* fits into memory by itself and needs to be repartitioned in the recursion again.
*/
@Test
- public void testSpillingHashJoinWithTwoRecursionsIntPair() throws IOException {
+ void testSpillingHashJoinWithTwoRecursionsIntPair() throws IOException {
// the following two values are known to have a hash-code collision on the first recursion
// level.
// we use them to make sure one partition grows over-proportionally large
@@ -1277,15 +1269,17 @@ public class HashTableITCase extends TestLogger {
MutableObjectIterator<IntPair> buildSide = join.getBuildSideIterator();
if ((record = buildSide.next(recordReuse)) != null) {
numBuildValues = 1;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, record.getKey());
+ assertThat(record.getKey())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
} else {
fail("No build side values found for a probe key.");
}
while ((record = buildSide.next(recordReuse)) != null) {
numBuildValues++;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, record.getKey());
+ assertThat(record.getKey())
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
}
Long contained = map.get(key);
@@ -1300,18 +1294,19 @@ public class HashTableITCase extends TestLogger {
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
- ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
- * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
- : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(
+ (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2)
+ ? (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
+ * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
+ : PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY);
}
// ----------------------------------------------------------------------------------------
@@ -1325,7 +1320,7 @@ public class HashTableITCase extends TestLogger {
* fits into memory by itself and needs to be repartitioned in the recursion again.
*/
@Test
- public void testFailingHashJoinTooManyRecursionsIntPair() throws IOException {
+ void testFailingHashJoinTooManyRecursionsIntPair() throws IOException {
// the following two values are known to have a hash-code collision on the first recursion
// level.
// we use them to make sure one partition grows over-proportionally large
@@ -1416,7 +1411,7 @@ public class HashTableITCase extends TestLogger {
* few probe records are used that some partitions remain empty.
*/
@Test
- public void testSparseProbeSpillingIntPair() throws IOException, MemoryAllocationException {
+ void testSparseProbeSpillingIntPair() throws IOException {
final int NUM_BUILD_KEYS = 1000000;
final int NUM_BUILD_VALS = 1;
final int NUM_PROBE_KEYS = 20;
@@ -1457,10 +1452,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- expectedNumResults,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(expectedNumResults);
join.close();
@@ -1472,8 +1466,7 @@ public class HashTableITCase extends TestLogger {
* during an insert into the same.
*/
@Test
- public void validateSpillingDuringInsertionIntPair()
- throws IOException, MemoryAllocationException {
+ void validateSpillingDuringInsertionIntPair() throws IOException {
final int NUM_BUILD_KEYS = 500000;
final int NUM_BUILD_VALS = 1;
final int NUM_PROBE_KEYS = 10;
@@ -1514,10 +1507,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- expectedNumResults,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(expectedNumResults);
join.close();
@@ -1525,7 +1517,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testInMemoryReOpen() throws IOException {
+ void testInMemoryReOpen() throws IOException {
final int NUM_KEYS = 100000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -1569,10 +1561,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -1595,10 +1586,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -1612,7 +1602,7 @@ public class HashTableITCase extends TestLogger {
* validates a bug fix MutableHashTable memory leakage with small memory segments.
*/
@Test
- public void testInMemoryReOpenWithSmallMemory() throws Exception {
+ void testInMemoryReOpenWithSmallMemory() throws Exception {
final int NUM_KEYS = 10000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -1657,10 +1647,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -1683,10 +1672,9 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
@@ -1696,7 +1684,7 @@ public class HashTableITCase extends TestLogger {
}
@Test
- public void testBucketsNotFulfillSegment() throws Exception {
+ void testBucketsNotFulfillSegment() throws Exception {
final int NUM_KEYS = 10000;
final int BUILD_VALS_PER_KEY = 3;
final int PROBE_VALS_PER_KEY = 10;
@@ -1757,17 +1745,16 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
this.memManager.release(join.getFreedMemory());
}
@Test
- public void testHashWithBuildSideOuterJoin1() throws Exception {
+ void testHashWithBuildSideOuterJoin1() throws Exception {
final int NUM_KEYS = 20000;
final int BUILD_VALS_PER_KEY = 1;
final int PROBE_VALS_PER_KEY = 1;
@@ -1812,17 +1799,16 @@ public class HashTableITCase extends TestLogger {
numRecordsInJoinResult++;
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- 2 * NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(2 * NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
this.memManager.release(join.getFreedMemory());
}
@Test
- public void testHashWithBuildSideOuterJoin2() throws Exception {
+ void testHashWithBuildSideOuterJoin2() throws Exception {
final int NUM_KEYS = 40000;
final int BUILD_VALS_PER_KEY = 2;
final int PROBE_VALS_PER_KEY = 1;
@@ -1876,10 +1862,9 @@ public class HashTableITCase extends TestLogger {
next = buildSide.next(recordReuse);
}
}
- Assert.assertEquals(
- "Wrong number of records in join result.",
- NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY,
- numRecordsInJoinResult);
+ assertThat(numRecordsInJoinResult)
+ .withFailMessage("Wrong number of records in join result.")
+ .isEqualTo(NUM_KEYS * BUILD_VALS_PER_KEY * PROBE_VALS_PER_KEY);
join.close();
this.memManager.release(join.getFreedMemory());
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTablePerformanceComparison.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTablePerformanceComparison.java
index c3b9a78870e..67fe973ea3b 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTablePerformanceComparison.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTablePerformanceComparison.java
@@ -33,14 +33,15 @@ import org.apache.flink.runtime.operators.testutils.types.IntPairPairComparator;
import org.apache.flink.runtime.operators.testutils.types.IntPairSerializer;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class HashTablePerformanceComparison {
+class HashTablePerformanceComparison {
private static final int PAGE_SIZE = 16 * 1024;
@@ -55,7 +56,7 @@ public class HashTablePerformanceComparison {
private final TypePairComparator<IntPair, IntPair> pairComparator = new IntPairPairComparator();
@Test
- public void testCompactingHashMapPerformance() {
+ void testCompactingHashMapPerformance() {
try {
final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
@@ -98,8 +99,8 @@ public class HashTablePerformanceComparison {
table.getProber(comparator, pairComparator);
IntPair temp = new IntPair();
while (probeTester.next(target) != null) {
- assertNotNull(prober.getMatchFor(target, temp));
- assertEquals(temp.getValue(), target.getValue());
+ assertThat(prober.getMatchFor(target, temp)).isNotNull();
+ assertThat(target.getValue()).isEqualTo(temp.getValue());
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end - start) + " ms");
@@ -116,8 +117,8 @@ public class HashTablePerformanceComparison {
System.out.println("Starting second probing run...");
start = System.currentTimeMillis();
while (updateTester.next(target) != null) {
- assertNotNull(prober.getMatchFor(target, temp));
- assertEquals(target.getValue() + 1, temp.getValue());
+ assertThat(prober.getMatchFor(target, temp)).isNotNull();
+ assertThat(target.getValue() + 1).isEqualTo(temp.getValue());
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end - start) + " ms");
@@ -127,7 +128,7 @@ public class HashTablePerformanceComparison {
end = System.currentTimeMillis();
System.out.println("Overall time: " + (end - first) + " ms");
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
@@ -135,7 +136,7 @@ public class HashTablePerformanceComparison {
}
@Test
- public void testMutableHashMapPerformance() {
+ void testMutableHashMapPerformance() {
try (IOManager ioManager = new IOManagerAsync()) {
final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
@@ -181,9 +182,9 @@ public class HashTablePerformanceComparison {
while (probeTester.next(compare) != null) {
iter = table.getMatchesFor(compare);
iter.next(target);
- assertEquals(target.getKey(), compare.getKey());
- assertEquals(target.getValue(), compare.getValue());
- assertTrue(iter.next(target) == null);
+ assertThat(target.getKey()).isEqualTo(compare.getKey());
+ assertThat(target.getValue()).isEqualTo(compare.getValue());
+ assertThat(iter.next(target)).isNull();
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end - start) + " ms");
@@ -206,9 +207,9 @@ public class HashTablePerformanceComparison {
compare.setValue(compare.getValue() + 1);
iter = table.getMatchesFor(compare);
iter.next(target);
- assertEquals(target.getKey(), compare.getKey());
- assertEquals(target.getValue(), compare.getValue());
- assertTrue(iter.next(target) == null);
+ assertThat(target.getKey()).isEqualTo(compare.getKey());
+ assertThat(target.getValue()).isEqualTo(compare.getValue());
+ assertThat(iter.next(target)).isNull();
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end - start) + " ms");
@@ -218,7 +219,9 @@ public class HashTablePerformanceComparison {
end = System.currentTimeMillis();
System.out.println("Overall time: " + (end - first) + " ms");
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreedMemory().size());
+ assertThat(table.getFreedMemory())
+ .withFailMessage("Memory lost")
+ .hasSize(NUM_MEM_PAGES);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
@@ -226,7 +229,7 @@ public class HashTablePerformanceComparison {
}
@Test
- public void testInPlaceMutableHashTablePerformance() {
+ void testInPlaceMutableHashTablePerformance() {
try {
final int NUM_MEM_PAGES = SIZE * NUM_PAIRS / PAGE_SIZE;
@@ -268,8 +271,8 @@ public class HashTablePerformanceComparison {
table.getProber(comparator, pairComparator);
IntPair temp = new IntPair();
while (probeTester.next(target) != null) {
- assertNotNull(prober.getMatchFor(target, temp));
- assertEquals(temp.getValue(), target.getValue());
+ assertThat(prober.getMatchFor(target, temp)).isNotNull();
+ assertThat(temp.getValue()).isEqualTo(target.getValue());
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end - start) + " ms");
@@ -286,8 +289,8 @@ public class HashTablePerformanceComparison {
System.out.println("Starting second probing run...");
start = System.currentTimeMillis();
while (updateTester.next(target) != null) {
- assertNotNull(prober.getMatchFor(target, temp));
- assertEquals(target.getValue() + 1, temp.getValue());
+ assertThat(prober.getMatchFor(target, temp)).isNotNull();
+ assertThat(target.getValue() + 1).isEqualTo(temp.getValue());
}
end = System.currentTimeMillis();
System.out.println("Probing done. Time: " + (end - start) + " ms");
@@ -297,7 +300,7 @@ public class HashTablePerformanceComparison {
end = System.currentTimeMillis();
System.out.println("Overall time: " + (end - first) + " ms");
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
} catch (Exception e) {
e.printStackTrace();
fail("Error: " + e.getMessage());
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableTest.java
index e58005f6915..e2bb51626a5 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/HashTableTest.java
@@ -38,8 +38,7 @@ import org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync;
import org.apache.flink.types.ByteValue;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -47,9 +46,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
-public class HashTableTest {
+class HashTableTest {
private final TypeSerializer<Tuple2<Long, byte[]>> buildSerializer;
private final TypeSerializer<Long> probeSerializer;
@@ -59,7 +60,7 @@ public class HashTableTest {
private final TypePairComparator<Long, Tuple2<Long, byte[]>> pairComparator;
- public HashTableTest() {
+ HashTableTest() {
TypeSerializer<?>[] fieldSerializers = {
LongSerializer.INSTANCE, BytePrimitiveArraySerializer.INSTANCE
};
@@ -112,7 +113,7 @@ public class HashTableTest {
* missing and the computation deadlocked.
*/
@Test
- public void testBufferMissingForProbing() {
+ void testBufferMissingForProbing() {
try (final IOManager ioMan = new IOManagerAsync()) {
final int pageSize = 32 * 1024;
final int numSegments = 34;
@@ -137,20 +138,19 @@ public class HashTableTest {
table.open(new TupleBytesIterator(payload, numRecords), new LongIterator(10000));
- try {
- while (table.nextRecord()) {
- MutableObjectIterator<Tuple2<Long, byte[]>> matches =
- table.getBuildSideIterator();
- while (matches.next() != null) ;
- }
- } catch (RuntimeException e) {
- if (!e.getMessage().contains("exceeded maximum number of recursions")) {
- e.printStackTrace();
- fail("Test failed with unexpected exception");
- }
- } finally {
- table.close();
- }
+ assertThatThrownBy(
+ () -> {
+ while (table.nextRecord()) {
+ MutableObjectIterator<Tuple2<Long, byte[]>> matches =
+ table.getBuildSideIterator();
+ while (matches.next() != null) ;
+ }
+ })
+ .withFailMessage("Test failed with unexpected exception")
+ .hasMessageContaining("exceeded maximum number of recursions")
+ .isInstanceOf(RuntimeException.class);
+
+ table.close();
checkNoTempFilesRemain(ioMan);
} catch (Exception e) {
@@ -165,7 +165,7 @@ public class HashTableTest {
* partition to spill.
*/
@Test
- public void testSpillingFreesOnlyOverflowSegments() {
+ void testSpillingFreesOnlyOverflowSegments() {
final TypeSerializer<ByteValue> serializer = ByteValueSerializer.INSTANCE;
final TypeComparator<ByteValue> buildComparator =
new ValueComparator<>(true, ByteValue.class);
@@ -209,7 +209,7 @@ public class HashTableTest {
* overflow segments in the partitions. This means that the records are large.
*/
@Test
- public void testSpillingWhenBuildingTableWithoutOverflow() throws Exception {
+ void testSpillingWhenBuildingTableWithoutOverflow() throws Exception {
try (final IOManager ioMan = new IOManagerAsync()) {
final TypeSerializer<byte[]> serializer = BytePrimitiveArraySerializer.INSTANCE;
final TypeComparator<byte[]> buildComparator = new BytePrimitiveArrayComparator(true);
@@ -258,7 +258,7 @@ public class HashTableTest {
}
// check that we retrieve all our elements
- Assert.assertEquals(numElements, counter);
+ assertThat(counter).isEqualTo(numElements);
}
table.close();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/InPlaceMutableHashTableTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/InPlaceMutableHashTableTest.java
index 9249c32cc05..8d02910b498 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/InPlaceMutableHashTableTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/InPlaceMutableHashTableTest.java
@@ -44,7 +44,7 @@ import org.apache.flink.util.MutableObjectIterator;
import org.apache.flink.shaded.guava31.com.google.common.collect.Ordering;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.EOFException;
import java.util.ArrayList;
@@ -55,13 +55,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Random;
-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.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
-public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
+class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
private static final long RANDOM_SEED = 58723953465322L;
@@ -130,7 +128,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
* of the different constructor calls.
*/
@Test
- public void testHashTableGrowthWithInsert() {
+ void testHashTableGrowthWithInsert() {
try {
final int numElements = 1000000;
@@ -151,14 +149,13 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
MutableObjectIterator<Tuple2<Long, String>> iter = table.getEntryIterator();
Tuple2<Long, String> next;
while ((next = iter.next()) != null) {
- assertNotNull(next.f0);
- assertNotNull(next.f1);
- assertEquals(next.f0.longValue(), Long.parseLong(next.f1));
+ assertThat(next.f1).isNotNull();
+ assertThat(next.f0).isNotNull().isEqualTo(Long.parseLong(next.f1));
bitSet.set(next.f0.intValue());
}
- assertEquals(numElements, bitSet.cardinality());
+ assertThat(bitSet.cardinality()).isEqualTo(numElements);
}
// make sure all entries are contained via the prober
@@ -169,8 +166,8 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
Tuple2<Long, String> reuse = new Tuple2<>();
for (long i = 0; i < numElements; i++) {
- assertNotNull(proper.getMatchFor(i, reuse));
- assertNull(proper.getMatchFor(i + numElements, reuse));
+ assertThat(proper.getMatchFor(i, reuse)).isNotNull();
+ assertThat(proper.getMatchFor(i + numElements, reuse)).isNull();
}
}
@@ -188,7 +185,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
* because of the different constructor calls.
*/
@Test
- public void testHashTableGrowthWithInsertOrReplace() {
+ void testHashTableGrowthWithInsertOrReplace() {
try {
final int numElements = 1000000;
@@ -209,14 +206,13 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
MutableObjectIterator<Tuple2<Long, String>> iter = table.getEntryIterator();
Tuple2<Long, String> next;
while ((next = iter.next()) != null) {
- assertNotNull(next.f0);
- assertNotNull(next.f1);
- assertEquals(next.f0.longValue(), Long.parseLong(next.f1));
+ assertThat(next.f1).isNotNull();
+ assertThat(next.f0).isNotNull().isEqualTo(Long.parseLong(next.f1));
bitSet.set(next.f0.intValue());
}
- assertEquals(numElements, bitSet.cardinality());
+ assertThat(bitSet.cardinality()).isEqualTo(numElements);
}
// make sure all entries are contained via the prober
@@ -227,8 +223,8 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
Tuple2<Long, String> reuse = new Tuple2<>();
for (long i = 0; i < numElements; i++) {
- assertNotNull(proper.getMatchFor(i, reuse));
- assertNull(proper.getMatchFor(i + numElements, reuse));
+ assertThat(proper.getMatchFor(i, reuse)).isNotNull();
+ assertThat(proper.getMatchFor(i + numElements, reuse)).isNull();
}
}
@@ -286,7 +282,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testWithIntPair() throws Exception {
+ void testWithIntPair() throws Exception {
Random rnd = new Random(RANDOM_SEED);
// varying the keyRange between 1000 and 1000000 can make a 5x speed difference
@@ -352,7 +348,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
// Check results
- assertEquals(expectedOutput.size(), actualOutput.size());
+ assertThat(actualOutput).hasSameSizeAs(expectedOutput);
Integer[] expectedValues = new Integer[expectedOutput.size()];
for (int i = 0; i < expectedOutput.size(); i++) {
@@ -365,7 +361,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
Arrays.sort(expectedValues, Ordering.<Integer>natural());
Arrays.sort(actualValues, Ordering.<Integer>natural());
- assertArrayEquals(expectedValues, actualValues);
+ assertThat(actualValues).isEqualTo(expectedValues);
}
class SumReducer implements ReduceFunction<IntPair> {
@@ -381,7 +377,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testWithLengthChangingReduceFunction() throws Exception {
+ void testWithLengthChangingReduceFunction() throws Exception {
Random rnd = new Random(RANDOM_SEED);
final int numKeys = 10000;
@@ -466,7 +462,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
// Check results
- assertEquals(expectedOutput.size(), actualOutput.size());
+ assertThat(actualOutput).hasSameSizeAs(expectedOutput);
String[] expectedValues = new String[expectedOutput.size()];
for (int i = 0; i < expectedOutput.size(); i++) {
@@ -479,7 +475,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
Arrays.sort(expectedValues, Ordering.<String>natural());
Arrays.sort(actualValues, Ordering.<String>natural());
- assertArrayEquals(expectedValues, actualValues);
+ assertThat(actualValues).isEqualTo(expectedValues);
expectedOutput.clear();
actualOutput.clear();
@@ -515,7 +511,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
* lots of compactions will happen.
*/
@Test
- public void testLargeRecordsWithManyCompactions() {
+ void testLargeRecordsWithManyCompactions() {
try {
final int numElements = 1000;
@@ -541,7 +537,7 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
prober = table.getProber(comparator, new SameTypePairComparator<>(comparator));
Tuple2<Long, String> reuse = new Tuple2<>();
for (long i = 0; i < numElements; i++) {
- assertNotNull(prober.getMatchFor(Tuple2.of(i, longString2), reuse));
+ assertThat(prober.getMatchFor(Tuple2.of(i, longString1), reuse)).isNotNull();
}
table.close();
@@ -560,31 +556,25 @@ public class InPlaceMutableHashTableTest extends MutableHashTableTestBase {
}
@Test
- public void testOutOfMemory() {
- try {
- List<MemorySegment> memory = getMemory(100, 1024);
+ void testOutOfMemory() {
+ List<MemorySegment> memory = getMemory(100, 1024);
- InPlaceMutableHashTable<Tuple2<Long, String>> table =
- new InPlaceMutableHashTable<>(serializer, comparator, memory);
+ InPlaceMutableHashTable<Tuple2<Long, String>> table =
+ new InPlaceMutableHashTable<>(serializer, comparator, memory);
- try {
- final int numElements = 100000;
+ final int numElements = 100000;
- table.open();
+ table.open();
- // Insert too many elements
- for (long i = 0; i < numElements; i++) {
- table.insertOrReplaceRecord(Tuple2.of(i, "alma"));
- }
+ // Insert too many elements
+ assertThatThrownBy(
+ () -> {
+ for (long i = 0; i < numElements; i++) {
+ table.insertOrReplaceRecord(Tuple2.of(i, "alma"));
+ }
+ })
+ .isInstanceOf(EOFException.class);
- fail("We should have got out of memory (EOFException)");
- } catch (EOFException e) {
- // OK
- table.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ table.close();
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/MutableHashTableTestBase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/MutableHashTableTestBase.java
index cf3b8c4692f..7ca38fa2803 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/MutableHashTableTestBase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/MutableHashTableTestBase.java
@@ -45,16 +45,16 @@ import org.apache.flink.runtime.operators.testutils.types.StringPairPairComparat
import org.apache.flink.runtime.operators.testutils.types.StringPairSerializer;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
-public abstract class MutableHashTableTestBase {
+abstract class MutableHashTableTestBase {
protected static final long RANDOM_SEED = 76518743207143L;
@@ -112,7 +112,7 @@ public abstract class MutableHashTableTestBase {
TypeSerializer<T> serializer, TypeComparator<T> comparator, List<MemorySegment> memory);
@Test
- public void testDifferentProbers() {
+ void testDifferentProbers() {
final int NUM_MEM_PAGES = 32 * NUM_PAIRS / PAGE_SIZE;
AbstractMutableHashTable<IntPair> table =
getHashTable(intPairSerializer, intPairComparator, getMemory(NUM_MEM_PAGES));
@@ -122,14 +122,14 @@ public abstract class MutableHashTableTestBase {
AbstractHashTableProber<IntPair, IntPair> prober2 =
table.getProber(intPairComparator, pairComparator);
- assertFalse(prober1 == prober2);
+ assertThat(prober1).isNotEqualTo(prober2);
table.close(); // (This also tests calling close without calling open first.)
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testBuildAndRetrieve() throws Exception {
+ void testBuildAndRetrieve() throws Exception {
final int NUM_MEM_PAGES = 32 * NUM_PAIRS / PAGE_SIZE;
AbstractMutableHashTable<IntPair> table =
getHashTable(intPairSerializer, intPairComparator, getMemory(NUM_MEM_PAGES));
@@ -148,16 +148,16 @@ public abstract class MutableHashTableTestBase {
IntPair target = new IntPair();
for (int i = 0; i < NUM_PAIRS; i++) {
- assertNotNull(prober.getMatchFor(pairs[i], target));
- assertEquals(pairs[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(target.getValue()).isEqualTo((pairs[i].getValue()));
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testEntryIterator() throws Exception {
+ void testEntryIterator() throws Exception {
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
getHashTable(serializerV, comparatorV, getMemory(NUM_MEM_PAGES));
@@ -181,12 +181,12 @@ public abstract class MutableHashTableTestBase {
}
table.close();
- assertTrue(sum == result);
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(sum).isEqualTo(result);
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testMultipleProbers() throws Exception {
+ void testMultipleProbers() throws Exception {
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
getHashTable(serializerV, comparatorV, getMemory(NUM_MEM_PAGES));
@@ -208,16 +208,16 @@ public abstract class MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(pairProber.getMatchFor(pairs[i], target));
- assertNotNull(listProber.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(pairProber.getMatchFor(pairs[i], target)).isNotNull();
+ assertThat(listProber.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testVariableLengthBuildAndRetrieve() throws Exception {
+ void testVariableLengthBuildAndRetrieve() throws Exception {
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
getHashTable(serializerV, comparatorV, getMemory(NUM_MEM_PAGES));
@@ -240,8 +240,8 @@ public abstract class MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
final IntList[] overwriteLists = getRandomizedIntLists(NUM_LISTS, rnd);
@@ -252,16 +252,16 @@ public abstract class MutableHashTableTestBase {
}
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull("" + i, prober.getMatchFor(overwriteLists[i], target));
- assertArrayEquals(overwriteLists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(overwriteLists[i], target)).isNotNull();
+ assertThat(overwriteLists[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testVariableLengthBuildAndRetrieveMajorityUpdated() throws Exception {
+ void testVariableLengthBuildAndRetrieveMajorityUpdated() throws Exception {
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
getHashTable(serializerV, comparatorV, getMemory(NUM_MEM_PAGES));
@@ -280,8 +280,8 @@ public abstract class MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
final IntList[] overwriteLists = getRandomizedIntLists(NUM_LISTS, rnd);
@@ -295,16 +295,16 @@ public abstract class MutableHashTableTestBase {
}
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull("" + i, prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testVariableLengthBuildAndRetrieveMinorityUpdated() throws Exception {
+ void testVariableLengthBuildAndRetrieveMinorityUpdated() throws Exception {
final int NUM_LISTS = 20000;
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
@@ -326,8 +326,8 @@ public abstract class MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
final IntList[] overwriteLists = getRandomizedIntLists(NUM_LISTS / STEP_SIZE, rnd);
@@ -341,16 +341,16 @@ public abstract class MutableHashTableTestBase {
}
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testRepeatedBuildAndRetrieve() throws Exception {
+ void testRepeatedBuildAndRetrieve() throws Exception {
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
getHashTable(serializerV, comparatorV, getMemory(NUM_MEM_PAGES));
@@ -373,8 +373,8 @@ public abstract class MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull(prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
}
IntList[] overwriteLists;
@@ -387,17 +387,17 @@ public abstract class MutableHashTableTestBase {
}
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull("" + i, prober.getMatchFor(overwriteLists[i], target));
- assertArrayEquals(overwriteLists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(overwriteLists[i], target)).isNotNull();
+ assertThat(overwriteLists[i].getValue()).isEqualTo(target.getValue());
}
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testProberUpdate() throws Exception {
+ void testProberUpdate() throws Exception {
final int NUM_MEM_PAGES = SIZE * NUM_LISTS / PAGE_SIZE;
AbstractMutableHashTable<IntList> table =
getHashTable(serializerV, comparatorV, getMemory(NUM_MEM_PAGES));
@@ -418,22 +418,22 @@ public abstract class MutableHashTableTestBase {
IntList target = new IntList();
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull("" + i, prober.getMatchFor(lists[i], target));
- assertArrayEquals(lists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(lists[i], target)).isNotNull();
+ assertThat(lists[i].getValue()).isEqualTo(target.getValue());
prober.updateMatch(overwriteLists[i]);
}
for (int i = 0; i < NUM_LISTS; i++) {
- assertNotNull("" + i, prober.getMatchFor(overwriteLists[i], target));
- assertArrayEquals(overwriteLists[i].getValue(), target.getValue());
+ assertThat(prober.getMatchFor(overwriteLists[i], target)).isNotNull();
+ assertThat(overwriteLists[i].getValue()).isEqualTo(target.getValue());
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
@Test
- public void testVariableLengthStringBuildAndRetrieve() throws IOException {
+ void testVariableLengthStringBuildAndRetrieve() throws IOException {
final int NUM_MEM_PAGES = 40 * NUM_PAIRS / PAGE_SIZE;
AbstractMutableHashTable<StringPair> table =
getHashTable(serializerS, comparatorS, getMemory(NUM_MEM_PAGES));
@@ -461,8 +461,8 @@ public abstract class MutableHashTableTestBase {
table.getProber(comparatorS, pairComparatorS);
StringPair temp = new StringPair();
while (probeTester.next(target) != null) {
- assertNotNull("" + target.getKey(), prober.getMatchFor(target, temp));
- assertEquals(temp.getValue(), target.getValue());
+ assertThat(prober.getMatchFor(target, temp)).isNotNull();
+ assertThat(target.getValue()).isEqualTo(temp.getValue());
}
while (updater.next(target) != null) {
@@ -471,12 +471,12 @@ public abstract class MutableHashTableTestBase {
}
while (updateTester.next(target) != null) {
- assertNotNull(prober.getMatchFor(target, temp));
- assertEquals(target.getValue(), temp.getValue());
+ assertThat(prober.getMatchFor(target, temp)).isNotNull();
+ assertThat(target.getValue()).isEqualTo(temp.getValue());
}
table.close();
- assertEquals("Memory lost", NUM_MEM_PAGES, table.getFreeMemory().size());
+ assertThat(table.getFreeMemory()).withFailMessage("Memory lost").hasSize(NUM_MEM_PAGES);
}
protected static IntPair[] getRandomizedIntPairs(int num, Random rnd) {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingHashJoinIteratorITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingHashJoinIteratorITCase.java
index 65dcc30f973..1932de32695 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingHashJoinIteratorITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingHashJoinIteratorITCase.java
@@ -42,12 +42,10 @@ import org.apache.flink.runtime.operators.testutils.types.IntPairSerializer;
import org.apache.flink.types.NullKeyFieldException;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
import java.util.Collection;
@@ -56,13 +54,16 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
@SuppressWarnings({
"serial",
"EqualsWhichDoesntCheckParameterClass",
"StatementWithEmptyBody",
"KeySetIterationMayUseEntrySet"
})
-public class NonReusingHashJoinIteratorITCase extends TestLogger {
+class NonReusingHashJoinIteratorITCase {
private static final int MEMORY_SIZE = 16000000; // total memory
@@ -89,8 +90,8 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
private TypePairComparator<Tuple2<Integer, String>, IntPair> recordPairPairComparator;
@SuppressWarnings("unchecked")
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
this.recordSerializer = TestData.getIntStringTupleSerializer();
this.record1Comparator = TestData.getIntStringTupleComparator();
@@ -107,24 +108,25 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
this.ioManager = new IOManagerAsync();
}
- @After
- public void afterTest() throws Exception {
+ @AfterEach
+ void afterTest() throws Exception {
if (this.ioManager != null) {
this.ioManager.close();
this.ioManager = null;
}
if (this.memoryManager != null) {
- Assert.assertTrue(
- "Memory Leak: Not all memory has been returned to the memory manager.",
- this.memoryManager.verifyEmpty());
+ assertThat(this.memoryManager.verifyEmpty())
+ .withFailMessage(
+ "Memory Leak: not all segments have been returned to the memory manager.")
+ .isTrue();
this.memoryManager.shutdown();
this.memoryManager = null;
}
}
@Test
- public void testBuildFirst() {
+ void testBuildFirst() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 500, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -181,18 +183,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstWithHighNumberOfCommonKeys() {
+ void testBuildFirstWithHighNumberOfCommonKeys() {
// the size of the left and right inputs
final int INPUT_1_SIZE = 200;
final int INPUT_2_SIZE = 100;
@@ -287,18 +289,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecond() {
+ void testBuildSecond() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 500, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -353,18 +355,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondWithHighNumberOfCommonKeys() {
+ void testBuildSecondWithHighNumberOfCommonKeys() {
// the size of the left and right inputs
final int INPUT_1_SIZE = 200;
final int INPUT_2_SIZE = 100;
@@ -459,18 +461,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstWithMixedDataTypes() {
+ void testBuildFirstWithMixedDataTypes() {
try {
MutableObjectIterator<IntPair> input1 = new UniformIntPairGenerator(500, 40, false);
@@ -521,18 +523,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleIntPairMatch>> entry :
expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondWithMixedDataTypes() {
+ void testBuildSecondWithMixedDataTypes() {
try {
MutableObjectIterator<IntPair> input1 = new UniformIntPairGenerator(500, 40, false);
@@ -583,18 +585,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleIntPairMatch>> entry :
expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstAndProbeSideOuterJoin() {
+ void testBuildFirstAndProbeSideOuterJoin() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 500, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -649,18 +651,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstAndBuildSideOuterJoin() {
+ void testBuildFirstAndBuildSideOuterJoin() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 500, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -715,18 +717,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstAndFullOuterJoin() {
+ void testBuildFirstAndFullOuterJoin() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 500, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -781,18 +783,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondAndProbeSideOuterJoin() {
+ void testBuildSecondAndProbeSideOuterJoin() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 1000, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -847,18 +849,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondAndBuildSideOuterJoin() {
+ void testBuildSecondAndBuildSideOuterJoin() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 1000, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -913,18 +915,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondAndFullOuterJoin() {
+ void testBuildSecondAndFullOuterJoin() {
try {
TupleGenerator generator1 =
new TupleGenerator(SEED1, 1000, 4096, KeyMode.RANDOM, ValueMode.RANDOM_LENGTH);
@@ -979,13 +981,13 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@@ -1228,7 +1230,7 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
}
/** Private class used for storage of the expected matches in a hash-map. */
- public static class TupleIntPairMatch {
+ static class TupleIntPairMatch {
private final int left;
private final String right;
@@ -1276,13 +1278,14 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
// System.err.println("rec1 key = "+key+" rec2 key= "+rec2.f0);
Collection<TupleMatch> matches = this.toRemoveFrom.get(key);
- if (matches == null) {
- Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected.");
- }
+ assertThat(matches)
+ .withFailMessage("Match %d - %s:%s is unexpected.", key, value1, value2)
+ .isNotNull();
- Assert.assertTrue(
- "Produced match was not contained: " + key + " - " + value1 + ":" + value2,
- matches.remove(new TupleMatch(value1, value2)));
+ assertThat(matches.remove(new TupleMatch(value1, value2)))
+ .withFailMessage(
+ "Produced match was not contained: %d - %s:%s", key, value1, value2)
+ .isTrue();
if (matches.isEmpty()) {
this.toRemoveFrom.remove(key);
@@ -1309,17 +1312,18 @@ public class NonReusingHashJoinIteratorITCase extends TestLogger {
final Integer key = rec2.f0;
final String value = rec2.f1;
- Assert.assertTrue(
- "Key does not match for matching IntPair Tuple combination.", k == key);
+ assertThat(key)
+ .withFailMessage("Key does not match for matching IntPair Tuple combination.")
+ .isEqualTo(k);
Collection<TupleIntPairMatch> matches = this.toRemoveFrom.get(key);
- if (matches == null) {
- Assert.fail("Match " + key + " - " + v + ":" + value + " is unexpected.");
- }
+ assertThat(matches)
+ .withFailMessage("Match %d - %d:%s is unexpected.", k, v, value)
+ .isNotNull();
- Assert.assertTrue(
- "Produced match was not contained: " + key + " - " + v + ":" + value,
- matches.remove(new TupleIntPairMatch(v, value)));
+ assertThat(matches.remove(new TupleIntPairMatch(v, value)))
+ .withFailMessage("Produced match was not contained: %d - %d:%s", key, v, value)
+ .isTrue();
if (matches.isEmpty()) {
this.toRemoveFrom.remove(key);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingReOpenableHashTableITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingReOpenableHashTableITCase.java
index 8f28f4219be..d568e48d6ea 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingReOpenableHashTableITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/NonReusingReOpenableHashTableITCase.java
@@ -27,8 +27,6 @@ import org.apache.flink.runtime.operators.testutils.TestData;
import org.apache.flink.runtime.operators.testutils.TestData.TupleGenerator;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -37,12 +35,13 @@ import java.util.Map.Entry;
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.collectTupleData;
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.joinTuples;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Test specialized hash join that keeps the build side data (in memory and on hard disk) This is
* used for iterative tasks.
*/
-public class NonReusingReOpenableHashTableITCase extends ReOpenableHashTableTestBase {
+class NonReusingReOpenableHashTableITCase extends ReOpenableHashTableTestBase {
protected void doTest(
TestData.TupleGeneratorIterator buildInput,
@@ -99,9 +98,9 @@ public class NonReusingReOpenableHashTableITCase extends ReOpenableHashTableTest
// assert that each expected match was seen for the first input
for (Entry<Integer, Collection<TupleMatch>> entry : expectedFirstMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
for (int i = 0; i < NUM_PROBES; i++) {
@@ -115,9 +114,9 @@ public class NonReusingReOpenableHashTableITCase extends ReOpenableHashTableTest
// assert that each expected match was seen for the second input
for (Entry<Integer, Collection<TupleMatch>> entry :
expectedNMatchesMapList.get(i).entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableITCase.java
index e885f79cd59..3fde6204297 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableITCase.java
@@ -35,12 +35,10 @@ import org.apache.flink.runtime.operators.testutils.TestData;
import org.apache.flink.runtime.operators.testutils.UniformIntTupleGenerator;
import org.apache.flink.runtime.operators.testutils.UnionIterator;
import org.apache.flink.util.MutableObjectIterator;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Assert;
-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.IOException;
import java.util.ArrayList;
@@ -48,9 +46,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class ReOpenableHashTableITCase extends TestLogger {
+class ReOpenableHashTableITCase {
private static final int PAGE_SIZE = 8 * 1024;
private static final long MEMORY_SIZE = PAGE_SIZE * 1000; // 100 Pages.
@@ -69,8 +68,8 @@ public class ReOpenableHashTableITCase extends TestLogger {
pactRecordComparator;
@SuppressWarnings({"unchecked", "rawtypes"})
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
this.recordBuildSideAccesssor = TestData.getIntIntTupleSerializer();
this.recordProbeSideAccesssor = TestData.getIntIntTupleSerializer();
this.recordBuildSideComparator = TestData.getIntIntTupleComparator();
@@ -87,17 +86,18 @@ public class ReOpenableHashTableITCase extends TestLogger {
this.ioManager = new IOManagerAsync();
}
- @After
- public void afterTest() throws Exception {
+ @AfterEach
+ void afterTest() throws Exception {
if (this.ioManager != null) {
this.ioManager.close();
this.ioManager = null;
}
if (this.memoryManager != null) {
- Assert.assertTrue(
- "Memory Leak: Not all memory has been returned to the memory manager.",
- this.memoryManager.verifyEmpty());
+ assertThat(this.memoryManager.verifyEmpty())
+ .withFailMessage(
+ "Memory Leak: Not all memory has been returned to the memory manager.")
+ .isTrue();
this.memoryManager.shutdown();
this.memoryManager = null;
}
@@ -122,7 +122,7 @@ public class ReOpenableHashTableITCase extends TestLogger {
}
@Test
- public void testSpillingHashJoinWithMassiveCollisions() throws IOException {
+ void testSpillingHashJoinWithMassiveCollisions() throws IOException {
// the following two values are known to have a hash-code collision on the initial level.
// we use them to make sure one partition grows over-proportionally large
final int REPEATED_VALUE_1 = 40559;
@@ -198,15 +198,17 @@ public class ReOpenableHashTableITCase extends TestLogger {
join.getBuildSideIterator();
if ((record = buildSide.next(recordReuse)) != null) {
numBuildValues = 1;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, record.f0);
+ assertThat(record.f0)
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
} else {
fail("No build side values found for a probe key.");
}
while ((record = buildSide.next(recordReuse)) != null) {
numBuildValues++;
- Assert.assertEquals(
- "Probe-side key was different than build-side key.", key, record.f0);
+ assertThat(record.f0)
+ .withFailMessage("Probe-side key was different than build-side key.")
+ .isEqualTo(key);
}
Long contained = map.get(key);
@@ -221,23 +223,24 @@ public class ReOpenableHashTableITCase extends TestLogger {
}
join.close();
- Assert.assertEquals("Wrong number of keys", NUM_KEYS, map.size());
+ assertThat(map).withFailMessage("Wrong number of keys").hasSize(NUM_KEYS);
for (Map.Entry<Integer, Long> entry : map.entrySet()) {
long val = entry.getValue();
int key = entry.getKey();
if (key == REPEATED_VALUE_1 || key == REPEATED_VALUE_2) {
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
- * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
- * NUM_PROBES,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(
+ (PROBE_VALS_PER_KEY + REPEATED_VALUE_COUNT_PROBE)
+ * (BUILD_VALS_PER_KEY + REPEATED_VALUE_COUNT_BUILD)
+ * NUM_PROBES);
} else {
- Assert.assertEquals(
- "Wrong number of values in per-key cross product for key " + key,
- PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY * NUM_PROBES,
- val);
+ assertThat(val)
+ .withFailMessage(
+ "Wrong number of values in per-key cross product for key %d", key)
+ .isEqualTo(PROBE_VALS_PER_KEY * BUILD_VALS_PER_KEY * NUM_PROBES);
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableTestBase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableTestBase.java
index 4dd966b76e9..cdfa71933cb 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableTestBase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReOpenableHashTableTestBase.java
@@ -35,16 +35,21 @@ import org.apache.flink.runtime.operators.testutils.TestData.TupleGenerator;
import org.apache.flink.runtime.operators.testutils.TestData.TupleGenerator.KeyMode;
import org.apache.flink.runtime.operators.testutils.TestData.TupleGenerator.ValueMode;
import org.apache.flink.runtime.operators.testutils.TestData.TupleGeneratorIterator;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Assert;
-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.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-public abstract class ReOpenableHashTableTestBase extends TestLogger {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+abstract class ReOpenableHashTableTestBase {
protected static final int PAGE_SIZE = 8 * 1024;
protected static final long MEMORY_SIZE = PAGE_SIZE * 1000; // 100 Pages.
@@ -73,8 +78,8 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
pactRecordComparator;
@SuppressWarnings({"unchecked", "rawtypes"})
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
this.recordSerializer = TestData.getIntStringTupleSerializer();
this.record1Comparator = TestData.getIntStringTupleComparator();
@@ -98,17 +103,18 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
this.ioManager = new IOManagerAsync();
}
- @After
- public void afterTest() throws Exception {
+ @AfterEach
+ void afterTest() throws Exception {
if (this.ioManager != null) {
this.ioManager.close();
this.ioManager = null;
}
if (this.memoryManager != null) {
- Assert.assertTrue(
- "Memory Leak: Not all memory has been returned to the memory manager.",
- this.memoryManager.verifyEmpty());
+ assertThat(this.memoryManager.verifyEmpty())
+ .withFailMessage(
+ "Memory Leak: Not all memory has been returned to the memory manager.")
+ .isTrue();
this.memoryManager.shutdown();
this.memoryManager = null;
}
@@ -119,7 +125,7 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
* input is reopened again)
*/
@Test
- public void testOverflow() {
+ void testOverflow() {
int buildSize = 1000;
int probeSize = 1000;
@@ -134,13 +140,13 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
doTest(buildInput, probeInput, bgen, pgen);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
/** Verify proper operation if the build side is spilled to disk. */
@Test
- public void testDoubleProbeSpilling() {
+ void testDoubleProbeSpilling() {
int buildSize = 1000;
int probeSize = 1000;
@@ -155,7 +161,7 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
doTest(buildInput, probeInput, bgen, pgen);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@@ -164,7 +170,7 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
* the build side fits completely into memory.
*/
@Test
- public void testDoubleProbeInMemory() {
+ void testDoubleProbeInMemory() {
int buildSize = 1000;
int probeSize = 1000;
@@ -180,7 +186,7 @@ public abstract class ReOpenableHashTableTestBase extends TestLogger {
doTest(buildInput, probeInput, bgen, pgen);
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingHashJoinIteratorITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingHashJoinIteratorITCase.java
index 0841b9e2f05..49187930a26 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingHashJoinIteratorITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingHashJoinIteratorITCase.java
@@ -44,12 +44,10 @@ import org.apache.flink.runtime.operators.testutils.types.IntPairSerializer;
import org.apache.flink.types.NullKeyFieldException;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
import java.util.Collection;
@@ -64,9 +62,11 @@ import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIterator
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.joinTuples;
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.leftOuterJoinTuples;
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.rightOuterJoinTuples;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
@SuppressWarnings({"serial"})
-public class ReusingHashJoinIteratorITCase extends TestLogger {
+class ReusingHashJoinIteratorITCase {
private static final int MEMORY_SIZE = 16000000; // total memory
@@ -93,8 +93,8 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
private TypePairComparator<Tuple2<Integer, String>, IntPair> recordPairPairComparator;
@SuppressWarnings("unchecked")
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
this.recordSerializer = TestData.getIntStringTupleSerializer();
this.record1Comparator = TestData.getIntStringTupleComparator();
@@ -112,24 +112,25 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
this.ioManager = new IOManagerAsync();
}
- @After
- public void afterTest() throws Exception {
+ @AfterEach
+ void afterTest() throws Exception {
if (this.ioManager != null) {
this.ioManager.close();
this.ioManager = null;
}
if (this.memoryManager != null) {
- Assert.assertTrue(
- "Memory Leak: Not all memory has been returned to the memory manager.",
- this.memoryManager.verifyEmpty());
+ assertThat(this.memoryManager.verifyEmpty())
+ .withFailMessage(
+ "Memory Leak: Not all memory has been returned to the memory manager.")
+ .isTrue();
this.memoryManager.shutdown();
this.memoryManager = null;
}
}
@Test
- public void testBuildFirst() {
+ void testBuildFirst() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -186,18 +187,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstWithHighNumberOfCommonKeys() {
+ void testBuildFirstWithHighNumberOfCommonKeys() {
// the size of the left and right inputs
final int INPUT_1_SIZE = 200;
final int INPUT_2_SIZE = 100;
@@ -294,18 +295,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecond() {
+ void testBuildSecond() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -362,18 +363,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondWithHighNumberOfCommonKeys() {
+ void testBuildSecondWithHighNumberOfCommonKeys() {
// the size of the left and right inputs
final int INPUT_1_SIZE = 200;
final int INPUT_2_SIZE = 100;
@@ -470,18 +471,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstWithMixedDataTypes() {
+ void testBuildFirstWithMixedDataTypes() {
try {
MutableObjectIterator<IntPair> input1 = new UniformIntPairGenerator(500, 40, false);
@@ -533,18 +534,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleIntPairMatch>> entry :
expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondWithMixedDataTypes() {
+ void testBuildSecondWithMixedDataTypes() {
try {
MutableObjectIterator<IntPair> input1 = new UniformIntPairGenerator(500, 40, false);
@@ -596,18 +597,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleIntPairMatch>> entry :
expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstAndProbeSideOuterJoin() {
+ void testBuildFirstAndProbeSideOuterJoin() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -664,18 +665,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstAndBuildSideOuterJoin() {
+ void testBuildFirstAndBuildSideOuterJoin() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -732,18 +733,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildFirstAndFullOuterJoin() {
+ void testBuildFirstAndFullOuterJoin() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -800,18 +801,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondAndProbeSideOuterJoin() {
+ void testBuildSecondAndProbeSideOuterJoin() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -868,18 +869,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondAndBuildSideOuterJoin() {
+ void testBuildSecondAndBuildSideOuterJoin() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -936,18 +937,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@Test
- public void testBuildSecondAndFullOuterJoin() {
+ void testBuildSecondAndFullOuterJoin() {
try {
TestData.TupleGenerator generator1 =
new TestData.TupleGenerator(
@@ -1004,13 +1005,13 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// assert that each expected match was seen
for (Entry<Integer, Collection<TupleMatch>> entry : expectedMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("An exception occurred during the test: " + e.getMessage());
+ fail("An exception occurred during the test: " + e.getMessage());
}
}
@@ -1039,13 +1040,14 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
// System.err.println("rec1 key = "+key+" rec2 key= "+rec2.getField(0,
// TestData.Key.class));
Collection<TupleMatch> matches = this.toRemoveFrom.get(key);
- if (matches == null) {
- Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected.");
- }
+ assertThat(matches)
+ .withFailMessage("Match %d - %s:%s is unexpected.", key, value1, value2)
+ .isNotNull();
- Assert.assertTrue(
- "Produced match was not contained: " + key + " - " + value1 + ":" + value2,
- matches.remove(new TupleMatch(value1, value2)));
+ assertThat(matches.remove(new TupleMatch(value1, value2)))
+ .withFailMessage(
+ "Produced match was not contained: %d - %s:%s", key, value1, value2)
+ .isTrue();
if (matches.isEmpty()) {
this.toRemoveFrom.remove(key);
@@ -1072,17 +1074,18 @@ public class ReusingHashJoinIteratorITCase extends TestLogger {
final Integer key = rec2.f0;
final String value = rec2.f1;
- Assert.assertTrue(
- "Key does not match for matching IntPair Tuple combination.", k == key);
+ assertThat(key)
+ .withFailMessage("Key does not match for matching IntPair Tuple combination.")
+ .isEqualTo(k);
Collection<TupleIntPairMatch> matches = this.toRemoveFrom.get(key);
- if (matches == null) {
- Assert.fail("Match " + key + " - " + v + ":" + value + " is unexpected.");
- }
+ assertThat(matches)
+ .withFailMessage("Match %d - %d:%s is unexpected.", key, v, value)
+ .isNotNull();
- Assert.assertTrue(
- "Produced match was not contained: " + key + " - " + v + ":" + value,
- matches.remove(new TupleIntPairMatch(v, value)));
+ assertThat(matches.remove(new TupleIntPairMatch(v, value)))
+ .withFailMessage("Produced match was not contained: %d - %d:%s", key, v, value)
+ .isTrue();
if (matches.isEmpty()) {
this.toRemoveFrom.remove(key);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingReOpenableHashTableITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingReOpenableHashTableITCase.java
index 5d43bb24a32..15fcab8ab1b 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingReOpenableHashTableITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/hash/ReusingReOpenableHashTableITCase.java
@@ -27,8 +27,6 @@ import org.apache.flink.runtime.operators.testutils.TestData;
import org.apache.flink.runtime.operators.testutils.TestData.TupleGenerator;
import org.apache.flink.util.Collector;
-import org.junit.Assert;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -37,12 +35,13 @@ import java.util.Map.Entry;
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.collectTupleData;
import static org.apache.flink.runtime.operators.hash.NonReusingHashJoinIteratorITCase.joinTuples;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Test specialized hash join that keeps the build side data (in memory and on hard disk) This is
* used for iterative tasks.
*/
-public class ReusingReOpenableHashTableITCase extends ReOpenableHashTableTestBase {
+class ReusingReOpenableHashTableITCase extends ReOpenableHashTableTestBase {
protected void doTest(
TestData.TupleGeneratorIterator buildInput,
@@ -99,9 +98,9 @@ public class ReusingReOpenableHashTableITCase extends ReOpenableHashTableTestBas
// assert that each expected match was seen for the first input
for (Entry<Integer, Collection<TupleMatch>> entry : expectedFirstMatchesMap.entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
for (int i = 0; i < NUM_PROBES; i++) {
@@ -115,9 +114,9 @@ public class ReusingReOpenableHashTableITCase extends ReOpenableHashTableTestBas
// assert that each expected match was seen for the second input
for (Entry<Integer, Collection<TupleMatch>> entry :
expectedNMatchesMapList.get(i).entrySet()) {
- if (!entry.getValue().isEmpty()) {
- Assert.fail("Collection for key " + entry.getKey() + " is not empty");
- }
+ assertThat(entry.getValue())
+ .withFailMessage("Collection for key %d is not empty", entry.getKey())
+ .isEmpty();
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
index ccdf3612163..44e4c3c3c7f 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/BlockResettableMutableObjectIteratorTest.java
@@ -29,15 +29,17 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
import java.util.List;
-public class BlockResettableMutableObjectIteratorTest {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class BlockResettableMutableObjectIteratorTest {
private static final int MEMORY_CAPACITY = 3 * 128 * 1024;
@@ -53,8 +55,8 @@ public class BlockResettableMutableObjectIteratorTest {
private List<Record> objects;
- @Before
- public void startup() {
+ @BeforeEach
+ void startup() {
// set up IO and memory manager
this.memman = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_CAPACITY).build();
@@ -68,22 +70,22 @@ public class BlockResettableMutableObjectIteratorTest {
this.reader = new MutableObjectIteratorWrapper(this.objects.iterator());
}
- @After
- public void shutdown() {
+ @AfterEach
+ void shutdown() {
this.objects = null;
// check that the memory manager got all segments back
- if (!this.memman.verifyEmpty()) {
- Assert.fail(
- "A memory leak has occurred: Not all memory was properly returned to the memory manager.");
- }
+ assertThat(this.memman.verifyEmpty())
+ .withFailMessage(
+ "A memory leak has occurred: Not all memory was properly returned to the memory manager.")
+ .isTrue();
this.memman.shutdown();
this.memman = null;
}
@Test
- public void testSerialBlockResettableIterator() throws Exception {
+ void testSerialBlockResettableIterator() throws Exception {
try {
// create the resettable Iterator
final BlockResettableMutableObjectIterator<Record> iterator =
@@ -102,7 +104,7 @@ public class BlockResettableMutableObjectIteratorTest {
Record target = new Record();
while ((target = iterator.next(target)) != null) {
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -111,21 +113,21 @@ public class BlockResettableMutableObjectIteratorTest {
int count = 0;
while ((target = iterator.next(target)) != null) {
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
} catch (Exception ex) {
- Assert.fail("Test encountered an exception: " + ex.getMessage());
+ fail("Test encountered an exception: " + ex.getMessage());
}
}
@Test
- public void testDoubleBufferedBlockResettableIterator() throws Exception {
+ void testDoubleBufferedBlockResettableIterator() throws Exception {
try {
// create the resettable Iterator
final BlockResettableMutableObjectIterator<Record> iterator =
@@ -145,7 +147,7 @@ public class BlockResettableMutableObjectIteratorTest {
// find the upper bound
while ((target = iterator.next(target)) != null) {
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -154,21 +156,21 @@ public class BlockResettableMutableObjectIteratorTest {
int count = 0;
while ((target = iterator.next(target)) != null) {
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
} catch (Exception ex) {
- Assert.fail("Test encountered an exception: " + ex.getMessage());
+ fail("Test encountered an exception: " + ex.getMessage());
}
}
@Test
- public void testTwelveFoldBufferedBlockResettableIterator() throws Exception {
+ void testTwelveFoldBufferedBlockResettableIterator() throws Exception {
try {
// create the resettable Iterator
final BlockResettableMutableObjectIterator<Record> iterator =
@@ -188,7 +190,7 @@ public class BlockResettableMutableObjectIteratorTest {
// find the upper bound
while ((target = iterator.next(target)) != null) {
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -197,16 +199,16 @@ public class BlockResettableMutableObjectIteratorTest {
int count = 0;
while ((target = iterator.next(target)) != null) {
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
} catch (Exception ex) {
- Assert.fail("Test encountered an exception: " + ex.getMessage());
+ fail("Test encountered an exception: " + ex.getMessage());
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
index 5d64466bc7b..8dc15dabaf2 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/NonReusingBlockResettableIteratorTest.java
@@ -27,16 +27,17 @@ import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-public class NonReusingBlockResettableIteratorTest {
+import static org.assertj.core.api.Assertions.assertThat;
+
+class NonReusingBlockResettableIteratorTest {
private static final int MEMORY_CAPACITY = 3 * 128 * 1024;
@@ -50,8 +51,8 @@ public class NonReusingBlockResettableIteratorTest {
private final TypeSerializer<Record> serializer = RecordSerializer.get();
- @Before
- public void startup() {
+ @BeforeEach
+ void startup() {
// set up IO and memory manager
this.memman = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_CAPACITY).build();
@@ -65,22 +66,22 @@ public class NonReusingBlockResettableIteratorTest {
this.reader = objects.iterator();
}
- @After
- public void shutdown() {
+ @AfterEach
+ void shutdown() {
this.objects = null;
// check that the memory manager got all segments back
- if (!this.memman.verifyEmpty()) {
- Assert.fail(
- "A memory leak has occurred: Not all memory was properly returned to the memory manager.");
- }
+ assertThat(this.memman.verifyEmpty())
+ .withFailMessage(
+ "A memory leak has occurred: Not all memory was properly returned to the memory manager.")
+ .isTrue();
this.memman.shutdown();
this.memman = null;
}
@Test
- public void testSerialBlockResettableIterator() throws Exception {
+ void testSerialBlockResettableIterator() throws Exception {
final AbstractInvokable memOwner = new DummyInvokable();
// create the resettable Iterator
final NonReusingBlockResettableIterator<Record> iterator =
@@ -99,7 +100,7 @@ public class NonReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -108,18 +109,18 @@ public class NonReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
}
@Test
- public void testDoubleBufferedBlockResettableIterator() throws Exception {
+ void testDoubleBufferedBlockResettableIterator() throws Exception {
final AbstractInvokable memOwner = new DummyInvokable();
// create the resettable Iterator
final NonReusingBlockResettableIterator<Record> iterator =
@@ -138,7 +139,7 @@ public class NonReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -147,19 +148,19 @@ public class NonReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
}
@Test
- public void testTwelveFoldBufferedBlockResettableIterator() throws Exception {
+ void testTwelveFoldBufferedBlockResettableIterator() throws Exception {
final AbstractInvokable memOwner = new DummyInvokable();
// create the resettable Iterator
final NonReusingBlockResettableIterator<Record> iterator =
@@ -178,7 +179,7 @@ public class NonReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -187,12 +188,12 @@ public class NonReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
index 0b1c83deaa5..3a5ad4d1906 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/ReusingBlockResettableIteratorTest.java
@@ -27,16 +27,17 @@ import org.apache.flink.runtime.testutils.recordutils.RecordSerializer;
import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-public class ReusingBlockResettableIteratorTest {
+import static org.assertj.core.api.Assertions.assertThat;
+
+class ReusingBlockResettableIteratorTest {
private static final int MEMORY_CAPACITY = 3 * 128 * 1024;
@@ -50,8 +51,8 @@ public class ReusingBlockResettableIteratorTest {
private final TypeSerializer<Record> serializer = RecordSerializer.get();
- @Before
- public void startup() {
+ @BeforeEach
+ void startup() {
// set up IO and memory manager
this.memman = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_CAPACITY).build();
@@ -65,22 +66,22 @@ public class ReusingBlockResettableIteratorTest {
this.reader = objects.iterator();
}
- @After
- public void shutdown() {
+ @AfterEach
+ void shutdown() {
this.objects = null;
// check that the memory manager got all segments back
- if (!this.memman.verifyEmpty()) {
- Assert.fail(
- "A memory leak has occurred: Not all memory was properly returned to the memory manager.");
- }
+ assertThat(this.memman.verifyEmpty())
+ .withFailMessage(
+ "A memory leak has occurred: Not all memory was properly returned to the memory manager.")
+ .isTrue();
this.memman.shutdown();
this.memman = null;
}
@Test
- public void testSerialBlockResettableIterator() throws Exception {
+ void testSerialBlockResettableIterator() throws Exception {
final AbstractInvokable memOwner = new DummyInvokable();
// create the resettable Iterator
final ReusingBlockResettableIterator<Record> iterator =
@@ -99,7 +100,7 @@ public class ReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -108,18 +109,18 @@ public class ReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
}
@Test
- public void testDoubleBufferedBlockResettableIterator() throws Exception {
+ void testDoubleBufferedBlockResettableIterator() throws Exception {
final AbstractInvokable memOwner = new DummyInvokable();
// create the resettable Iterator
final ReusingBlockResettableIterator<Record> iterator =
@@ -138,7 +139,7 @@ public class ReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -147,19 +148,19 @@ public class ReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
}
@Test
- public void testTwelveFoldBufferedBlockResettableIterator() throws Exception {
+ void testTwelveFoldBufferedBlockResettableIterator() throws Exception {
final AbstractInvokable memOwner = new DummyInvokable();
// create the resettable Iterator
final ReusingBlockResettableIterator<Record> iterator =
@@ -178,7 +179,7 @@ public class ReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(upper++, val);
+ assertThat(val).isEqualTo(upper++);
}
// now reset the buffer a few times
for (int i = 0; i < 5; ++i) {
@@ -187,12 +188,12 @@ public class ReusingBlockResettableIteratorTest {
while (iterator.hasNext()) {
Record target = iterator.next();
int val = target.getField(0, IntValue.class).getValue();
- Assert.assertEquals(lower + (count++), val);
+ assertThat(val).isEqualTo(lower + (count++));
}
- Assert.assertEquals(upper - lower, count);
+ assertThat(count).isEqualTo(upper - lower);
}
} while (iterator.nextBlock());
- Assert.assertEquals(NUM_VALUES, upper);
+ assertThat(upper).isEqualTo(NUM_VALUES);
// close the iterator
iterator.close();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableIteratorTest.java
index 7781e3bbf8f..cdb5ff96d25 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableIteratorTest.java
@@ -28,16 +28,19 @@ import org.apache.flink.runtime.memory.MemoryManagerBuilder;
import org.apache.flink.runtime.operators.testutils.DummyInvokable;
import org.apache.flink.types.IntValue;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
-public class SpillingResettableIteratorTest {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
+
+class SpillingResettableIteratorTest {
private static final int NUM_TESTRECORDS = 50000;
@@ -53,8 +56,8 @@ public class SpillingResettableIteratorTest {
private final TypeSerializer<IntValue> serializer = new IntValueSerializer();
- @Before
- public void startup() {
+ @BeforeEach
+ void startup() {
// set up IO and memory manager
this.memman = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_CAPACITY).build();
this.ioman = new IOManagerAsync();
@@ -69,15 +72,15 @@ public class SpillingResettableIteratorTest {
this.reader = objects.iterator();
}
- @After
- public void shutdown() throws Exception {
+ @AfterEach
+ void shutdown() throws Exception {
this.ioman.close();
this.ioman = null;
- if (!this.memman.verifyEmpty()) {
- Assert.fail(
- "A memory leak has occurred: Not all memory was properly returned to the memory manager.");
- }
+ assertThat(this.memman.verifyEmpty())
+ .withFailMessage(
+ "A memory leak has occurred: Not all memory was properly returned to the memory manager.")
+ .isTrue();
this.memman.shutdown();
this.memman = null;
}
@@ -87,7 +90,7 @@ public class SpillingResettableIteratorTest {
* disk.
*/
@Test
- public void testResettableIterator() {
+ void testResettableIterator() {
try {
// create the resettable Iterator
SpillingResettableIterator<IntValue> iterator =
@@ -104,39 +107,36 @@ public class SpillingResettableIteratorTest {
// now test walking through the iterator
int count = 0;
while (iterator.hasNext()) {
- Assert.assertEquals(
- "In initial run, element " + count + " does not match expected value!",
- count++,
- iterator.next().getValue());
+ assertThat(iterator.next().getValue())
+ .withFailMessage(
+ "In initial run, element %d does not match expected value!", count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied in initial run!", NUM_TESTRECORDS, count);
+ assertThat(count)
+ .withFailMessage("Too few elements were deserialized in initial run!")
+ .isEqualTo(NUM_TESTRECORDS);
// test resetting the iterator a few times
for (int j = 0; j < 10; ++j) {
count = 0;
iterator.reset();
// now we should get the same results
while (iterator.hasNext()) {
- Assert.assertEquals(
- "After reset nr. "
- + j
- + 1
- + " element "
- + count
- + " does not match expected value!",
- count++,
- iterator.next().getValue());
+ assertThat(iterator.next().getValue())
+ .withFailMessage(
+ "After reset nr. %d element %d does not match expected value!",
+ j + 1, count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied after reset nr. " + j + 1 + "!",
- NUM_TESTRECORDS,
- count);
+ assertThat(count)
+ .withFailMessage(
+ "Too few elements were deserialized after reset nr. %d!", j + 1)
+ .isEqualTo(NUM_TESTRECORDS);
}
// close the iterator
iterator.close();
} catch (Exception ex) {
ex.printStackTrace();
- Assert.fail("Test encountered an exception.");
+ fail("Test encountered an exception.");
}
}
@@ -145,7 +145,7 @@ public class SpillingResettableIteratorTest {
* membuffer.
*/
@Test
- public void testResettableIteratorInMemory() {
+ void testResettableIteratorInMemory() {
try {
// create the resettable Iterator
SpillingResettableIterator<IntValue> iterator =
@@ -162,45 +162,42 @@ public class SpillingResettableIteratorTest {
// now test walking through the iterator
int count = 0;
while (iterator.hasNext()) {
- Assert.assertEquals(
- "In initial run, element " + count + " does not match expected value!",
- count++,
- iterator.next().getValue());
+ assertThat(iterator.next().getValue())
+ .withFailMessage(
+ "In initial run, element %d does not match expected value!", count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied in initial run!", NUM_TESTRECORDS, count);
+ assertThat(count)
+ .withFailMessage("Too few elements were deserialized in initial run!")
+ .isEqualTo(NUM_TESTRECORDS);
// test resetting the iterator a few times
for (int j = 0; j < 10; ++j) {
count = 0;
iterator.reset();
// now we should get the same results
while (iterator.hasNext()) {
- Assert.assertEquals(
- "After reset nr. "
- + j
- + 1
- + " element "
- + count
- + " does not match expected value!",
- count++,
- iterator.next().getValue());
+ assertThat(iterator.next().getValue())
+ .withFailMessage(
+ "After reset nr. %d element %d does not match expected value!",
+ j + 1, count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied after reset nr. " + j + 1 + "!",
- NUM_TESTRECORDS,
- count);
+ assertThat(count)
+ .withFailMessage(
+ "Too few elements were deserialized after reset nr. %d!", j + 1)
+ .isEqualTo(NUM_TESTRECORDS);
}
// close the iterator
iterator.close();
} catch (Exception ex) {
ex.printStackTrace();
- Assert.fail("Test encountered an exception.");
+ fail("Test encountered an exception.");
}
}
/** Tests whether multiple call of hasNext() changes the state of the iterator */
@Test
- public void testHasNext() {
+ void testHasNext() {
try {
// create the resettable Iterator
SpillingResettableIterator<IntValue> iterator =
@@ -221,20 +218,21 @@ public class SpillingResettableIteratorTest {
cnt++;
}
- Assert.assertTrue(
- cnt + " elements read from iterator, but " + NUM_TESTRECORDS + " expected",
- cnt == NUM_TESTRECORDS);
+ assertThat(cnt)
+ .withFailMessage(
+ "%d elements read from iterator, but %d expected", cnt, NUM_TESTRECORDS)
+ .isEqualTo(NUM_TESTRECORDS);
iterator.close();
} catch (Exception ex) {
ex.printStackTrace();
- Assert.fail("Test encountered an exception.");
+ fail("Test encountered an exception.");
}
}
/** Test whether next() depends on previous call of hasNext() */
@Test
- public void testNext() {
+ void testNext() {
try {
// create the resettable Iterator
SpillingResettableIterator<IntValue> iterator =
@@ -252,21 +250,18 @@ public class SpillingResettableIteratorTest {
int cnt = 0;
while (cnt < NUM_TESTRECORDS) {
record = iterator.next();
- Assert.assertTrue("Record was not read from iterator", record != null);
+ assertThat(record).withFailMessage("Record was not read from iterator").isNotNull();
cnt++;
}
- try {
- record = iterator.next();
- Assert.fail("Too many records were read from iterator.");
- } catch (NoSuchElementException nseex) {
- // expected
- }
+ assertThatThrownBy(iterator::next)
+ .withFailMessage("Too many records were read from iterator.")
+ .isInstanceOf(NoSuchElementException.class);
iterator.close();
} catch (Exception ex) {
ex.printStackTrace();
- Assert.fail("Test encountered an exception.");
+ fail("Test encountered an exception.");
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
index d3859f5c43c..8b3114be0da 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/resettable/SpillingResettableMutableObjectIteratorTest.java
@@ -31,14 +31,16 @@ import org.apache.flink.types.IntValue;
import org.apache.flink.types.Record;
import org.apache.flink.util.MutableObjectIterator;
-import org.junit.After;
-import org.junit.Assert;
-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.util.ArrayList;
-public class SpillingResettableMutableObjectIteratorTest {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+class SpillingResettableMutableObjectIteratorTest {
private static final int NUM_TESTRECORDS = 50000;
@@ -52,8 +54,8 @@ public class SpillingResettableMutableObjectIteratorTest {
private final TypeSerializer<Record> serializer = RecordSerializer.get();
- @Before
- public void startup() {
+ @BeforeEach
+ void startup() {
// set up IO and memory manager
this.memman = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_CAPACITY).build();
this.ioman = new IOManagerAsync();
@@ -68,15 +70,15 @@ public class SpillingResettableMutableObjectIteratorTest {
this.reader = new MutableObjectIteratorWrapper(objects.iterator());
}
- @After
- public void shutdown() throws Exception {
+ @AfterEach
+ void shutdown() throws Exception {
this.ioman.close();
this.ioman = null;
- if (!this.memman.verifyEmpty()) {
- Assert.fail(
- "A memory leak has occurred: Not all memory was properly returned to the memory manager.");
- }
+ assertThat(this.memman.verifyEmpty())
+ .withFailMessage(
+ "A memory leak has occurred: Not all memory was properly returned to the memory manager.")
+ .isTrue();
this.memman.shutdown();
this.memman = null;
}
@@ -86,7 +88,7 @@ public class SpillingResettableMutableObjectIteratorTest {
* disk.
*/
@Test
- public void testResettableIterator() {
+ void testResettableIterator() {
try {
final AbstractInvokable memOwner = new DummyInvokable();
@@ -102,13 +104,14 @@ public class SpillingResettableMutableObjectIteratorTest {
int count = 0;
Record target = new Record();
while ((target = iterator.next(target)) != null) {
- Assert.assertEquals(
- "In initial run, element " + count + " does not match expected value!",
- count++,
- target.getField(0, IntValue.class).getValue());
+ assertThat(target.getField(0, IntValue.class).getValue())
+ .withFailMessage(
+ "In initial run, element %d does not match expected value!", count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied in initial run!", NUM_TESTRECORDS, count);
+ assertThat(count)
+ .withFailMessage("Too few elements were deserialized in initial run!")
+ .isEqualTo(NUM_TESTRECORDS);
// test resetting the iterator a few times
for (int j = 0; j < 10; ++j) {
count = 0;
@@ -116,26 +119,22 @@ public class SpillingResettableMutableObjectIteratorTest {
target = new Record();
// now we should get the same results
while ((target = iterator.next(target)) != null) {
- Assert.assertEquals(
- "After reset nr. "
- + j
- + 1
- + " element "
- + count
- + " does not match expected value!",
- count++,
- target.getField(0, IntValue.class).getValue());
+ assertThat(target.getField(0, IntValue.class).getValue())
+ .withFailMessage(
+ "After reset nr. %d element %d does not match expected value!",
+ j + 1, count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied after reset nr. " + j + 1 + "!",
- NUM_TESTRECORDS,
- count);
+ assertThat(count)
+ .withFailMessage(
+ "Too few elements were deserialized after reset nr. %d!", j + 1)
+ .isEqualTo(NUM_TESTRECORDS);
}
// close the iterator
iterator.close();
} catch (Exception ex) {
ex.printStackTrace();
- Assert.fail("Test encountered an exception.");
+ fail("Test encountered an exception.");
}
}
@@ -143,7 +142,7 @@ public class SpillingResettableMutableObjectIteratorTest {
* Tests the resettable iterator with enough memory so that all data is kept locally in memory.
*/
@Test
- public void testResettableIteratorInMemory() {
+ void testResettableIteratorInMemory() {
try {
final AbstractInvokable memOwner = new DummyInvokable();
@@ -159,13 +158,14 @@ public class SpillingResettableMutableObjectIteratorTest {
int count = 0;
Record target = new Record();
while ((target = iterator.next(target)) != null) {
- Assert.assertEquals(
- "In initial run, element " + count + " does not match expected value!",
- count++,
- target.getField(0, IntValue.class).getValue());
+ assertThat(target.getField(0, IntValue.class).getValue())
+ .withFailMessage(
+ "In initial run, element %d does not match expected value!", count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied in initial run!", NUM_TESTRECORDS, count);
+ assertThat(count)
+ .withFailMessage("Too few elements were deserialized in initial run!")
+ .isEqualTo(NUM_TESTRECORDS);
// test resetting the iterator a few times
for (int j = 0; j < 10; ++j) {
count = 0;
@@ -173,26 +173,22 @@ public class SpillingResettableMutableObjectIteratorTest {
target = new Record();
// now we should get the same results
while ((target = iterator.next(target)) != null) {
- Assert.assertEquals(
- "After reset nr. "
- + j
- + 1
- + " element "
- + count
- + " does not match expected value!",
- count++,
- target.getField(0, IntValue.class).getValue());
+ assertThat(target.getField(0, IntValue.class).getValue())
+ .withFailMessage(
+ "After reset nr. %d element %d does not match expected value!",
+ j + 1, count)
+ .isEqualTo(count++);
}
- Assert.assertEquals(
- "Too few elements were deserialzied after reset nr. " + j + 1 + "!",
- NUM_TESTRECORDS,
- count);
+ assertThat(count)
+ .withFailMessage(
+ "Too few elements were deserialized after reset nr. %d!", j + 1)
+ .isEqualTo(NUM_TESTRECORDS);
}
// close the iterator
iterator.close();
} catch (Exception ex) {
ex.printStackTrace();
- Assert.fail("Test encountered an exception.");
+ fail("Test encountered an exception.");
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/sort/AbstractSortMergeOuterJoinIteratorITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/sort/AbstractSortMergeOuterJoinIteratorITCase.java
index e8719e50ff3..28ca1d55cb6 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/operators/sort/AbstractSortMergeOuterJoinIteratorITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/operators/sort/AbstractSortMergeOuterJoinIteratorITCase.java
@@ -53,22 +53,22 @@ import org.apache.flink.runtime.operators.testutils.TestData.TupleGeneratorItera
import org.apache.flink.runtime.util.ResettableMutableObjectIterator;
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;
-import org.apache.flink.util.TestLogger;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-public abstract class AbstractSortMergeOuterJoinIteratorITCase extends TestLogger {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+abstract class AbstractSortMergeOuterJoinIteratorITCase {
... 3694 lines suppressed ...