use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class InstanceOperatorClientImplTest method testListInstance.
@Test
public void testListInstance() {
Mockito.when(pushService.canEnablePush(Mockito.anyString())).thenReturn(true);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setGroupName("DEFAULT_GROUP");
serviceInfo.setName("B");
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
ServiceMetadata metadata = new ServiceMetadata();
Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
Subscriber subscriber = new Subscriber("2.2.2.2", "", "app", "1.1.1.1", "A", "B", 8848);
instanceOperatorClient.listInstance("A", "B", subscriber, "C", true);
Mockito.verify(clientOperationService).subscribeService(Mockito.any(), Mockito.any(), Mockito.anyString());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class InstanceOperatorClientImplTest method testBatchDeleteMetadata.
@Test
public void testBatchDeleteMetadata() throws NacosException {
Instance instance = new Instance();
instance.setServiceName("C");
instance.setIp("1.1.1.1");
instance.setPort(8848);
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setHosts(Collections.singletonList(instance));
Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
List<String> res = instanceOperatorClient.batchDeleteMetadata("A", new InstanceOperationInfo(), new HashMap<>());
Assert.assertEquals(1, res.size());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceListTest_ITCase method getSubscribeServices_deregisterInstance.
/**
* @throws NacosException
* @description 删除注册,获取当前订阅的所有服务
*/
@Test
public void getSubscribeServices_deregisterInstance() throws NacosException, InterruptedException {
listenseCount = 0;
EventListener listener = new EventListener() {
@Override
public void onEvent(Event event) {
System.out.println(((NamingEvent) event).getServiceName());
System.out.println(((NamingEvent) event).getInstances());
listenseCount++;
}
};
List<ServiceInfo> serviceInfoList = naming.getSubscribeServices();
int count = serviceInfoList.size();
String serviceName = randomDomainName();
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
naming.subscribe(serviceName, listener);
serviceInfoList = naming.getSubscribeServices();
Assert.assertEquals(count + 1, serviceInfoList.size());
naming.deregisterInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
Assert.assertEquals(count + 1, serviceInfoList.size());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceListTest_ITCase method getSubscribeServices.
/**
* @throws NacosException
* @description 获取当前订阅的所有服务
*/
@Test
public void getSubscribeServices() throws NacosException, InterruptedException {
ListView<String> listView = naming.getServicesOfServer(1, 10);
if (listView != null && listView.getCount() > 0) {
naming.getAllInstances(listView.getData().get(0));
}
List<ServiceInfo> serviceInfoList = naming.getSubscribeServices();
int count = serviceInfoList.size();
String serviceName = randomDomainName();
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
naming.subscribe(serviceName, new EventListener() {
@Override
public void onEvent(Event event) {
}
});
serviceInfoList = naming.getSubscribeServices();
Assert.assertEquals(count + 1, serviceInfoList.size());
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class DoubleWriteServiceRemovalToV2Task method run.
@Override
public void run() {
try {
InstanceOperatorClientImpl instanceOperator = ApplicationUtils.getBean(InstanceOperatorClientImpl.class);
ClientServiceIndexesManager clientServiceIndexesManager = ApplicationUtils.getBean(ClientServiceIndexesManager.class);
ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
ServiceInfo serviceInfo = serviceStorage.getPushData(service);
for (Instance instance : serviceInfo.getHosts()) {
instanceOperator.removeInstance(service.getNamespace(), service.getName(), instance);
}
int count = 0;
while (!clientServiceIndexesManager.getAllClientsRegisteredService(service).isEmpty() && count < MAX_WAIT_TIMES) {
TimeUnit.MILLISECONDS.sleep(100);
count += 1;
}
clientServiceIndexesManager.removePublisherIndexesByEmptyService(service);
ServiceManager.getInstance().removeSingleton(service);
serviceStorage.removeData(service);
NotifyCenter.publishEvent(new MetadataEvent.ServiceMetadataEvent(service, true));
} catch (Exception e) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write removal of {} from 1 to 2 failed", service, e);
}
ServiceChangeV1Task retryTask = new ServiceChangeV1Task(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral(), DoubleWriteContent.BOTH, DoubleWriteAction.REMOVE);
retryTask.setTaskInterval(INTERVAL);
String taskKey = ServiceChangeV1Task.getKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
}
}
Aggregations