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

Aias00 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 e586024f1e fix: handle discovery upstream DELETE events in path data 
sync (#6661) (#7060)
e586024f1e is described below

commit e586024f1e26d5973b8bb59a6bb7ab86950f4da8
Author: wy471x <[email protected]>
AuthorDate: Wed Sep 30 10:00:35 2026 +0800

    fix: handle discovery upstream DELETE events in path data sync (#6661) 
(#7060)
    
    Co-authored-by: Liming Deng <[email protected]>
    Co-authored-by: aias00 <[email protected]>
---
 .../data/core/AbstractPathDataSyncService.java     | 22 +++++++++++++++++-----
 .../data/core/AbstractPathDataSyncServiceTest.java | 22 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git 
a/shenyu-sync-data-center/shenyu-sync-data-api/src/main/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncService.java
 
b/shenyu-sync-data-center/shenyu-sync-data-api/src/main/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncService.java
index f9a3c2a0e9..10c86a1aa1 100644
--- 
a/shenyu-sync-data-center/shenyu-sync-data-api/src/main/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncService.java
+++ 
b/shenyu-sync-data-center/shenyu-sync-data-api/src/main/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncService.java
@@ -130,14 +130,21 @@ public abstract class AbstractPathDataSyncService 
implements SyncDataService {
     }
 
     private void discoveryUpstreamHandlerEvent(final String updatePath, final 
String updateData, final EventType eventType) {
-        String[] pathInfoArray2 = updatePath.split("/");
-        if (pathInfoArray2.length != 5) {
+        String[] pathInfoArray = updatePath.split("/");
+        if (pathInfoArray.length != 5) {
             return;
         }
-        if (!EventType.DELETE.equals(eventType)) {
-            Optional.ofNullable(updateData)
-                    .ifPresent(e -> 
cacheDiscoveryUpstreamData(GsonUtils.getInstance().fromJson(updateData, 
DiscoverySyncData.class)));
+        String pluginName = pathInfoArray[pathInfoArray.length - 2];
+        String selectorId = pathInfoArray[pathInfoArray.length - 1];
+        if (EventType.DELETE.equals(eventType)) {
+            DiscoverySyncData discoverySyncData = new DiscoverySyncData();
+            discoverySyncData.setPluginName(pluginName);
+            discoverySyncData.setSelectorId(selectorId);
+            unCacheDiscoveryUpstreamData(discoverySyncData);
+            return;
         }
+        Optional.ofNullable(updateData)
+                .ifPresent(e -> 
cacheDiscoveryUpstreamData(GsonUtils.getInstance().fromJson(updateData, 
DiscoverySyncData.class)));
     }
 
     private void ruleHandlerEvent(final String updatePath, final String 
updateData, final EventType eventType) {
@@ -280,6 +287,11 @@ public abstract class AbstractPathDataSyncService 
implements SyncDataService {
                 .ifPresent(data -> discoveryUpstreamDataSubscribers.forEach(e 
-> e.onSubscribe(upstreamDataList)));
     }
 
+    protected void unCacheDiscoveryUpstreamData(final DiscoverySyncData 
discoverySyncData) {
+        Optional.ofNullable(discoverySyncData)
+                .ifPresent(data -> discoveryUpstreamDataSubscribers.forEach(e 
-> e.unSubscribe(data)));
+    }
+
     protected void unCacheMetaData(final MetaData metaData) {
         Optional.ofNullable(metaData)
                 .ifPresent(data -> metaDataSubscribers.forEach(e -> 
e.unSubscribe(metaData)));
diff --git 
a/shenyu-sync-data-center/shenyu-sync-data-api/src/test/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncServiceTest.java
 
b/shenyu-sync-data-center/shenyu-sync-data-api/src/test/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncServiceTest.java
index bfb80e0fcc..c1c25e9deb 100644
--- 
a/shenyu-sync-data-center/shenyu-sync-data-api/src/test/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncServiceTest.java
+++ 
b/shenyu-sync-data-center/shenyu-sync-data-api/src/test/java/org/apache/shenyu/sync/data/core/AbstractPathDataSyncServiceTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.shenyu.sync.data.core;
 
+import org.apache.shenyu.common.constant.DefaultPathConstants;
 import org.apache.shenyu.common.dto.AppAuthData;
+import org.apache.shenyu.common.dto.DiscoverySyncData;
 import org.apache.shenyu.common.utils.GsonUtils;
 import org.apache.shenyu.sync.data.api.AuthDataSubscriber;
 import org.apache.shenyu.sync.data.api.DiscoveryUpstreamDataSubscriber;
@@ -27,6 +29,7 @@ import 
org.apache.shenyu.sync.data.api.ProxySelectorDataSubscriber;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -34,6 +37,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.verify;
 
@@ -85,6 +89,24 @@ public class AbstractPathDataSyncServiceTest {
         verify(authDataSubscriber).unSubscribe(any());
     }
 
+    @Test
+    public void testDiscoveryUpstreamHandlerEvent() {
+
+        String namespaceId = "/namespace";
+        String registerPath = namespaceId + 
DefaultPathConstants.DISCOVERY_UPSTREAM;
+        String updatePath = registerPath + "/divide/testSelectorId";
+        String jsonData = 
"{\"pluginName\":\"divide\",\"selectorId\":\"testSelectorId\",\"selectorName\":\"testSelector\"}";
+
+        pathDataSyncService.event(namespaceId, updatePath, jsonData, 
registerPath, AbstractPathDataSyncService.EventType.PUT);
+        verify(discoveryUpstreamDataSubscriber).onSubscribe(any());
+
+        pathDataSyncService.event(namespaceId, updatePath, null, registerPath, 
AbstractPathDataSyncService.EventType.DELETE);
+        ArgumentCaptor<DiscoverySyncData> captor = 
ArgumentCaptor.forClass(DiscoverySyncData.class);
+        verify(discoveryUpstreamDataSubscriber).unSubscribe(captor.capture());
+        assertEquals("divide", captor.getValue().getPluginName());
+        assertEquals("testSelectorId", captor.getValue().getSelectorId());
+    }
+
     // Mock implementation
     static class AbstractPathDataSyncServiceImpl extends 
AbstractPathDataSyncService {
 

Reply via email to