use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class Unsubscribe_ITCase method unsubscribeCluster.
/**
* 取消订阅,在指定cluster添加IP,不会收到通知
* @throws Exception
*/
@Test
public void unsubscribeCluster() throws Exception {
String serviceName = randomDomainName();
EventListener listener = 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.subscribe(serviceName, Arrays.asList("c1"), listener);
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
while (instances.isEmpty()) {
Thread.sleep(1000L);
}
Assert.assertTrue(verifyInstanceList(instances, naming.getAllInstances(serviceName)));
naming.unsubscribe(serviceName, Arrays.asList("c1"), listener);
instances = Collections.emptyList();
naming.registerInstance(serviceName, "127.0.0.2", TEST_PORT, "c1");
int i = 0;
while (instances.isEmpty()) {
Thread.sleep(1000L);
if (i++ > 10) {
return;
}
}
Assert.fail();
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class NacosNamingServiceTest method testSubscribe3.
@Test
public void testSubscribe3() throws NacosException {
// given
String serviceName = "service1";
List<String> clusterList = Arrays.asList("cluster1", "cluster2");
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
}
};
// when
client.subscribe(serviceName, clusterList, listener);
// then
verify(changeNotifier, times(1)).registerListener(Constants.DEFAULT_GROUP, serviceName, "cluster1,cluster2", listener);
verify(proxy, times(1)).subscribe(serviceName, Constants.DEFAULT_GROUP, "cluster1,cluster2");
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class NacosNamingServiceTest method testUnSubscribe2.
@Test
public void testUnSubscribe2() throws NacosException {
// given
String serviceName = "service1";
String groupName = "group1";
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
}
};
when(changeNotifier.isSubscribed(serviceName, groupName, "")).thenReturn(false);
// when
client.unsubscribe(serviceName, groupName, listener);
// then
verify(changeNotifier, times(1)).deregisterListener(groupName, serviceName, "", listener);
verify(proxy, times(1)).unsubscribe(serviceName, groupName, "");
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class NacosNamingServiceTest method testUnSubscribe4.
@Test
public void testUnSubscribe4() throws NacosException {
// given
String serviceName = "service1";
String groupName = "group1";
List<String> clusterList = Arrays.asList("cluster1", "cluster2");
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
}
};
when(changeNotifier.isSubscribed(serviceName, groupName, "cluster1,cluster2")).thenReturn(false);
// when
client.unsubscribe(serviceName, groupName, clusterList, listener);
// then
verify(changeNotifier, times(1)).deregisterListener(groupName, serviceName, "cluster1,cluster2", listener);
verify(proxy, times(1)).unsubscribe(serviceName, groupName, "cluster1,cluster2");
}
use of com.alibaba.nacos.api.naming.listener.Event in project nacos by alibaba.
the class NacosNamingServiceTest method testUnSubscribe1.
@Test
public void testUnSubscribe1() throws NacosException {
// given
String serviceName = "service1";
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
}
};
when(changeNotifier.isSubscribed(serviceName, Constants.DEFAULT_GROUP, "")).thenReturn(false);
// when
client.unsubscribe(serviceName, listener);
// then
verify(changeNotifier, times(1)).deregisterListener(Constants.DEFAULT_GROUP, serviceName, "", listener);
verify(proxy, times(1)).unsubscribe(serviceName, Constants.DEFAULT_GROUP, "");
}
Aggregations