From 41b08c8b53e481f3c4d823821c0b8d381091d10f Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Wed, 31 Mar 2021 13:48:26 +0800 Subject: [PATCH] fix publishConfig lost type (#5186) --- .../client/config/NacosConfigService.java | 2 +- .../client/config/impl/ClientWorker.java | 9 +++++--- .../config/impl/ConfigTransportClient.java | 5 ++-- .../client/config/NacosConfigServiceTest.java | 23 +++++++++++-------- .../client/config/impl/ClientWorkerTest.java | 4 +++- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java b/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java index 2bbbac686..e0ca9708c 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/NacosConfigService.java @@ -201,7 +201,7 @@ public class NacosConfigService implements ConfigService { configFilterChainManager.doFilter(cr, null); content = cr.getContent(); - return worker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, casMd5); + return worker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, casMd5, type); } diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java index cf0b96a97..63b3096a0 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ClientWorker.java @@ -253,12 +253,14 @@ public class ClientWorker implements Closeable { * @param tag tag. * @param betaIps betaIps. * @param content content. + * @param casMd5 casMd5. + * @param type type. * @return success or not. * @throws NacosException exception throw. */ public boolean publishConfig(String dataId, String group, String tenant, String appName, String tag, String betaIps, - String content, String casMd5) throws NacosException { - return agent.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, casMd5); + String content, String casMd5, String type) throws NacosException { + return agent.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, casMd5, type); } /** @@ -1004,13 +1006,14 @@ public class ClientWorker implements Closeable { @Override public boolean publishConfig(String dataId, String group, String tenant, String appName, String tag, - String betaIps, String content, String casMd5) throws NacosException { + String betaIps, String content, String casMd5, String type) throws NacosException { try { ConfigPublishRequest request = new ConfigPublishRequest(dataId, group, tenant, content); request.setCasMd5(casMd5); request.putAdditionalParam("tag", tag); request.putAdditionalParam("appName", appName); request.putAdditionalParam("betaIps", betaIps); + request.putAdditionalParam("type", type); ConfigPublishResponse response = (ConfigPublishResponse) requestProxy(getOneRunningClient(), request); if (!response.isSuccess()) { LOGGER.warn("[{}] [publish-single] fail, dataId={}, group={}, tenant={}, code={}, msg={}", diff --git a/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigTransportClient.java b/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigTransportClient.java index b801584b8..a47408b95 100644 --- a/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigTransportClient.java +++ b/client/src/main/java/com/alibaba/nacos/client/config/impl/ConfigTransportClient.java @@ -316,12 +316,13 @@ public abstract class ConfigTransportClient { * @param tag tag. * @param betaIps betaIps. * @param content content. - * @param casMd5 casMd5. + * @param casMd5 casMd5. + * @param type type. * @return success or not. * @throws NacosException throw where publish fail. */ public abstract boolean publishConfig(String dataId, String group, String tenant, String appName, String tag, - String betaIps, String content, String casMd5) throws NacosException; + String betaIps, String content, String casMd5, String type) throws NacosException; /** * remove config. diff --git a/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java b/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java index fdc97290b..eb12015e9 100644 --- a/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/config/NacosConfigServiceTest.java @@ -129,14 +129,15 @@ public class NacosConfigServiceTest { String group = "2"; String content = "123"; String namespace = ""; - Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, null)) + String type = ConfigType.getDefaultType().getType(); + Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, null, type)) .thenReturn(true); final boolean b = nacosConfigService.publishConfig(dataId, group, content); Assert.assertTrue(b); Mockito.verify(mockWoker, Mockito.times(1)) - .publishConfig(dataId, group, namespace, null, null, null, content, null); + .publishConfig(dataId, group, namespace, null, null, null, content, null, type); } @Test @@ -145,15 +146,16 @@ public class NacosConfigServiceTest { String group = "2"; String content = "123"; String namespace = ""; - Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, null)) + String type = ConfigType.PROPERTIES.getType(); + + Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, null, type)) .thenReturn(true); - String type = ConfigType.PROPERTIES.getType(); final boolean b = nacosConfigService.publishConfig(dataId, group, content, type); Assert.assertTrue(b); Mockito.verify(mockWoker, Mockito.times(1)) - .publishConfig(dataId, group, namespace, null, null, null, content, null); + .publishConfig(dataId, group, namespace, null, null, null, content, null, type); } @Test @@ -163,15 +165,16 @@ public class NacosConfigServiceTest { String content = "123"; String namespace = ""; String casMd5 = "96147704e3cb8be8597d55d75d244a02"; + String type = ConfigType.getDefaultType().getType(); - Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, casMd5)) + Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, casMd5, type)) .thenReturn(true); final boolean b = nacosConfigService.publishConfigCas(dataId, group, content, casMd5); Assert.assertTrue(b); Mockito.verify(mockWoker, Mockito.times(1)) - .publishConfig(dataId, group, namespace, null, null, null, content, casMd5); + .publishConfig(dataId, group, namespace, null, null, null, content, casMd5, type); } @Test @@ -181,16 +184,16 @@ public class NacosConfigServiceTest { String content = "123"; String namespace = ""; String casMd5 = "96147704e3cb8be8597d55d75d244a02"; + String type = ConfigType.PROPERTIES.getType(); - Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, casMd5)) + Mockito.when(mockWoker.publishConfig(dataId, group, namespace, null, null, null, content, casMd5, type)) .thenReturn(true); - String type = ConfigType.PROPERTIES.getType(); final boolean b = nacosConfigService.publishConfigCas(dataId, group, content, casMd5, type); Assert.assertTrue(b); Mockito.verify(mockWoker, Mockito.times(1)) - .publishConfig(dataId, group, namespace, null, null, null, content, casMd5); + .publishConfig(dataId, group, namespace, null, null, null, content, casMd5, type); } @Test diff --git a/client/src/test/java/com/alibaba/nacos/client/config/impl/ClientWorkerTest.java b/client/src/test/java/com/alibaba/nacos/client/config/impl/ClientWorkerTest.java index 2fba1e2ea..cd48768e1 100644 --- a/client/src/test/java/com/alibaba/nacos/client/config/impl/ClientWorkerTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/config/impl/ClientWorkerTest.java @@ -131,7 +131,9 @@ public class ClientWorkerTest { String betaIps = "1.1.1.1"; String casMd5 = "1111"; - boolean b = clientWorker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, casMd5); + String type = "properties"; + + boolean b = clientWorker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, casMd5, type); Assert.assertFalse(b); try { clientWorker.removeConfig(dataId, group, tenant, tag);