@Override
    public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
            throws NullPointerException, IllegalArgumentException {
        // check if listener has already been added through another interface/service
        if (!instanceListeners.add(listener)) {
            return;
        }
        for (String serviceName : listener.getServiceNames()) {
            NacosEventListener nacosEventListener = eventListeners.get(serviceName);
            if (nacosEventListener != null) {
                nacosEventListener.addListener(listener);
            } else {
                try {
                    nacosEventListener = new NacosEventListener();
                    nacosEventListener.addListener(listener);
                    namingService.subscribe(serviceName, group, nacosEventListener);
                    eventListeners.put(serviceName, nacosEventListener);
                } catch (NacosException e) {
                    logger.error(
                            REGISTRY_NACOS_EXCEPTION, "", "", "add nacos service instances changed listener fail ", e);
                }
            }
        }
    }
@Test
    void testAddServiceInstancesChangedListener() {
        List<ServiceInstance> serviceInstances = new LinkedList<>();
        // Add Listener
        nacosServiceDiscovery.addServiceInstancesChangedListener(
                new ServiceInstancesChangedListener(Sets.newSet(SERVICE_NAME), nacosServiceDiscovery) {
                    @Override
                    public void onEvent(ServiceInstancesChangedEvent event) {
                        serviceInstances.addAll(event.getServiceInstances());
                    }
                });

        nacosServiceDiscovery.register();
        nacosServiceDiscovery.update();
        nacosServiceDiscovery.unregister();

        assertTrue(serviceInstances.isEmpty());
    }