This is an automated email from the ASF dual-hosted git repository.

jonyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 53d23b203 fix issue2461 (#2462)
53d23b203 is described below

commit 53d23b203c2b5e7225c5adba2c941e65358f0dde
Author: jonyangx <[email protected]>
AuthorDate: Wed Dec 7 11:46:32 2022 +0800

    fix issue2461 (#2462)
    
    Co-authored-by: jonyangx <[email protected]>
---
 .../runtime/admin/controller/ClientManageControllerTest.java | 12 +++++++++---
 .../admin/handler/QueryRecommendEventMeshHandlerTest.java    | 10 ++++++----
 .../admin/handler/RedirectClientByIpPortHandlerTest.java     |  2 +-
 .../admin/handler/RedirectClientByPathHandlerTest.java       |  8 ++++----
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/controller/ClientManageControllerTest.java
 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/controller/ClientManageControllerTest.java
index a7303bf97..b728ab32f 100644
--- 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/controller/ClientManageControllerTest.java
+++ 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/controller/ClientManageControllerTest.java
@@ -33,6 +33,7 @@ import 
org.apache.eventmesh.webhook.api.WebHookConfigOperation;
 
 import java.io.IOException;
 
+import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.MockedStatic;
 import org.mockito.Mockito;
@@ -42,7 +43,7 @@ import com.sun.net.httpserver.HttpServer;
 public class ClientManageControllerTest {
 
     @Test
-    public void testStart() throws IOException {
+    public void testStart() {
         EventMeshTCPServer eventMeshTCPServer = mock(EventMeshTCPServer.class);
         AdminController adminController = mock(AdminController.class);
         EventMeshTCPConfiguration tcpConfiguration = 
mock(EventMeshTCPConfiguration.class);
@@ -58,8 +59,13 @@ public class ClientManageControllerTest {
         try (MockedStatic<HttpServer> dummyStatic = 
Mockito.mockStatic(HttpServer.class)) {
             HttpServer server = mock(HttpServer.class);
             dummyStatic.when(() -> HttpServer.create(any(), 
anyInt())).thenReturn(server);
-            Mockito.doNothing().when(adminController).run(server);
-            controller.start();
+            try {
+                Mockito.doNothing().when(adminController).run(server);
+                controller.start();
+            } catch (IOException e) {
+                Assert.fail(e.getMessage());
+            }
+
         }
     }
 }
\ No newline at end of file
diff --git 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandlerTest.java
 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandlerTest.java
index 57b895384..6b93446ad 100644
--- 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandlerTest.java
+++ 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandlerTest.java
@@ -65,14 +65,16 @@ public class QueryRecommendEventMeshHandlerTest {
         HttpHandlerManager httpHandlerManager = new HttpHandlerManager();
         QueryRecommendEventMeshHandler handler = new 
QueryRecommendEventMeshHandler(eventMeshTCPServer, httpHandlerManager);
 
+        String returnValue = "result";
+
         // case 1: normal case
         tcpConfiguration.eventMeshServerRegistryEnable = true;
         when(httpExchange.getResponseBody()).thenReturn(outputStream);
         try (MockedConstruction<EventMeshRecommendImpl> ignored = 
mockConstruction(EventMeshRecommendImpl.class,
-            (mock, context) -> 
when(mock.calculateRecommendEventMesh(anyString(), 
anyString())).thenReturn("result"))) {
+            (mock, context) -> 
when(mock.calculateRecommendEventMesh(anyString(), 
anyString())).thenReturn(returnValue))) {
             handler.handle(httpExchange);
             String response = outputStream.toString();
-            Assert.assertEquals("result", response);
+            Assert.assertEquals(returnValue, response);
         }
 
         // case 2: params illegal
@@ -91,10 +93,10 @@ public class QueryRecommendEventMeshHandlerTest {
         doThrow(new IOException()).when(outputStream).close();
         when(httpExchange.getResponseBody()).thenReturn(outputStream);
         try (MockedConstruction<EventMeshRecommendImpl> ignored = 
mockConstruction(EventMeshRecommendImpl.class,
-            (mock, context) -> 
when(mock.calculateRecommendEventMesh(anyString(), 
anyString())).thenReturn("result"))) {
+            (mock, context) -> 
when(mock.calculateRecommendEventMesh(anyString(), 
anyString())).thenReturn(returnValue))) {
             handler.handle(httpExchange);
             String response = outputStream.toString();
-            Assert.assertNotEquals("result", response);
+            Assert.assertNotEquals(returnValue, response);
         }
     }
 }
\ No newline at end of file
diff --git 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java
 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java
index 46146ea5f..aa16d988d 100644
--- 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java
+++ 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java
@@ -36,7 +36,7 @@ import com.sun.net.httpserver.HttpExchange;
 
 public class RedirectClientByIpPortHandlerTest {
 
-    private RedirectClientByIpPortHandler redirectClientByIpPortHandler;
+    private static transient RedirectClientByIpPortHandler 
redirectClientByIpPortHandler;
 
     @Before
     public void init() {
diff --git 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandlerTest.java
 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandlerTest.java
index e7f18240f..286b1f0fb 100644
--- 
a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandlerTest.java
+++ 
b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandlerTest.java
@@ -59,7 +59,7 @@ import com.sun.net.httpserver.HttpExchange;
 public class RedirectClientByPathHandlerTest {
 
     @Mock
-    private EventMeshTCPServer eventMeshTCPServer;
+    private static transient EventMeshTCPServer eventMeshTCPServer;
 
     @Before
     public void init() {
@@ -93,7 +93,7 @@ public class RedirectClientByPathHandlerTest {
         try (MockedStatic<NetUtils> netUtilsMockedStatic = 
Mockito.mockStatic(NetUtils.class)) {
             Map<String, String> queryStringInfo = new HashMap<>();
             queryStringInfo.put(EventMeshConstants.MANAGE_PATH, 
EventMeshConstants.MANAGE_PATH);
-            queryStringInfo.put(EventMeshConstants.MANAGE_DEST_IP, 
"127.0.0.1");
+            queryStringInfo.put(EventMeshConstants.MANAGE_DEST_IP, 
"localhost");
             queryStringInfo.put(EventMeshConstants.MANAGE_DEST_PORT, "8080");
             netUtilsMockedStatic.when(() -> 
NetUtils.formData2Dic(anyString())).thenReturn(queryStringInfo);
 
@@ -101,7 +101,7 @@ public class RedirectClientByPathHandlerTest {
             when(mockExchange.getResponseBody()).thenReturn(outputStream);
             try (MockedStatic<EventMeshTcp2Client> clientMockedStatic = 
Mockito.mockStatic(EventMeshTcp2Client.class)) {
                 clientMockedStatic.when(() -> 
EventMeshTcp2Client.redirectClient2NewEventMesh(any(), anyString(), anyInt(), 
any(),
-                    any())).thenReturn("redirectResult");
+                        any())).thenReturn("redirectResult");
                 redirectClientByPathHandler.handle(mockExchange);
                 String response = 
outputStream.toString(StandardCharsets.UTF_8.name());
                 Assert.assertTrue(response.startsWith("redirectClientByPath 
success!"));
@@ -122,7 +122,7 @@ public class RedirectClientByPathHandlerTest {
             when(mockExchange.getResponseBody()).thenReturn(outputStream);
             try (MockedStatic<EventMeshTcp2Client> clientMockedStatic = 
Mockito.mockStatic(EventMeshTcp2Client.class)) {
                 clientMockedStatic.when(() -> 
EventMeshTcp2Client.redirectClient2NewEventMesh(any(), anyString(), anyInt(), 
any(),
-                    any())).thenThrow(new RuntimeException());
+                        any())).thenThrow(new RuntimeException());
                 redirectClientByPathHandler.handle(mockExchange);
                 String response = outputStream.toString();
                 Assert.assertTrue(response.startsWith("redirectClientByPath 
fail!"));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to