From bfd5ca19ba2e7fa2df465c807d923f951707c024 Mon Sep 17 00:00:00 2001 From: Jiang Date: Fri, 21 Nov 2025 03:01:52 +0800 Subject: [PATCH 1/2] Add unit test case for StandaloneHaServices constructor --- .../standalone/StandaloneHaServices.java | 2 +- .../standalone/StandaloneHaServicesTest.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServices.java b/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServices.java index 38a508d02538c..3cbd66bbba4ac 100644 --- a/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServices.java +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServices.java @@ -61,7 +61,7 @@ public StandaloneHaServices( checkNotNull(resourceManagerAddress, "resourceManagerAddress"); this.dispatcherAddress = checkNotNull(dispatcherAddress, "dispatcherAddress"); this.clusterRestEndpointAddress = - checkNotNull(clusterRestEndpointAddress, clusterRestEndpointAddress); + checkNotNull(clusterRestEndpointAddress, "clusterRestEndpointAddress"); } // ------------------------------------------------------------------------ diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java index d31b763820a36..c08514a9f6f6a 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java @@ -30,6 +30,8 @@ import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -141,4 +143,28 @@ public void testJobMasterLeaderRetrieval() throws Exception { .notifyLeaderAddress( eq(jobManagerAddress2), eq(HighAvailabilityServices.DEFAULT_LEADER_ID)); } + + /** + * Tests that the constructor properly validates null parameters and provides meaningful error messages. + */ + @Test + public void testConstructorNullValidation() { + // Test null resourceManagerAddress + Exception exception = assertThrows( + NullPointerException.class, + () -> new StandaloneHaServices(null, dispatcherAddress, webMonitorAddress)); + assertTrue(exception.getMessage().contains("resourceManagerAddress")); + + // Test null dispatcherAddress + exception = assertThrows( + NullPointerException.class, + () -> new StandaloneHaServices(resourceManagerAddress, null, webMonitorAddress)); + assertTrue(exception.getMessage().contains("dispatcherAddress")); + + // Test null clusterRestEndpointAddress + exception = assertThrows( + NullPointerException.class, + () -> new StandaloneHaServices(resourceManagerAddress, dispatcherAddress, null)); + assertTrue(exception.getMessage().contains("clusterRestEndpointAddress")); + } } From 0b886472841a9062bf351496da0a1d935df31efc Mon Sep 17 00:00:00 2001 From: Jiang Date: Fri, 21 Nov 2025 12:55:21 +0800 Subject: [PATCH 2/2] apply spotless format --- .../standalone/StandaloneHaServicesTest.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java index c08514a9f6f6a..7749f2fe91a59 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/highavailability/nonha/standalone/StandaloneHaServicesTest.java @@ -145,26 +145,34 @@ public void testJobMasterLeaderRetrieval() throws Exception { } /** - * Tests that the constructor properly validates null parameters and provides meaningful error messages. + * Tests that the constructor properly validates null parameters and provides meaningful error + * messages. */ @Test public void testConstructorNullValidation() { // Test null resourceManagerAddress - Exception exception = assertThrows( - NullPointerException.class, - () -> new StandaloneHaServices(null, dispatcherAddress, webMonitorAddress)); + Exception exception = + assertThrows( + NullPointerException.class, + () -> new StandaloneHaServices(null, dispatcherAddress, webMonitorAddress)); assertTrue(exception.getMessage().contains("resourceManagerAddress")); // Test null dispatcherAddress - exception = assertThrows( - NullPointerException.class, - () -> new StandaloneHaServices(resourceManagerAddress, null, webMonitorAddress)); + exception = + assertThrows( + NullPointerException.class, + () -> + new StandaloneHaServices( + resourceManagerAddress, null, webMonitorAddress)); assertTrue(exception.getMessage().contains("dispatcherAddress")); // Test null clusterRestEndpointAddress - exception = assertThrows( - NullPointerException.class, - () -> new StandaloneHaServices(resourceManagerAddress, dispatcherAddress, null)); + exception = + assertThrows( + NullPointerException.class, + () -> + new StandaloneHaServices( + resourceManagerAddress, dispatcherAddress, null)); assertTrue(exception.getMessage().contains("clusterRestEndpointAddress")); } }