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

liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b42718a6e fix non deterministic test (#6229)
6b42718a6e is described below

commit 6b42718a6ee9027b003b76170a2cb02a269cf26b
Author: Ann (Huei) Chen <[email protected]>
AuthorDate: Wed Nov 19 16:40:56 2025 -0600

    fix non deterministic test (#6229)
---
 .../WebsocketDataChangedListenerTest.java          | 101 ++++++++++++++++++---
 1 file changed, 86 insertions(+), 15 deletions(-)

diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketDataChangedListenerTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketDataChangedListenerTest.java
index 27721ffa99..e439d9d624 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketDataChangedListenerTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/listener/websocket/WebsocketDataChangedListenerTest.java
@@ -38,6 +38,12 @@ import java.util.ArrayList;
 import java.util.List;
 
 import static org.mockito.Mockito.mockStatic;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 /**
  * Data Change WebSocketListener Test.
@@ -74,11 +80,24 @@ public final class WebsocketDataChangedListenerTest {
     public void testOnPluginChanged() {
         String message = 
"{\"groupType\":\"PLUGIN\",\"eventType\":\"UPDATE\",\"data\":[{\"config\":\"{\\\\\\\"model\\\\\\\":\\\\\\\"black\\\\\\\"}\","
                 + 
"\"role\":\"1\",\"id\":\"2\",\"name\":\"waf\",\"enabled\":true,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
-        MockedStatic.Verification verification = () -> 
WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, 
DataEventTypeEnum.UPDATE);
         try (MockedStatic<WebsocketCollector> mockedStatic = 
mockStatic(WebsocketCollector.class)) {
-            mockedStatic.when(verification).thenAnswer((Answer<Void>) 
invocation -> null);
+            mockedStatic.when(() -> WebsocketCollector.send(anyString(), 
anyString(), any()))
+                .thenAnswer(invocation -> null);
             websocketDataChangedListener.onPluginChanged(pluginDataList, 
DataEventTypeEnum.UPDATE);
-            mockedStatic.verify(verification);
+            mockedStatic.verify(() -> WebsocketCollector.send(
+                eq(Constants.SYS_DEFAULT_NAMESPACE_ID),
+                argThat(actualMsg -> {
+                    try {
+                        ObjectMapper mapper = new ObjectMapper();
+                        JsonNode expectedJson = mapper.readTree(message);
+                        JsonNode actualJson = mapper.readTree(actualMsg);
+                        return expectedJson.equals(actualJson);
+                    } catch (Exception e) {
+                        return false;
+                    }
+                }),
+                eq(DataEventTypeEnum.UPDATE)
+            ));
         }
     }
 
@@ -98,16 +117,29 @@ public final class WebsocketDataChangedListenerTest {
                 + 
"\\\\\\\"weight\\\\\\\":\\\\\\\"49\\\\\\\"}]\",\"conditionList\":[{\"paramType\":\"uri\","
                 + 
"\"operator\":\"match\",\"paramName\":\"/\",\"paramValue\":\"/http/**\"}],\"id\":\"1336329408516136960\","
                 + 
"\"name\":\"/http\",\"enabled\":true,\"sort\":1,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
-        MockedStatic.Verification verification = () -> 
WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, 
DataEventTypeEnum.UPDATE);
 
         try (MockedStatic<WebsocketCollector> mockedStatic = 
mockStatic(WebsocketCollector.class)) {
-            mockedStatic.when(verification).thenAnswer((Answer<Void>) 
invocation -> null);
+            mockedStatic.when(() -> WebsocketCollector.send(anyString(), 
anyString(), any()))
+                .thenAnswer(invocation -> null);
 
             // 调用被测试的方法
             websocketDataChangedListener.onSelectorChanged(selectorDataList, 
DataEventTypeEnum.UPDATE);
 
             // 验证
-            mockedStatic.verify(verification);
+            mockedStatic.verify(() -> WebsocketCollector.send(
+                eq(Constants.SYS_DEFAULT_NAMESPACE_ID),
+                argThat(actualMsg -> {
+                    try {
+                        ObjectMapper mapper = new ObjectMapper();
+                        JsonNode expectedJson = mapper.readTree(message);
+                        JsonNode actualJson = mapper.readTree(actualMsg);
+                        return expectedJson.equals(actualJson);
+                    } catch (Exception e) {
+                        return false;
+                    }
+                }),
+                eq(DataEventTypeEnum.UPDATE)
+            ));
         }
     }
 
@@ -123,11 +155,24 @@ public final class WebsocketDataChangedListenerTest {
                 + 
"\\\\\\\"503\\\\\\\"}\",\"conditionDataList\":[{\"paramType\":\"header\",\"operator\":"
                 + 
"\"\\u003d\",\"paramName\":\"test\",\"paramValue\":\"a\"}],\"id\":\"1336350040008105984\",\"name\":\"test\","
                 + 
"\"enabled\":true,\"sort\":1,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
-        MockedStatic.Verification verification = () -> 
WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, 
DataEventTypeEnum.UPDATE);
         try (MockedStatic<WebsocketCollector> mockedStatic = 
mockStatic(WebsocketCollector.class)) {
-            mockedStatic.when(verification).thenAnswer((Answer<Void>) 
invocation -> null);
+            mockedStatic.when(() -> WebsocketCollector.send(anyString(), 
anyString(), any()))
+                .thenAnswer(invocation -> null);
             websocketDataChangedListener.onRuleChanged(ruleDataList, 
DataEventTypeEnum.UPDATE);
-            mockedStatic.verify(verification);
+            mockedStatic.verify(() -> WebsocketCollector.send(
+                eq(Constants.SYS_DEFAULT_NAMESPACE_ID),
+                argThat(actualMsg -> {
+                    try {
+                        ObjectMapper mapper = new ObjectMapper();
+                        JsonNode expectedJson = mapper.readTree(message);
+                        JsonNode actualJson = mapper.readTree(actualMsg);
+                        return expectedJson.equals(actualJson);
+                    } catch (Exception e) {
+                        return false;
+                    }
+                }),
+                eq(DataEventTypeEnum.UPDATE)
+            ));
         }
     }
 
@@ -140,11 +185,24 @@ public final class WebsocketDataChangedListenerTest {
                 + 
"\"D9FD95F496C9495DB5604778A13C3D08\",\"appSecret\":\"02D25048AA1E466F8920E68B08E668DE\","
                 + 
"\"enabled\":true,\"paramDataList\":[{\"appName\":\"axiba\",\"appParam\":\"123\"}]"
                 + 
",\"pathDataList\":[{\"appName\":\"alibaba\",\"path\":\"/1\",\"enabled\":true}],\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
-        MockedStatic.Verification verification = () -> 
WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, 
DataEventTypeEnum.UPDATE);
         try (MockedStatic<WebsocketCollector> mockedStatic = 
mockStatic(WebsocketCollector.class)) {
-            mockedStatic.when(verification).thenAnswer((Answer<Void>) 
invocation -> null);
+            mockedStatic.when(() -> 
WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, 
DataEventTypeEnum.UPDATE))
+                .thenAnswer((Answer<Void>) invocation -> null);
             websocketDataChangedListener.onAppAuthChanged(appAuthDataList, 
DataEventTypeEnum.UPDATE);
-            mockedStatic.verify(verification);
+            mockedStatic.verify(() -> WebsocketCollector.send(
+                eq(Constants.SYS_DEFAULT_NAMESPACE_ID),
+                argThat(actualMsg -> {
+                    try {
+                        ObjectMapper mapper = new ObjectMapper();
+                        JsonNode expectedJson = mapper.readTree(message);
+                        JsonNode actualJson = mapper.readTree(actualMsg);
+                        return expectedJson.equals(actualJson);
+                    } catch (Exception e) {
+                        return false;
+                    }
+                }),
+                eq(DataEventTypeEnum.UPDATE)
+            ));
         }
     }
 
@@ -156,11 +214,24 @@ public final class WebsocketDataChangedListenerTest {
         String message = 
"{\"groupType\":\"META_DATA\",\"eventType\":\"CREATE\",\"data\":[{\"appName\":\"axiba\","
                 + 
"\"path\":\"/test/execute\",\"rpcType\":\"http\",\"serviceName\":\"execute\",\"methodName\":"
                 + 
"\"execute\",\"parameterTypes\":\"int\",\"rpcExt\":\"{}\",\"enabled\":true,\"namespaceId\":\"649330b6-c2d7-4edc-be8e-8a54df9eb385\"}]}";
-        MockedStatic.Verification verification = () -> 
WebsocketCollector.send(Constants.SYS_DEFAULT_NAMESPACE_ID, message, 
DataEventTypeEnum.CREATE);
         try (MockedStatic<WebsocketCollector> mockedStatic = 
mockStatic(WebsocketCollector.class)) {
-            mockedStatic.when(verification).thenAnswer((Answer<Void>) 
invocation -> null);
+            mockedStatic.when(() -> WebsocketCollector.send(anyString(), 
anyString(), any()))
+                .thenAnswer(invocation -> null);
             websocketDataChangedListener.onMetaDataChanged(metaDataList, 
DataEventTypeEnum.CREATE);
-            mockedStatic.verify(verification);
+            mockedStatic.verify(() -> WebsocketCollector.send(
+                eq(Constants.SYS_DEFAULT_NAMESPACE_ID),
+                argThat(actualMsg -> {
+                    try {
+                        ObjectMapper mapper = new ObjectMapper();
+                        JsonNode expectedJson = mapper.readTree(message);
+                        JsonNode actualJson = mapper.readTree(actualMsg);
+                        return expectedJson.equals(actualJson);
+                    } catch (Exception e) {
+                        return false;
+                    }
+                }),
+                eq(DataEventTypeEnum.CREATE)
+            ));
         }
     }
 

Reply via email to