fix publishConfig lost type (#5186)

This commit is contained in:
shalk(xiao kun) 2021-03-31 13:48:26 +08:00 committed by GitHub
parent d146e057c4
commit 41b08c8b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 17 deletions

View File

@ -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);
}

View File

@ -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={}",

View File

@ -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.

View File

@ -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

View File

@ -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);