Merge pull request #1373 from IanCao/fix11
Just return empty instance list if service not found #1367
This commit is contained in:
commit
cca2ca9752
@ -373,7 +373,11 @@ public class InstanceController {
|
||||
Service service = serviceManager.getService(namespaceId, serviceName);
|
||||
|
||||
if (service == null) {
|
||||
throw new NacosException(NacosException.NOT_FOUND, "service not found: " + serviceName);
|
||||
if (Loggers.DEBUG_LOG.isDebugEnabled()) {
|
||||
Loggers.DEBUG_LOG.debug("no instance to serve for service: " + serviceName);
|
||||
}
|
||||
result.put("hosts", new JSONArray());
|
||||
return result;
|
||||
}
|
||||
|
||||
checkIfDisabled(service);
|
||||
|
@ -148,4 +148,20 @@ public class InstanceControllerTest extends BaseTest {
|
||||
Assert.assertEquals(8888, host.getIntValue("port"));
|
||||
Assert.assertEquals(2.0, host.getDoubleValue("weight"), 0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNullServiceInstances() throws Exception {
|
||||
Mockito.when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME)).thenReturn(null);
|
||||
|
||||
MockHttpServletRequestBuilder builder =
|
||||
MockMvcRequestBuilders.get(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/instance/list")
|
||||
.param("serviceName", TEST_SERVICE_NAME);
|
||||
|
||||
MockHttpServletResponse response = mockmvc.perform(builder).andReturn().getResponse();
|
||||
String actualValue = response.getContentAsString();
|
||||
JSONObject result = JSON.parseObject(actualValue);
|
||||
|
||||
JSONArray hosts = result.getJSONArray("hosts");
|
||||
Assert.assertEquals(hosts.size(), 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user