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 2023/03/09 06:07:51 UTC
[flink] 01/02: [hotfix] Migrate AbstractHaServicesTest to JUnit 5 and AssertJ.
This is an automated email from the ASF dual-hosted git repository.
guoweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit eb66e6d18ec628fba5129b2bde1af264d5085eea
Author: Zhanghao Chen <m1...@outlook.com>
AuthorDate: Tue Mar 7 23:15:33 2023 +0800
[hotfix] Migrate AbstractHaServicesTest to JUnit 5 and AssertJ.
---
.../highavailability/AbstractHaServicesTest.java | 39 ++++++++--------------
1 file changed, 14 insertions(+), 25 deletions(-)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/AbstractHaServicesTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/AbstractHaServicesTest.java
index a6f9729c7c2..90a642f325d 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/AbstractHaServicesTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/AbstractHaServicesTest.java
@@ -28,12 +28,11 @@ import org.apache.flink.runtime.leaderelection.LeaderElectionDriverFactory;
import org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService;
import org.apache.flink.runtime.testutils.TestingJobResultStore;
import org.apache.flink.util.FlinkException;
-import org.apache.flink.util.TestLogger;
import org.apache.flink.util.concurrent.Executors;
import org.apache.flink.util.function.RunnableWithException;
import org.apache.flink.util.function.ThrowingConsumer;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -42,20 +41,18 @@ import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.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;
/** Tests for the {@link AbstractHaServices}. */
-public class AbstractHaServicesTest extends TestLogger {
+class AbstractHaServicesTest {
/**
* Tests that we first delete all pointers from the HA services before deleting the blobs. See
* FLINK-22014 for more details.
*/
@Test
- public void testCloseAndCleanupAllDataDeletesBlobsAfterCleaningUpHAData() throws Exception {
+ void testCloseAndCleanupAllDataDeletesBlobsAfterCleaningUpHAData() throws Exception {
final Queue<CloseOperations> closeOperations = new ArrayDeque<>(3);
final TestingBlobStoreService testingBlobStoreService =
@@ -72,12 +69,10 @@ public class AbstractHaServicesTest extends TestLogger {
haServices.closeAndCleanupAllData();
- assertThat(
- closeOperations,
- contains(
- CloseOperations.HA_CLEANUP,
- CloseOperations.HA_CLOSE,
- CloseOperations.BLOB_CLEANUP_AND_CLOSE));
+ assertThat(closeOperations).contains(
+ CloseOperations.HA_CLEANUP,
+ CloseOperations.HA_CLOSE,
+ CloseOperations.BLOB_CLEANUP_AND_CLOSE);
}
/**
@@ -85,7 +80,7 @@ public class AbstractHaServicesTest extends TestLogger {
* services. See FLINK-22014 for more details.
*/
@Test
- public void testCloseAndCleanupAllDataDoesNotDeleteBlobsIfCleaningUpHADataFails() {
+ void testCloseAndCleanupAllDataDoesNotDeleteBlobsIfCleaningUpHADataFails() {
final Queue<CloseOperations> closeOperations = new ArrayDeque<>(3);
final TestingBlobStoreService testingBlobStoreService =
@@ -102,18 +97,12 @@ public class AbstractHaServicesTest extends TestLogger {
},
ignored -> {});
- try {
- haServices.closeAndCleanupAllData();
- fail("Expected that the close operation fails.");
- } catch (Exception expected) {
-
- }
-
- assertThat(closeOperations, contains(CloseOperations.HA_CLOSE, CloseOperations.BLOB_CLOSE));
+ assertThatThrownBy(haServices::closeAndCleanupAllData).isInstanceOf(FlinkException.class);
+ assertThat(closeOperations).contains(CloseOperations.HA_CLOSE, CloseOperations.BLOB_CLOSE);
}
@Test
- public void testCleanupJobData() throws Exception {
+ void testCleanupJobData() throws Exception {
final Queue<CloseOperations> closeOperations = new ArrayDeque<>(3);
final TestingBlobStoreService testingBlobStoreService =
new TestingBlobStoreService(closeOperations);
@@ -132,7 +121,7 @@ public class AbstractHaServicesTest extends TestLogger {
haServices.globalCleanupAsync(jobID, Executors.directExecutor()).join();
JobID jobIDCleaned = jobCleanupFuture.get();
- assertThat(jobIDCleaned, is(jobID));
+ assertThat(jobIDCleaned).isEqualTo(jobID);
}
private enum CloseOperations {