fix(test): fix NamingMaintainService_ITCase mistake

This commit is contained in:
chuntaojun 2019-05-16 12:08:28 +08:00
parent 01b74be838
commit 4c5c2a66e8

View File

@ -40,6 +40,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.alibaba.nacos.test.naming.NamingBase.randomDomainName;
/** /**
* @author liaochuntao * @author liaochuntao
* @date 2019-05-07 10:13 * @date 2019-05-07 10:13
@ -52,7 +54,7 @@ public class NamingMaintainService_ITCase {
private NamingMaintainService namingMaintainService; private NamingMaintainService namingMaintainService;
private NamingService namingService; private NamingService namingService;
private Instance instance; private Instance instance;
private Service service; private String serviceName;
@LocalServerPort @LocalServerPort
private int port; private int port;
@ -82,13 +84,8 @@ public class NamingMaintainService_ITCase {
map.put("version", "1.0"); map.put("version", "1.0");
instance.setMetadata(map); instance.setMetadata(map);
service = new Service(); serviceName = randomDomainName();
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);
} }
@Test @Test
@ -96,52 +93,58 @@ public class NamingMaintainService_ITCase {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("netType", "external-update"); map.put("netType", "external-update");
map.put("version", "2.0"); map.put("version", "2.0");
namingService.registerInstance(serviceName, instance);
instance.setMetadata(map); instance.setMetadata(map);
namingService.registerInstance("nacos-api", instance); namingMaintainService.updateInstance(serviceName, instance);
namingMaintainService.updateInstance("nacos-api", instance); List<Instance> instances = namingService.getAllInstances(serviceName, true);
List<Instance> instances = namingService.getAllInstances("nacos-api", true);
Assert.assertEquals(instances.size(), 1); Assert.assertEquals(instances.size(), 1);
System.out.println(instances.get(0)); System.out.println(instances.get(0));
} }
@Test @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(); ExpressionSelector selector = new ExpressionSelector();
selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B"); selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
System.out.println("service info : " + service); System.out.println("service info : " + preService);
namingMaintainService.createService(service, selector); namingMaintainService.createService(preService, selector);
Service remoteService = namingMaintainService.queryService("nacos-api"); Service remoteService = namingMaintainService.queryService(serviceName);
System.out.println("remote service info : " + remoteService); System.out.println("remote service info : " + remoteService);
Assert.assertEquals(service.toString(), remoteService.toString()); Assert.assertEquals(preService.toString(), remoteService.toString());
}
@Test // update service
public void updateService() throws NacosException { Service nowService = new Service();
Service service = new Service(); nowService.setName(serviceName);
service.setName("nacos-api"); nowService.setGroupName(Constants.DEFAULT_GROUP);
service.setGroupName(Constants.DEFAULT_GROUP); nowService.setProtectThreshold(1.0f);
service.setProtectThreshold(1.0f); metadata.clear();
Map<String, String> metadata = new HashMap<String, String>(); metadata.put(serviceName, "this is a update metadata");
metadata.put("nacos-1", "nacos-3-update"); nowService.setMetadata(metadata);
service.setMetadata(metadata);
namingMaintainService.updateService(service, new NoneSelector()); namingMaintainService.updateService(nowService, new NoneSelector());
Service remoteService = namingMaintainService.queryService("nacos-api"); remoteService = namingMaintainService.queryService(serviceName);
System.out.println("remote service info : " + remoteService); System.out.println("remote service info : " + remoteService);
Assert.assertEquals(service.toString(), remoteService.toString()); Assert.assertEquals(nowService.toString(), remoteService.toString());
} }
@Test @Test
public void deleteService() throws NacosException { public void deleteService() throws NacosException {
Assert.assertTrue(namingMaintainService.deleteService("nacos-api")); Assert.assertTrue(namingMaintainService.deleteService(serviceName));
} }
@Test @Test
public void dregInstance() throws NacosException { public void dregInstance() throws NacosException {
namingService.deregisterInstance("nacos-api", "127.0.0.1", 8081); namingService.deregisterInstance(serviceName, "127.0.0.1", 8081);
} }
} }