You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by gu...@apache.org on 2022/03/18 03:00:35 UTC
[flink] 01/02: [hotfix][tests] Update junit4 to junit5 in endpoint related test case
This is an automated email from the ASF dual-hosted git repository.
guoyangze pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 7bf97d5e84f2156c24fbfef37de1d159be12143d
Author: shammon <zj...@gmail.com>
AuthorDate: Tue Feb 22 11:13:30 2022 +0800
[hotfix][tests] Update junit4 to junit5 in endpoint related test case
---
.../concurrent/ScheduledFutureAdapterTest.java | 78 ++++++++++++----------
.../flink/runtime/rpc/FencedRpcEndpointTest.java | 33 ++++-----
.../apache/flink/runtime/rpc/RpcEndpointTest.java | 71 +++++++++++---------
3 files changed, 98 insertions(+), 84 deletions(-)
diff --git a/flink-rpc/flink-rpc-core/src/test/java/org/apache/flink/runtime/concurrent/ScheduledFutureAdapterTest.java b/flink-rpc/flink-rpc-core/src/test/java/org/apache/flink/runtime/concurrent/ScheduledFutureAdapterTest.java
index 6bd5ee9..ec0138f 100644
--- a/flink-rpc/flink-rpc-core/src/test/java/org/apache/flink/runtime/concurrent/ScheduledFutureAdapterTest.java
+++ b/flink-rpc/flink-rpc-core/src/test/java/org/apache/flink/runtime/concurrent/ScheduledFutureAdapterTest.java
@@ -18,24 +18,28 @@
package org.apache.flink.runtime.concurrent;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.Assert;
-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 javax.annotation.Nonnull;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
/** Unit tests for {@link ScheduledFutureAdapter}. */
-public class ScheduledFutureAdapterTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+public class ScheduledFutureAdapterTest {
private ScheduledFutureAdapter<Integer> objectUnderTest;
private TestFuture innerDelegate;
- @Before
+ @BeforeEach
public void before() {
this.innerDelegate = new TestFuture();
this.objectUnderTest =
@@ -45,62 +49,62 @@ public class ScheduledFutureAdapterTest extends TestLogger {
@Test
public void testForwardedMethods() throws Exception {
- Assert.assertEquals((Integer) 4711, objectUnderTest.get());
- Assert.assertEquals(1, innerDelegate.getGetInvocationCount());
+ assertEquals((Integer) 4711, objectUnderTest.get());
+ assertEquals(1, innerDelegate.getGetInvocationCount());
- Assert.assertEquals((Integer) 4711, objectUnderTest.get(42L, TimeUnit.SECONDS));
- Assert.assertEquals(1, innerDelegate.getGetTimeoutInvocationCount());
+ assertEquals((Integer) 4711, objectUnderTest.get(42L, TimeUnit.SECONDS));
+ assertEquals(1, innerDelegate.getGetTimeoutInvocationCount());
- Assert.assertEquals(innerDelegate.isCancelExpected(), objectUnderTest.cancel(true));
- Assert.assertEquals(1, innerDelegate.getCancelInvocationCount());
+ assertEquals(innerDelegate.isCancelExpected(), objectUnderTest.cancel(true));
+ assertEquals(1, innerDelegate.getCancelInvocationCount());
innerDelegate.setCancelResult(!innerDelegate.isCancelExpected());
- Assert.assertEquals(innerDelegate.isCancelExpected(), objectUnderTest.cancel(true));
- Assert.assertEquals(2, innerDelegate.getCancelInvocationCount());
+ assertEquals(innerDelegate.isCancelExpected(), objectUnderTest.cancel(true));
+ assertEquals(2, innerDelegate.getCancelInvocationCount());
- Assert.assertEquals(innerDelegate.isCancelledExpected(), objectUnderTest.isCancelled());
- Assert.assertEquals(1, innerDelegate.getIsCancelledInvocationCount());
+ assertEquals(innerDelegate.isCancelledExpected(), objectUnderTest.isCancelled());
+ assertEquals(1, innerDelegate.getIsCancelledInvocationCount());
innerDelegate.setIsCancelledResult(!innerDelegate.isCancelledExpected());
- Assert.assertEquals(innerDelegate.isCancelledExpected(), objectUnderTest.isCancelled());
- Assert.assertEquals(2, innerDelegate.getIsCancelledInvocationCount());
+ assertEquals(innerDelegate.isCancelledExpected(), objectUnderTest.isCancelled());
+ assertEquals(2, innerDelegate.getIsCancelledInvocationCount());
- Assert.assertEquals(innerDelegate.isDoneExpected(), objectUnderTest.isDone());
- Assert.assertEquals(1, innerDelegate.getIsDoneInvocationCount());
+ assertEquals(innerDelegate.isDoneExpected(), objectUnderTest.isDone());
+ assertEquals(1, innerDelegate.getIsDoneInvocationCount());
innerDelegate.setIsDoneExpected(!innerDelegate.isDoneExpected());
- Assert.assertEquals(innerDelegate.isDoneExpected(), objectUnderTest.isDone());
- Assert.assertEquals(2, innerDelegate.getIsDoneInvocationCount());
+ assertEquals(innerDelegate.isDoneExpected(), objectUnderTest.isDone());
+ assertEquals(2, innerDelegate.getIsDoneInvocationCount());
}
@Test
public void testCompareToEqualsHashCode() {
- Assert.assertEquals(0, objectUnderTest.compareTo(objectUnderTest));
- Assert.assertEquals(objectUnderTest, objectUnderTest);
+ assertEquals(0, objectUnderTest.compareTo(objectUnderTest));
+ assertEquals(objectUnderTest, objectUnderTest);
ScheduledFutureAdapter<?> other =
getDeepCopyWithAdjustedTime(0L, objectUnderTest.getTieBreakerUid());
- Assert.assertEquals(0, objectUnderTest.compareTo(other));
- Assert.assertEquals(0, other.compareTo(objectUnderTest));
- Assert.assertEquals(objectUnderTest, other);
- Assert.assertEquals(objectUnderTest.hashCode(), other.hashCode());
+ assertEquals(0, objectUnderTest.compareTo(other));
+ assertEquals(0, other.compareTo(objectUnderTest));
+ assertEquals(objectUnderTest, other);
+ assertEquals(objectUnderTest.hashCode(), other.hashCode());
other = getDeepCopyWithAdjustedTime(0L, objectUnderTest.getTieBreakerUid() + 1L);
- Assert.assertEquals(-1, Integer.signum(objectUnderTest.compareTo(other)));
- Assert.assertEquals(+1, Integer.signum(other.compareTo(objectUnderTest)));
- Assert.assertNotEquals(objectUnderTest, other);
+ assertEquals(-1, Integer.signum(objectUnderTest.compareTo(other)));
+ assertEquals(+1, Integer.signum(other.compareTo(objectUnderTest)));
+ assertNotEquals(objectUnderTest, other);
other = getDeepCopyWithAdjustedTime(+1L, objectUnderTest.getTieBreakerUid());
- Assert.assertEquals(-1, Integer.signum(objectUnderTest.compareTo(other)));
- Assert.assertEquals(+1, Integer.signum(other.compareTo(objectUnderTest)));
- Assert.assertNotEquals(objectUnderTest, other);
+ assertEquals(-1, Integer.signum(objectUnderTest.compareTo(other)));
+ assertEquals(+1, Integer.signum(other.compareTo(objectUnderTest)));
+ assertNotEquals(objectUnderTest, other);
other = getDeepCopyWithAdjustedTime(-1L, objectUnderTest.getTieBreakerUid());
- Assert.assertEquals(+1, Integer.signum(objectUnderTest.compareTo(other)));
- Assert.assertEquals(-1, Integer.signum(other.compareTo(objectUnderTest)));
- Assert.assertNotEquals(objectUnderTest, other);
+ assertEquals(+1, Integer.signum(objectUnderTest.compareTo(other)));
+ assertEquals(-1, Integer.signum(other.compareTo(objectUnderTest)));
+ assertNotEquals(objectUnderTest, other);
}
private ScheduledFutureAdapter<Integer> getDeepCopyWithAdjustedTime(long nanoAdjust, long uid) {
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/FencedRpcEndpointTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/FencedRpcEndpointTest.java
index 4dc2710..24b1c1b 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/FencedRpcEndpointTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/FencedRpcEndpointTest.java
@@ -25,11 +25,12 @@ import org.apache.flink.runtime.rpc.exceptions.FencingTokenException;
import org.apache.flink.runtime.rpc.exceptions.RpcRuntimeException;
import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.util.FlinkException;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -38,24 +39,26 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
-public class FencedRpcEndpointTest extends TestLogger {
+/** Tests for the FencedRpcEndpoint. */
+@ExtendWith(TestLoggerExtension.class)
+public class FencedRpcEndpointTest {
private static final Time timeout = Time.seconds(10L);
private static RpcService rpcService;
- @BeforeClass
+ @BeforeAll
public static void setup() {
rpcService = new TestingRpcService();
}
- @AfterClass
+ @AfterAll
public static void teardown()
throws ExecutionException, InterruptedException, TimeoutException {
if (rpcService != null) {
@@ -92,8 +95,8 @@ public class FencedRpcEndpointTest extends TestLogger {
}
assertFalse(
- "Setting fencing token from outside the main thread did not fail as expected.",
- failed);
+ failed,
+ "Setting fencing token from outside the main thread did not fail as expected.");
assertNull(fencedTestingEndpoint.getFencingToken());
CompletableFuture<Acknowledge> setFencingFuture =
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/RpcEndpointTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/RpcEndpointTest.java
index eaf573d..baec000 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/RpcEndpointTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rpc/RpcEndpointTest.java
@@ -20,11 +20,12 @@ package org.apache.flink.runtime.rpc;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.configuration.Configuration;
-import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.TestLoggerExtension;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.time.Duration;
import java.util.concurrent.Callable;
@@ -35,25 +36,26 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
/** Tests for the RpcEndpoint, its self gateways and MainThreadExecutor scheduling command. */
-public class RpcEndpointTest extends TestLogger {
+@ExtendWith(TestLoggerExtension.class)
+public class RpcEndpointTest {
private static final Time TIMEOUT = Time.seconds(10L);
private static RpcService rpcService = null;
- @BeforeClass
+ @BeforeAll
public static void setup() throws Exception {
rpcService = RpcSystem.load().localServiceBuilder(new Configuration()).createAndStart();
}
- @AfterClass
+ @AfterAll
public static void teardown() throws Exception {
rpcService.stopService().get();
}
@@ -84,21 +86,26 @@ public class RpcEndpointTest extends TestLogger {
* Tests that we cannot accidentally obtain a wrong self gateway type which is not implemented
* by the RpcEndpoint.
*/
- @Test(expected = RuntimeException.class)
- public void testWrongSelfGateway() throws Exception {
- int expectedValue = 1337;
- BaseEndpoint baseEndpoint = new BaseEndpoint(rpcService, expectedValue);
-
- try {
- baseEndpoint.start();
-
- DifferentGateway differentGateway = baseEndpoint.getSelfGateway(DifferentGateway.class);
-
- fail(
- "Expected to fail with a RuntimeException since we requested the wrong gateway type.");
- } finally {
- RpcUtils.terminateRpcEndpoint(baseEndpoint, TIMEOUT);
- }
+ @Test
+ public void testWrongSelfGateway() {
+ assertThrows(
+ RuntimeException.class,
+ () -> {
+ int expectedValue = 1337;
+ BaseEndpoint baseEndpoint = new BaseEndpoint(rpcService, expectedValue);
+
+ try {
+ baseEndpoint.start();
+
+ DifferentGateway differentGateway =
+ baseEndpoint.getSelfGateway(DifferentGateway.class);
+
+ fail(
+ "Expected to fail with a RuntimeException since we requested the wrong gateway type.");
+ } finally {
+ RpcUtils.terminateRpcEndpoint(baseEndpoint, TIMEOUT);
+ }
+ });
}
/**
@@ -142,7 +149,7 @@ public class RpcEndpointTest extends TestLogger {
try {
endpoint.start();
- assertThat(gateway.queryIsRunningFlag().get(), is(true));
+ assertTrue(gateway.queryIsRunningFlag().get());
} finally {
RpcUtils.terminateRpcEndpoint(endpoint, TIMEOUT);
}
@@ -161,7 +168,7 @@ public class RpcEndpointTest extends TestLogger {
endpoint.start();
CompletableFuture<Void> terminationFuture = endpoint.closeAndWaitUntilOnStopCalled();
- assertThat(gateway.queryIsRunningFlag().get(), is(false));
+ assertFalse(gateway.queryIsRunningFlag().get());
stopFuture.complete(null);
terminationFuture.get(TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
@@ -324,7 +331,7 @@ public class RpcEndpointTest extends TestLogger {
scheduler.accept(mainThreadExecutor, expectedDelay);
- assertThat(actualDelayMsFuture.get(), is(expectedDelay.toMillis()));
+ assertEquals(actualDelayMsFuture.get(), expectedDelay.toMillis());
}
/**
@@ -376,7 +383,7 @@ public class RpcEndpointTest extends TestLogger {
final Throwable throwable = throwableFuture.get();
assertNotNull(throwable);
- assertThat(throwable, instanceOf(TimeoutException.class));
+ assertTrue(throwable instanceof TimeoutException);
} finally {
latch.countDown();
RpcUtils.terminateRpcEndpoint(endpoint, TIMEOUT);