You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Jiabao-Sun (via GitHub)" <gi...@apache.org> on 2023/08/16 15:51:25 UTC
[GitHub] [flink] Jiabao-Sun commented on a diff in pull request #23199: [FLINK-32858][tests][JUnit5 migration] Migrate flink-runtime/utils tests to JUnit5
Jiabao-Sun commented on code in PR #23199:
URL: https://github.com/apache/flink/pull/23199#discussion_r1296055132
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/AddressResolutionTest.java:
##########
@@ -21,28 +21,30 @@
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.rpc.AddressResolution;
import org.apache.flink.runtime.rpc.RpcSystem;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assumptions.assumeThat;
/** Unit tests for respecting {@link AddressResolution}. */
-public class AddressResolutionTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
I think we needn't this line. There's an common configuration already in
`META-INF/services/org.junit.jupiter.api.extension.Extension`.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/HardwareTest.java:
##########
@@ -18,16 +18,17 @@
package org.apache.flink.runtime.util;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class HardwareTest {
+class HardwareTest {
@Test
public void testCpuCores() {
Review Comment:
```suggestion
void testCpuCores() {
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java:
##########
@@ -18,33 +18,39 @@
package org.apache.flink.runtime.util;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Arrays;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class EnvironmentInformationTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/JvmExitOnFatalErrorTest.java:
##########
@@ -90,21 +91,22 @@
* Test that verifies the behavior of blocking shutdown hooks and of the {@link
* JvmShutdownSafeguard} that guards against it.
*/
-public class JvmExitOnFatalErrorTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java:
##########
@@ -100,587 +102,615 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("F"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("G"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("F");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("G");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("J"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("K"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("L"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("J");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("K");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("L");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
Review Comment:
How about use `assertThatThrownBy` for this pattern.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java:
##########
@@ -100,587 +102,615 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
Review Comment:
How about use `assertThatThrownBy` for this pattern.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/RunnablesTest.java:
##########
@@ -33,7 +33,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-public class RunnablesTest extends TestLogger {
+import static org.assertj.core.api.Assertions.assertThat;
+
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
```suggestion
assertThat(actual).isEqualTo(expected);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891 "); // with leading and trailing whitespace
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
```suggestion
assertThat(actual).isEqualTo(expected);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891 "); // with leading and trailing whitespace
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891"); // whitespace after port
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
```suggestion
assertThat(actual).isEqualTo(expected);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/DualKeyLinkedMapTest.java:
##########
@@ -19,25 +19,24 @@
package org.apache.flink.runtime.util;
import org.apache.flink.api.java.tuple.Tuple2;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the {@link DualKeyLinkedMap}. */
-public class DualKeyLinkedMapTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/BoundedFIFOQueueTest.java:
##########
@@ -18,90 +18,87 @@
package org.apache.flink.runtime.util;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** {@code BoundedFIFOQueueTest} tests {@link BoundedFIFOQueue}. */
-public class BoundedFIFOQueueTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/JobManagerProcessSpecTest.java:
##########
@@ -20,18 +20,18 @@
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.runtime.jobmanager.JobManagerProcessSpec;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link JobManagerProcessSpec}. */
-public class JobManagerProcessSpecTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/HardwareTest.java:
##########
@@ -38,7 +39,7 @@ public void testCpuCores() {
public void testPhysicalMemory() {
Review Comment:
```suggestion
void testPhysicalMemory() {
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ResourceCounterTest.java:
##########
@@ -19,109 +19,107 @@
package org.apache.flink.runtime.util;
import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
import org.apache.flink.shaded.guava31.com.google.common.collect.ImmutableMap;
-import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Tests for the {@link ResourceCounter}. */
-public class ResourceCounterTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/FlinkSecurityManagerITCase.java:
##########
@@ -23,48 +23,49 @@
import org.apache.flink.core.security.FlinkSecurityManager;
import org.apache.flink.runtime.testutils.TestJvmProcess;
import org.apache.flink.util.OperatingSystem;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assume.assumeTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
/** Integration tests for the {@link FlinkSecurityManager}. */
-public class FlinkSecurityManagerITCase extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/JvmExitOnFatalErrorTest.java:
##########
@@ -90,21 +91,22 @@
* Test that verifies the behavior of blocking shutdown hooks and of the {@link
* JvmShutdownSafeguard} that guards against it.
*/
-public class JvmExitOnFatalErrorTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+class JvmExitOnFatalErrorTest {
- @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @TempDir private java.nio.file.Path tempDir;
@Test
- public void testExitJvmOnOutOfMemory() throws Exception {
+ void testExitJvmOnOutOfMemory() throws Exception {
// this test works only on linux and MacOS
assumeFalse(OperatingSystem.isWindows());
Review Comment:
```suggestion
assumeThat(OperatingSystem.isWindows()).isFalse();
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTreeCacheTest.java:
##########
@@ -33,21 +32,23 @@
import org.apache.flink.shaded.guava31.com.google.common.io.Closer;
import org.apache.curator.test.TestingServer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReference;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
/**
* Tests for {@link ZooKeeperUtils#createTreeCache(CuratorFramework, String,
* org.apache.flink.util.function.RunnableWithException)}.
*/
-public class ZooKeeperUtilsTreeCacheTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java:
##########
@@ -18,33 +18,39 @@
package org.apache.flink.runtime.util;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Arrays;
-import static org.junit.Assert.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
-public class EnvironmentInformationTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+class EnvironmentInformationTest {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
@Test
public void testJavaMemory() {
try {
long fullHeap = EnvironmentInformation.getMaxJvmHeapMemory();
long freeWithGC = EnvironmentInformation.getSizeOfFreeHeapMemoryWithDefrag();
- assertTrue(fullHeap > 0);
- assertTrue(freeWithGC >= 0);
+ assertThat(fullHeap).isGreaterThan(0);
+ assertThat(freeWithGC).isGreaterThanOrEqualTo(0);
try {
long free = EnvironmentInformation.getSizeOfFreeHeapMemory();
- assertTrue(free >= 0);
+ assertThat(free).isGreaterThanOrEqualTo(0);
} catch (RuntimeException e) {
// this may only occur if the Xmx is not set
- assertEquals(Long.MAX_VALUE, EnvironmentInformation.getMaxJvmHeapMemory());
+ assertThat(Long.MAX_VALUE).isEqualTo(EnvironmentInformation.getMaxJvmHeapMemory());
Review Comment:
```suggestion
assertThat(EnvironmentInformation.getMaxJvmHeapMemory()).isEqualTo(Long.MAX_VALUE);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/NonReusingKeyGroupedIteratorTest.java:
##########
@@ -100,587 +102,615 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
Review Comment:
How about use `assertThatThrownBy` for this pattern.
```java
assertThatThrownBy(this.psi.getValues()::next)
.isInstanceOf(NoSuchElementException.class);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/ManagedMemoryUtilsTest.java:
##########
@@ -203,11 +212,11 @@ public void testConvertToFractionOfSlotWeightNotConfigured() {
Optional.of(true),
ClassLoader.getSystemClassLoader());
- assertEquals(0.0, fractionOfSlot, DELTA);
+ assertThat(0.0).isCloseTo(fractionOfSlot, Offset.offset(DELTA));
Review Comment:
```suggestion
assertThat(fractionOfSlot).isCloseTo(0.0, Offset.offset(DELTA));
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java:
##########
@@ -103,600 +105,624 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("F"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("G"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("F");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("G");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("J"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("K"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("L"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("J");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("K");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("L");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(this.psi.getValues());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues()).isNull();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testMixedProgress() throws Exception {
+ void testMixedProgress() throws Exception {
try {
// Progression only via nextKey() and hasNext() - Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
// Progression only through nextKey() - Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
// Progression first though haNext() and next(), then through hasNext() - Key 3, Values
// C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Progression first via next() only, then hasNext() only Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
// end
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testHasNextDoesNotOverweiteCurrentRecord() throws Exception {
+ void testHasNextDoesNotOverwriteCurrentRecord() throws Exception {
try {
Iterator<Record> valsIter = null;
Record rec = null;
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
valsIter = this.psi.getValues();
- Assert.assertNotNull("Returned Iterator must not be null", valsIter);
- Assert.assertTrue(
- "KeyGroupedIterator's value iterator must have another value.",
- valsIter.hasNext());
+ assertThat(valsIter).withFailMessage("Returned Iterator must not be null").isNotNull();
+ assertThat(valsIter.hasNext())
Review Comment:
```suggestion
assertThat(valsIter).hasNext()
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/ManagedMemoryUtilsTest.java:
##########
@@ -262,13 +271,16 @@ private void testConvertToFractionOfSlotGivenWhetherStateBackendUsesManagedMemor
Optional.of(stateBackendUsesManagedMemory),
ClassLoader.getSystemClassLoader());
- assertEquals(expectedOperatorFractionOfSlot, opFractionOfSlot, DELTA);
- assertEquals(expectedStateFractionOfSlot, stateFractionOfSlot, DELTA);
- assertEquals(expectedPythonFractionOfSlot, pythonFractionOfSlot, DELTA);
+ assertThat(expectedOperatorFractionOfSlot)
+ .isCloseTo(opFractionOfSlot, Offset.offset(DELTA));
+ assertThat(expectedStateFractionOfSlot)
+ .isCloseTo(stateFractionOfSlot, Offset.offset(DELTA));
+ assertThat(expectedPythonFractionOfSlot)
+ .isCloseTo(pythonFractionOfSlot, Offset.offset(DELTA));
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891 "); // with leading and trailing whitespace
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891"); // whitespace after port
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
}
{
expected = "localhost:2891,localhost:2891";
setQuorum(conf, "localhost:2891,localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost:2891, localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/ProcessMemoryUtilsTestBase.java:
##########
@@ -63,86 +65,83 @@ protected ProcessMemoryUtilsTestBase(
this.newOptionForLegacyHeapOption = checkNotNull(newOptionForLegacyHeapOption);
}
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
oldEnvVariables = System.getenv();
}
- @After
- public void teardown() {
+ @AfterEach
+ void teardown() {
if (oldEnvVariables != null) {
CommonTestUtils.setEnv(oldEnvVariables, true);
}
}
@Test
- public void testGenerateJvmParameters() {
+ void testGenerateJvmParameters() {
ProcessMemorySpec spec = JvmArgTestingProcessMemorySpec.generate();
String jvmParamsStr = ProcessMemoryUtils.generateJvmParametersStr(spec, true);
Map<String, String> configs = ConfigurationUtils.parseJvmArgString(jvmParamsStr);
- assertThat(configs.size(), is(4));
- assertThat(MemorySize.parse(configs.get("-Xmx")), is(spec.getJvmHeapMemorySize()));
- assertThat(MemorySize.parse(configs.get("-Xms")), is(spec.getJvmHeapMemorySize()));
- assertThat(
- MemorySize.parse(configs.get("-XX:MaxMetaspaceSize=")),
- is(spec.getJvmMetaspaceSize()));
- assertThat(
- MemorySize.parse(configs.get("-XX:MaxDirectMemorySize=")),
- is(spec.getJvmDirectMemorySize()));
+ assertThat(configs).hasSize(4);
+ assertThat(MemorySize.parse(configs.get("-Xmx"))).isEqualTo(spec.getJvmHeapMemorySize());
+ assertThat(MemorySize.parse(configs.get("-Xms"))).isEqualTo(spec.getJvmHeapMemorySize());
+ assertThat(MemorySize.parse(configs.get("-XX:MaxMetaspaceSize=")))
+ .isEqualTo(spec.getJvmMetaspaceSize());
+ assertThat(MemorySize.parse(configs.get("-XX:MaxDirectMemorySize=")))
+ .isEqualTo(spec.getJvmDirectMemorySize());
}
@Test
- public void testGenerateJvmParametersWithoutDirectMemoryLimit() {
+ void testGenerateJvmParametersWithoutDirectMemoryLimit() {
ProcessMemorySpec spec = JvmArgTestingProcessMemorySpec.generate();
String jvmParamsStr = ProcessMemoryUtils.generateJvmParametersStr(spec, false);
Map<String, String> configs = ConfigurationUtils.parseJvmArgString(jvmParamsStr);
- assertThat(configs.size(), is(3));
- assertThat(MemorySize.parse(configs.get("-Xmx")), is(spec.getJvmHeapMemorySize()));
- assertThat(MemorySize.parse(configs.get("-Xms")), is(spec.getJvmHeapMemorySize()));
- assertThat(
- MemorySize.parse(configs.get("-XX:MaxMetaspaceSize=")),
- is(spec.getJvmMetaspaceSize()));
- assertThat(configs.containsKey("-XX:MaxDirectMemorySize="), is(false));
+ assertThat(configs).hasSize(3);
+ assertThat(MemorySize.parse(configs.get("-Xmx"))).isEqualTo(spec.getJvmHeapMemorySize());
+ assertThat(MemorySize.parse(configs.get("-Xms"))).isEqualTo(spec.getJvmHeapMemorySize());
+ assertThat(MemorySize.parse(configs.get("-XX:MaxMetaspaceSize=")))
+ .isEqualTo(spec.getJvmMetaspaceSize());
+ assertThat(configs.containsKey("-XX:MaxDirectMemorySize=")).isFalse();
}
@Test
- public void testConfigTotalFlinkMemory() {
+ void testConfigTotalFlinkMemory() {
MemorySize totalFlinkMemorySize = MemorySize.parse("1g");
Configuration conf = new Configuration();
conf.set(options.getTotalFlinkMemoryOption(), totalFlinkMemorySize);
T processSpec = processSpecFromConfig(conf);
- assertThat(processSpec.getTotalFlinkMemorySize(), is(totalFlinkMemorySize));
+ assertThat(processSpec.getTotalFlinkMemorySize()).isEqualTo(totalFlinkMemorySize);
}
@Test
- public void testConfigTotalProcessMemorySize() {
+ void testConfigTotalProcessMemorySize() {
MemorySize totalProcessMemorySize = MemorySize.parse("2g");
Configuration conf = new Configuration();
conf.set(options.getTotalProcessMemoryOption(), totalProcessMemorySize);
T processSpec = processSpecFromConfig(conf);
- assertThat(processSpec.getTotalProcessMemorySize(), is(totalProcessMemorySize));
+ assertThat(processSpec.getTotalProcessMemorySize()).isEqualTo(totalProcessMemorySize);
}
@Test
- public void testExceptionShouldContainRequiredConfigOptions() {
+ void testExceptionShouldContainRequiredConfigOptions() {
try {
processSpecFromConfig(new Configuration());
} catch (IllegalConfigurationException e) {
options.getRequiredFineGrainedOptions()
- .forEach(option -> assertThat(e.getMessage(), containsString(option.key())));
- assertThat(e.getMessage(), containsString(options.getTotalFlinkMemoryOption().key()));
- assertThat(e.getMessage(), containsString(options.getTotalProcessMemoryOption().key()));
+ .forEach(option -> assertThat(e.getMessage()).contains(option.key()));
+ assertThat(e.getMessage()).contains(options.getTotalFlinkMemoryOption().key());
+ assertThat(e.getMessage()).contains(options.getTotalProcessMemoryOption().key());
Review Comment:
```suggestion
assertThat(e).hasMessageContaining(options.getTotalProcessMemoryOption().key());
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java:
##########
@@ -103,600 +105,624 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/ProcessMemoryUtilsTestBase.java:
##########
@@ -24,29 +24,31 @@
import org.apache.flink.configuration.IllegalConfigurationException;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.core.testutils.CommonTestUtils;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import static org.apache.flink.util.Preconditions.checkNotNull;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.Matchers.greaterThanOrEqualTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.lessThanOrEqualTo;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Base test suite for JM/TM memory calculations to test common methods in {@link
* ProcessMemoryUtils}.
*/
-@SuppressWarnings("AbstractClassExtendsConcreteClass")
-public abstract class ProcessMemoryUtilsTestBase<T extends ProcessMemorySpec> extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/StateHandleStoreUtilsTest.java:
##########
@@ -20,55 +20,53 @@
import org.apache.flink.runtime.persistence.TestingLongStateHandleHelper;
import org.apache.flink.runtime.state.StateObject;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
import org.apache.flink.util.function.RunnableWithException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* {@code StateHandleStoreUtilsTest} tests the utility classes collected in {@link
* StateHandleStoreUtils}.
*/
-public class StateHandleStoreUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java:
##########
@@ -103,600 +105,624 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/SlotSelectionStrategyUtilsTest.java:
##########
@@ -24,39 +24,40 @@
import org.apache.flink.runtime.jobmaster.slotpool.LocationPreferenceSlotSelectionStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.PreviousAllocationSlotSelectionStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.SlotSelectionStrategy;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link SlotSelectionStrategyUtils}. */
-public class SlotSelectionStrategyUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+public class SlotSelectionStrategyUtilsTest {
Review Comment:
```suggestion
class SlotSelectionStrategyUtilsTest {
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/TaskExecutorProcessSpecTest.java:
##########
@@ -22,22 +22,22 @@
import org.apache.flink.api.common.resources.ExternalResource;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Collections;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link TaskExecutorProcessSpec}. */
-public class TaskExecutorProcessSpecTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/SerializedThrowableTest.java:
##########
@@ -86,49 +81,47 @@ public void testSerialization() {
String.format(
"%s: %s",
userException2.getClass().getName(), userException2.getMessage());
- assertEquals(serialized2.getMessage(), result);
+ assertThat(serialized2.getMessage()).isEqualTo(result);
// copy the serialized throwable and make sure everything still works
SerializedThrowable copy = CommonTestUtils.createCopySerializable(serialized);
- assertEquals(
- ExceptionUtils.stringifyException(userException),
- ExceptionUtils.stringifyException(copy));
- assertArrayEquals(userException.getStackTrace(), copy.getStackTrace());
+ assertThat(ExceptionUtils.stringifyException(userException))
+ .isEqualTo(ExceptionUtils.stringifyException(copy));
+ assertThat(userException.getStackTrace()).isEqualTo(copy.getStackTrace());
// deserialize the proper exception
Throwable deserialized = copy.deserializeError(loader);
- assertEquals(clazz, deserialized.getClass());
+ assertThat(clazz).isEqualTo(deserialized.getClass());
Review Comment:
```suggestion
assertThat(deserialized.getClass()).isEqualTo(clazz);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java:
##########
@@ -103,600 +105,624 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("F"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("G"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("F");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("G");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("J"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("K"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("L"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("J");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("K");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("L");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891 "); // with leading and trailing whitespace
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891"); // whitespace after port
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
}
{
expected = "localhost:2891,localhost:2891";
setQuorum(conf, "localhost:2891,localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/StateHandleStoreUtilsTest.java:
##########
@@ -20,55 +20,53 @@
import org.apache.flink.runtime.persistence.TestingLongStateHandleHelper;
import org.apache.flink.runtime.state.StateObject;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
import org.apache.flink.util.function.RunnableWithException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* {@code StateHandleStoreUtilsTest} tests the utility classes collected in {@link
* StateHandleStoreUtils}.
*/
-public class StateHandleStoreUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+public class StateHandleStoreUtilsTest {
Review Comment:
```suggestion
class StateHandleStoreUtilsTest {
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/SlotSelectionStrategyUtilsTest.java:
##########
@@ -24,39 +24,40 @@
import org.apache.flink.runtime.jobmaster.slotpool.LocationPreferenceSlotSelectionStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.PreviousAllocationSlotSelectionStrategy;
import org.apache.flink.runtime.jobmaster.slotpool.SlotSelectionStrategy;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.instanceOf;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link SlotSelectionStrategyUtils}. */
-public class SlotSelectionStrategyUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/StateHandleStoreUtilsTest.java:
##########
@@ -20,55 +20,53 @@
import org.apache.flink.runtime.persistence.TestingLongStateHandleHelper;
import org.apache.flink.runtime.state.StateObject;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
import org.apache.flink.util.function.RunnableWithException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* {@code StateHandleStoreUtilsTest} tests the utility classes collected in {@link
* StateHandleStoreUtils}.
*/
-public class StateHandleStoreUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+public class StateHandleStoreUtilsTest {
@Test
- public void testSerializationAndDeserialization() throws Exception {
+ void testSerializationAndDeserialization() throws Exception {
final TestingLongStateHandleHelper.LongStateHandle original =
new TestingLongStateHandleHelper.LongStateHandle(42L);
byte[] serializedData = StateHandleStoreUtils.serializeOrDiscard(original);
final TestingLongStateHandleHelper.LongStateHandle deserializedInstance =
StateHandleStoreUtils.deserialize(serializedData);
- assertThat(deserializedInstance.getStateSize(), is(original.getStateSize()));
- assertThat(deserializedInstance.getValue(), is(original.getValue()));
+ assertThat(deserializedInstance.getStateSize()).isEqualTo(original.getStateSize());
+ assertThat(deserializedInstance.getValue()).isEqualTo(original.getValue());
}
@Test
- public void testSerializeOrDiscardFailureHandling() throws Exception {
+ void testSerializeOrDiscardFailureHandling() throws Exception {
final AtomicBoolean discardCalled = new AtomicBoolean(false);
final StateObject original =
new FailingSerializationStateObject(() -> discardCalled.set(true));
- try {
- StateHandleStoreUtils.serializeOrDiscard(original);
- fail("An IOException is expected to be thrown.");
- } catch (IOException e) {
- // IOException is expected
- }
+ assertThatThrownBy(() -> StateHandleStoreUtils.serializeOrDiscard(original))
+ .withFailMessage("An IOException is expected to be thrown.")
+ .isInstanceOf(IOException.class);
- assertThat(discardCalled.get(), is(true));
+ assertThat(discardCalled.get()).isTrue();
Review Comment:
```suggestion
assertThat(discardCalled).isTrue();
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java:
##########
@@ -103,600 +105,624 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("F"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("G"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("F");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("G");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("J"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("K"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("L"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("J");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("K");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("L");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -20,23 +20,22 @@
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.HighAvailabilityOptions;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
import org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link ZooKeeperUtils}. */
-public class ZooKeeperUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ReusingKeyGroupedIteratorTest.java:
##########
@@ -103,600 +105,624 @@ public Record next() throws IOException {
}
@Test
- public void testNextKeyOnly() throws Exception {
+ void testNextKeyOnly() throws Exception {
try {
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(
- "KeyGroupedIterator must not have another value.", this.psi.getValues());
-
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isNull();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testFullIterationThroughAllValues() throws IOException {
+ void testFullIterationThroughAllValues() throws IOException {
try {
// Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(1))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(1))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(2))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(2))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
// Key 3, Values C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("D"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("D");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(3))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("F"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("G"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(4))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 4,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("F");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("G");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(4))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(4);
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("J"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("K"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("L"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("J");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("K");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("L");
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse(
- "KeyGroupedIterator must not have another value.",
- this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(
+ this.psi
+ .getComparatorWithCurrentReference()
+ .equalToReference(new Record(new IntValue(5))))
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
try {
this.psi.getValues().next();
- Assert.fail(
+ fail(
"A new KeyGroupedIterator must not have any value available and hence throw an exception on next().");
} catch (NoSuchElementException nseex) {
}
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertNull(this.psi.getValues());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat((Iterable<? extends Record>) this.psi.getValues()).isNull();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testMixedProgress() throws Exception {
+ void testMixedProgress() throws Exception {
try {
// Progression only via nextKey() and hasNext() - Key 1, Value A
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
// Progression only through nextKey() - Key 2, Value B
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
// Progression first though haNext() and next(), then through hasNext() - Key 3, Values
// C, D
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("C"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(3))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 3,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("C");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(3);
// Progression first via next() only, then hasNext() only Key 4, Values E, F, G
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("E"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("E");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
// Key 5, Values H, I, J, K, L
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("H"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
- Assert.assertTrue(
- "KeyGroupedIterator returned a wrong key.",
- this.psi
- .getComparatorWithCurrentReference()
- .equalToReference(new Record(new IntValue(5))));
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 5,
- this.psi.getCurrent().getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("I"),
- this.psi.getValues().next().getField(1, StringValue.class));
- Assert.assertTrue(hasIterator(this.psi.getValues()));
- Assert.assertFalse(hasIterator(this.psi.getValues()));
- Assert.assertTrue(
- "KeyGroupedIterator must have another value.", this.psi.getValues().hasNext());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("H");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getCurrent().getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(5);
+ assertThat(this.psi.getValues().next().getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("I");
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isTrue();
+ assertThat(hasIterator(this.psi.getValues())).isFalse();
+ assertThat(this.psi.getValues().hasNext())
+ .withFailMessage("KeyGroupedIterator must have another value.")
+ .isTrue();
// end
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
- Assert.assertFalse("KeyGroupedIterator must not have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must not have another key.")
+ .isFalse();
} catch (Exception e) {
e.printStackTrace();
- Assert.fail("The test encountered an unexpected exception.");
+ fail("The test encountered an unexpected exception.");
}
}
@Test
- public void testHasNextDoesNotOverweiteCurrentRecord() throws Exception {
+ void testHasNextDoesNotOverwriteCurrentRecord() throws Exception {
try {
Iterator<Record> valsIter = null;
Record rec = null;
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
valsIter = this.psi.getValues();
- Assert.assertNotNull("Returned Iterator must not be null", valsIter);
- Assert.assertTrue(
- "KeyGroupedIterator's value iterator must have another value.",
- valsIter.hasNext());
+ assertThat(valsIter).withFailMessage("Returned Iterator must not be null").isNotNull();
+ assertThat(valsIter.hasNext())
+ .withFailMessage("KeyGroupedIterator's value iterator must have another value.")
+ .isTrue();
rec = valsIter.next();
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- rec.getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- rec.getField(1, StringValue.class));
- Assert.assertFalse("KeyGroupedIterator must have another value.", valsIter.hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 1,
- rec.getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("A"),
- rec.getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator's value iterator must not have another value.",
- valsIter.hasNext());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
+ assertThat(rec.getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(rec.getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(valsIter.hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
+ assertThat(rec.getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isOne();
+ assertThat(rec.getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("A");
+ assertThat(valsIter.hasNext())
+ .withFailMessage(
+ "KeyGroupedIterator's value iterator must not have another value.")
+ .isFalse();
+
+ assertThat(this.psi.nextKey())
+ .withFailMessage("KeyGroupedIterator must have another key.")
+ .isTrue();
valsIter = this.psi.getValues();
- Assert.assertNotNull("Returned Iterator must not be null", valsIter);
- Assert.assertTrue(
- "KeyGroupedIterator's value iterator must have another value.",
- valsIter.hasNext());
+ assertThat(valsIter).withFailMessage("Returned Iterator must not be null").isNotNull();
+ assertThat(valsIter.hasNext())
+ .withFailMessage("KeyGroupedIterator's value iterator must have another value.")
+ .isTrue();
rec = valsIter.next();
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- rec.getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- rec.getField(1, StringValue.class));
- Assert.assertFalse("KeyGroupedIterator must have another value.", valsIter.hasNext());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong key.",
- 2,
- rec.getField(0, IntValue.class).getValue());
- Assert.assertEquals(
- "KeyGroupedIterator returned a wrong value.",
- new StringValue("B"),
- rec.getField(1, StringValue.class));
- Assert.assertFalse(
- "KeyGroupedIterator's value iterator must not have another value.",
- valsIter.hasNext());
-
- Assert.assertTrue("KeyGroupedIterator must have another key.", this.psi.nextKey());
+ assertThat(rec.getField(0, IntValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong key.")
+ .isEqualTo(2);
+ assertThat(rec.getField(1, StringValue.class).getValue())
+ .withFailMessage("KeyGroupedIterator returned a wrong value.")
+ .isEqualTo("B");
+ assertThat(valsIter.hasNext())
+ .withFailMessage("KeyGroupedIterator must not have another value.")
+ .isFalse();
Review Comment:
```suggestion
assertThat(valsIter)
.withFailMessage("KeyGroupedIterator must not have another value.")
.isExhausted();
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891 "); // with leading and trailing whitespace
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891"); // whitespace after port
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
}
{
expected = "localhost:2891,localhost:2891";
setQuorum(conf, "localhost:2891,localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost:2891, localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891, localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
Same as above.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/bash/FlinkConfigLoaderTest.java:
##########
@@ -20,73 +20,73 @@
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.Configuration;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.testutils.junit.utils.TempDirUtils;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.io.FileWriter;
+import java.io.IOException;
import static org.apache.flink.configuration.ConfigOptions.key;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link FlinkConfigLoader}. */
-public class FlinkConfigLoaderTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/bash/BashJavaUtilsTest.java:
##########
@@ -22,26 +22,27 @@
import org.apache.flink.configuration.ConfigurationUtils;
import org.apache.flink.configuration.JobManagerOptions;
import org.apache.flink.configuration.MemorySize;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.Map;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link BashJavaUtils}. */
-public class BashJavaUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -105,13 +104,13 @@ public void testStartCuratorFrameworkFailed() throws Exception {
})
.namespace("flink");
ZooKeeperUtils.startCuratorFramework(curatorFrameworkBuilder, handler);
- Assert.assertEquals(errorMsg, handler.getErrorFuture().get().getMessage());
+ assertThat(errorMsg).isEqualTo(handler.getErrorFuture().get().getMessage());
Review Comment:
```suggestion
assertThat(handler.getErrorFuture().get().getMessage()).isEqualTo(errorMsg);
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/config/memory/ManagedMemoryUtilsTest.java:
##########
@@ -34,12 +36,12 @@
import java.util.Optional;
import java.util.Set;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Tests for {@link ManagedMemoryUtils}. */
-public class ManagedMemoryUtilsTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
Review Comment:
```suggestion
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/util/ZooKeeperUtilsTest.java:
##########
@@ -59,40 +58,40 @@ public void testZooKeeperEnsembleConnectStringConfiguration() throws Exception {
setQuorum(conf, expected);
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891 "); // with leading and trailing whitespace
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891"); // whitespace after port
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
}
{
expected = "localhost:2891,localhost:2891";
setQuorum(conf, "localhost:2891,localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost:2891, localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, "localhost :2891, localhost:2891");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
setQuorum(conf, " localhost:2891, localhost:2891 ");
actual = ZooKeeperUtils.getZooKeeperEnsemble(conf);
- assertEquals(expected, actual);
+ assertThat(expected).isEqualTo(actual);
Review Comment:
Same as above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org