@Override
    public void batchRegisterInstance(Service service, List<Instance> instances, String clientId) {
        Service singleton = ServiceManager.getInstance().getSingleton(service);
        if (!singleton.isEphemeral()) {
            throw new NacosRuntimeException(NacosException.INVALID_PARAM,
                    String.format("Current service %s is persistent service, can't batch register ephemeral instance.",
                            singleton.getGroupedServiceName()));
        }
        Client client = clientManager.getClient(clientId);
        checkClientIsLegal(client, clientId);
        BatchInstancePublishInfo batchInstancePublishInfo = new BatchInstancePublishInfo();
        List<InstancePublishInfo> resultList = new ArrayList<>();
        for (Instance instance : instances) {
            InstancePublishInfo instanceInfo = getPublishInfo(instance);
            resultList.add(instanceInfo);
        }
        batchInstancePublishInfo.setInstancePublishInfos(resultList);
        client.addServiceInstance(singleton, batchInstancePublishInfo);
        client.setLastUpdatedTime();
        client.recalculateRevision();
        NotifyCenter.publishEvent(new ClientOperationEvent.ClientRegisterServiceEvent(singleton, clientId));
        NotifyCenter.publishEvent(
                new MetadataEvent.InstanceMetadataEvent(singleton, batchInstancePublishInfo.getMetadataId(), false));
    }
@Test
    void testBatchRegisterAndDeregisterInstance() throws Exception {
        // test Batch register instance
        
        Instance instance1 = new Instance();
        instance1.setEphemeral(true);
        instance1.setIp("127.0.0.1");
        instance1.setPort(9087);
        instance1.setHealthy(true);
        
        Instance instance2 = new Instance();
        instance2.setEphemeral(true);
        instance2.setIp("127.0.0.2");
        instance2.setPort(9045);
        instance2.setHealthy(true);
        
        List<Instance> instances = new ArrayList<>();
        instances.add(instance1);
        instances.add(instance2);
        ephemeralClientOperationServiceImpl.batchRegisterInstance(service, instances, connectionBasedClientId);
        assertTrue(connectionBasedClient.getAllPublishedService().contains(service));
    }