use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class MultiTenant_ITCase method multipleTenant_group_unSubscribe.
/**
* @TCDescription : 多租户,多group下, 多个group订阅,查看服务的个数
* @TestStep :
* @ExpectResult :
*/
@Test
public void multipleTenant_group_unSubscribe() throws Exception {
String serviceName = randomDomainName();
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
System.out.println(((NamingEvent) event).getServiceName());
instances = ((NamingEvent) event).getInstances();
}
};
naming1.subscribe(serviceName, Constants.DEFAULT_GROUP, listener);
naming1.subscribe(serviceName, TEST_GROUP_2, listener);
naming1.subscribe(serviceName, TEST_GROUP_1, listener);
naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1");
naming1.registerInstance(serviceName, TEST_GROUP_2, "33.33.33.33", TEST_PORT, "c1");
while (instances.size() == 0) {
TimeUnit.SECONDS.sleep(1L);
}
TimeUnit.SECONDS.sleep(2L);
Assert.assertEquals(serviceName, naming1.getSubscribeServices().get(0).getName());
Assert.assertEquals(3, naming1.getSubscribeServices().size());
naming1.unsubscribe(serviceName, listener);
naming1.unsubscribe(serviceName, TEST_GROUP_2, listener);
TimeUnit.SECONDS.sleep(3L);
Assert.assertEquals(1, naming1.getSubscribeServices().size());
Assert.assertEquals(TEST_GROUP_1, naming1.getSubscribeServices().get(0).getGroupName());
naming1.unsubscribe(serviceName, TEST_GROUP_1, listener);
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class MultiTenant_ITCase method multipleTenant_subscribe.
/**
* @TCDescription : 多租户订阅服务
* @TestStep :
* @ExpectResult :
*/
@Test
public void multipleTenant_subscribe() throws Exception {
String serviceName = randomDomainName();
naming1.subscribe(serviceName, new EventListener() {
@Override
public void onEvent(Event event) {
instances = ((NamingEvent) event).getInstances();
}
});
naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1");
naming2.registerInstance(serviceName, "33.33.33.33", TEST_PORT, "c1");
while (instances.size() == 0) {
TimeUnit.SECONDS.sleep(1L);
}
Assert.assertEquals(1, instances.size());
TimeUnit.SECONDS.sleep(2L);
Assert.assertTrue(verifyInstanceList(instances, naming1.getAllInstances(serviceName)));
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class MultiTenant_ITCase method multipleTenant_group_nosubscribe_unSubscribe.
/**
* @TCDescription : 多租户,多group下, 没有对应的group订阅,取消订阅服务
* @TestStep :
* @ExpectResult :
*/
@Test
public void multipleTenant_group_nosubscribe_unSubscribe() throws Exception {
String serviceName = randomDomainName();
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
System.out.println(((NamingEvent) event).getServiceName());
instances = ((NamingEvent) event).getInstances();
}
};
naming1.subscribe(serviceName, TEST_GROUP_1, listener);
naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1");
naming1.registerInstance(serviceName, TEST_GROUP_2, "33.33.33.33", TEST_PORT, "c1");
TimeUnit.SECONDS.sleep(3L);
Assert.assertEquals(serviceName, naming1.getSubscribeServices().get(0).getName());
Assert.assertEquals(0, naming2.getSubscribeServices().size());
// 取消订阅服务,没有订阅group
naming1.unsubscribe(serviceName, listener);
TimeUnit.SECONDS.sleep(3L);
Assert.assertEquals(1, naming1.getSubscribeServices().size());
// 取消订阅服务,有订阅group
naming1.unsubscribe(serviceName, TEST_GROUP_1, listener);
TimeUnit.SECONDS.sleep(3L);
Assert.assertEquals(0, naming1.getSubscribeServices().size());
Assert.assertEquals(0, naming2.getSubscribeServices().size());
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class MultiTenant_ITCase method multipleTenant_group_subscribe.
/**
* @TCDescription : 多租户多group订阅服务
* @TestStep :
* @ExpectResult :
*/
@Test
public void multipleTenant_group_subscribe() throws Exception {
String serviceName = randomDomainName();
naming1.subscribe(serviceName, TEST_GROUP_1, new EventListener() {
@Override
public void onEvent(Event event) {
instances = ((NamingEvent) event).getInstances();
}
});
naming1.registerInstance(serviceName, "11.11.11.11", TEST_PORT, "c1");
naming1.registerInstance(serviceName, TEST_GROUP_1, "33.33.33.33", TEST_PORT, "c1");
while (instances.size() == 0) {
TimeUnit.SECONDS.sleep(1L);
}
TimeUnit.SECONDS.sleep(2L);
Assert.assertEquals(1, instances.size());
TimeUnit.SECONDS.sleep(2L);
Assert.assertTrue(verifyInstanceList(instances, naming1.getAllInstances(serviceName, TEST_GROUP_1)));
naming1.deregisterInstance(serviceName, "11.11.11.11", TEST_PORT, "c1");
naming1.deregisterInstance(serviceName, TEST_GROUP_1, "33.33.33.33", TEST_PORT, "c1");
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class SubscribeCluster_ITCase method subscribeUnhealthy.
/**
* 添加不可用IP,收到通知
*
* @throws Exception
*/
@Test(timeout = 10000L)
public void subscribeUnhealthy() throws Exception {
String serviceName = randomDomainName();
naming.subscribe(serviceName, Arrays.asList("c1"), new EventListener() {
@Override
public void onEvent(Event event) {
System.out.println(((NamingEvent) event).getServiceName());
System.out.println(((NamingEvent) event).getInstances());
instances = ((NamingEvent) event).getInstances();
}
});
naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");
while (instances.isEmpty()) {
Thread.sleep(1000L);
}
Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName)));
}
Aggregations