Search in sources :

Example 1 with ConnectionBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient in project nacos by alibaba.

the class HealthOperatorV2ImplTest method testUpdateHealthStatusForPersistentInstance.

@Test
public void testUpdateHealthStatusForPersistentInstance() {
    try {
        ServiceMetadata metadata = new ServiceMetadata();
        Map<String, ClusterMetadata> clusterMap = new HashMap<>(2);
        ClusterMetadata cluster = Mockito.mock(ClusterMetadata.class);
        clusterMap.put("C", cluster);
        metadata.setClusters(clusterMap);
        Instance instance = new Instance();
        instance.setIp("1.1.1.1");
        instance.setPort(8080);
        Mockito.when(cluster.getHealthyCheckType()).thenReturn(HealthCheckType.NONE.name());
        Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
        ConnectionBasedClient client = Mockito.mock(ConnectionBasedClient.class);
        Mockito.when(clientManager.getClient(Mockito.anyString())).thenReturn(client);
        InstancePublishInfo instancePublishInfo = new InstancePublishInfo();
        instancePublishInfo.setExtendDatum(new HashMap<>(2));
        Mockito.when(client.getInstancePublishInfo(Mockito.any())).thenReturn(instancePublishInfo);
        healthOperatorV2.updateHealthStatusForPersistentInstance("A", "B", "C", "1.1.1.1", 8080, true);
    } catch (NacosException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) HashMap(java.util.HashMap) ConnectionBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 2 with ConnectionBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient in project nacos by alibaba.

the class ConnectionBasedClientManager method clientDisconnected.

@Override
public boolean clientDisconnected(String clientId) {
    Loggers.SRV_LOG.info("Client connection {} disconnect, remove instances and subscribers", clientId);
    ConnectionBasedClient client = clients.remove(clientId);
    if (null == client) {
        return true;
    }
    client.release();
    NotifyCenter.publishEvent(new ClientEvent.ClientDisconnectEvent(client));
    return true;
}
Also used : ConnectionBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient) ClientEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)

Aggregations

ConnectionBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)1 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)1 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1