Skip to content

Commit

Permalink
Merge branch 'develop' into feature_multi_tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Jan 16, 2019
2 parents dee6857 + 6b02614 commit 5c7b2a2
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 2 deletions.
171 changes: 171 additions & 0 deletions test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,177 @@ public void getResponsibleServer4Dom() throws Exception {
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
}

@Test
public void domServeStatus() throws Exception {

ResponseEntity<String> response = request("/nacos/v1/ns/api/domServeStatus",
Params.newParams()
.appendParam("dom", NamingBase.TEST_DOM_1)
.done(),
String.class);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());

JSONObject json = JSON.parseObject(response.getBody());
Assert.assertTrue(json.getBooleanValue("success"));
Assert.assertTrue(json.getJSONObject("data").getJSONArray("ips").size() > 0);
}

/**
* @TCDescription : 根据serviceName创建服务
* @TestStep :
* @ExpectResult :
*/
@Test
public void createService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());

namingServiceDelete(serviceName);
}

/**
* @TCDescription : 根据serviceName获取服务信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void getService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());

//get service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class);

Assert.assertTrue(response.getStatusCode().is2xxSuccessful());

JSONObject json = JSON.parseObject(response.getBody());
Assert.assertEquals(serviceName, json.getString("name"));

namingServiceDelete(serviceName);
}

/**
* @TCDescription : 获取服务list信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void listService() throws Exception {
String serviceName = NamingBase.randomDomainName();
//get service
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service/list",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("pageNo", "1")
.appendParam("pageSize", "15")
.done(),
String.class);

Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
int count = json.getIntValue("count");
Assert.assertTrue(count >= 0);

response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());

response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service/list",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("pageNo", "1")
.appendParam("pageSize", "15")
.done(),
String.class);

Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
json = JSON.parseObject(response.getBody());
Assert.assertEquals(count+1, json.getIntValue("count"));

namingServiceDelete(serviceName);
}

/**
* @TCDescription : 更新serviceName获取服务信息
* @TestStep :
* @ExpectResult :
*/
@Test
public void updateService() throws Exception {
String serviceName = NamingBase.randomDomainName();
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.PUT);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());

//update service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.appendParam("healthCheckMode", "server")
.appendParam("protectThreshold", "3")
.done(),
String.class,
HttpMethod.POST);

Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());

//get service
response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class);

Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
JSONObject json = JSON.parseObject(response.getBody());
System.out.println(json);
Assert.assertEquals(3.0f, json.getFloatValue("protectThreshold"), 0.0f);

namingServiceDelete(serviceName);
}

private void namingServiceDelete(String serviceName) {
//delete service
ResponseEntity<String> response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service",
Params.newParams()
.appendParam("serviceName", serviceName)
.done(),
String.class,
HttpMethod.DELETE);

Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
Assert.assertEquals("ok", response.getBody());
}

private <T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz) {

HttpHeaders headers = new HttpHeaders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ServiceListTest {
public class ServiceList_ITCase {

private NamingService naming;

Expand Down Expand Up @@ -92,7 +92,6 @@ public void getSubscribeServices() throws NacosException, InterruptedException {
Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName)));
serviceInfoList = naming.getSubscribeServices();

System.out.println("dfdfdfd = " + serviceInfoList);
Assert.assertEquals(count+1, serviceInfoList.size());
}

Expand Down Expand Up @@ -126,6 +125,7 @@ public void onEvent(Event event) {

naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c2");
TimeUnit.SECONDS.sleep(5);

Assert.assertEquals(count+1, serviceInfoList.size());
}
Expand Down

0 comments on commit 5c7b2a2

Please sign in to comment.