Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update MaintainService_ITCase #1232

Merged
merged 3 commits into from
May 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static com.alibaba.nacos.test.naming.NamingBase.randomDomainName;

/**
* @author liaochuntao
* @date 2019-05-07 10:13
Expand All @@ -52,7 +54,7 @@ public class NamingMaintainService_ITCase {
private NamingMaintainService namingMaintainService;
private NamingService namingService;
private Instance instance;
private Service service;
private String serviceName;

@LocalServerPort
private int port;
Expand Down Expand Up @@ -82,66 +84,68 @@ public void init() throws Exception {
map.put("version", "1.0");
instance.setMetadata(map);

service = new Service();
service.setName("nacos-api");
service.setGroupName(Constants.DEFAULT_GROUP);
service.setProtectThreshold(1.0f);
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("nacos-1", "this is a test metadata");
service.setMetadata(metadata);
serviceName = randomDomainName();

}

@Test
public void updateInstance() throws NacosException {
Map<String, String> map = new HashMap<String, String>();
map.put("netType", "external-update");
map.put("version", "2.0");
namingService.registerInstance(serviceName, instance);
instance.setMetadata(map);
namingService.registerInstance("nacos-api", instance);
namingMaintainService.updateInstance("nacos-api", instance);
List<Instance> instances = namingService.getAllInstances("nacos-api", true);
namingMaintainService.updateInstance(serviceName, instance);
List<Instance> instances = namingService.getAllInstances(serviceName, true);

Assert.assertEquals(instances.size(), 1);
System.out.println(instances.get(0));
}

@Test
public void createService() throws NacosException {
public void createAndUpdateService() throws NacosException {

// register service
Service preService = new Service();
preService.setName(serviceName);
preService.setGroupName(Constants.DEFAULT_GROUP);
preService.setProtectThreshold(1.0f);
Map<String, String> metadata = new HashMap<String, String>();
metadata.put(serviceName, "this is a register metadata");
preService.setMetadata(metadata);
ExpressionSelector selector = new ExpressionSelector();
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");

System.out.println("service info : " + service);
namingMaintainService.createService(service, selector);
Service remoteService = namingMaintainService.queryService("nacos-api");
System.out.println("service info : " + preService);
namingMaintainService.createService(preService, selector);
Service remoteService = namingMaintainService.queryService(serviceName);
System.out.println("remote service info : " + remoteService);
Assert.assertEquals(service.toString(), remoteService.toString());
}

@Test
public void updateService() throws NacosException {
Service service = new Service();
service.setName("nacos-api");
service.setGroupName(Constants.DEFAULT_GROUP);
service.setProtectThreshold(1.0f);
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("nacos-1", "nacos-3-update");
service.setMetadata(metadata);

namingMaintainService.updateService(service, new NoneSelector());
Service remoteService = namingMaintainService.queryService("nacos-api");
Assert.assertEquals(preService.toString(), remoteService.toString());

// update service
Service nowService = new Service();
nowService.setName(serviceName);
nowService.setGroupName(Constants.DEFAULT_GROUP);
nowService.setProtectThreshold(1.0f);
metadata.clear();
metadata.put(serviceName, "this is a update metadata");
nowService.setMetadata(metadata);

namingMaintainService.updateService(nowService, new NoneSelector());
remoteService = namingMaintainService.queryService(serviceName);
System.out.println("remote service info : " + remoteService);
Assert.assertEquals(service.toString(), remoteService.toString());
Assert.assertEquals(nowService.toString(), remoteService.toString());
}

@Test
public void deleteService() throws NacosException {
Assert.assertTrue(namingMaintainService.deleteService("nacos-api"));
}

@Test
public void dregInstance() throws NacosException {
namingService.deregisterInstance("nacos-api", "127.0.0.1", 8081);
Service preService = new Service();
preService.setName(serviceName);
System.out.println("service info : " + preService);
namingMaintainService.createService(preService, new NoneSelector());

Assert.assertTrue(namingMaintainService.deleteService(serviceName));
}

}