Search in sources :

Example 6 with IpPortBasedClient

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

the class EphemeralClientOperationServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    when(instance.getIp()).thenReturn(ip);
    when(instance.getPort()).thenReturn(port);
    when(service.getNamespace()).thenReturn("public");
    when(service.getGroupedServiceName()).thenReturn("G@@S");
    when(service.isEphemeral()).thenReturn(true);
    ephemeralClientOperationServiceImpl = new EphemeralClientOperationServiceImpl(clientManager);
    client = new IpPortBasedClient(clientId, true);
    when(clientManager.getClient(clientId)).thenReturn(client);
}
Also used : IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Before(org.junit.Before)

Example 7 with IpPortBasedClient

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

the class EphemeralIpPortClientManager method clientConnected.

@Override
public boolean clientConnected(final Client client) {
    clients.computeIfAbsent(client.getClientId(), s -> {
        Loggers.SRV_LOG.info("Client connection {} connect", client.getClientId());
        IpPortBasedClient ipPortBasedClient = (IpPortBasedClient) client;
        ipPortBasedClient.init();
        return ipPortBasedClient;
    });
    return true;
}
Also used : IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)

Example 8 with IpPortBasedClient

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

the class InstanceOperatorClientImpl method registerInstance.

/**
 * This method creates {@code IpPortBasedClient} if it don't exist.
 */
@Override
public void registerInstance(String namespaceId, String serviceName, Instance instance) {
    boolean ephemeral = instance.isEphemeral();
    String clientId = IpPortBasedClient.getClientId(instance.toInetAddr(), ephemeral);
    createIpPortClientIfAbsent(clientId);
    Service service = getService(namespaceId, serviceName, ephemeral);
    clientOperationService.registerInstance(service, instance, clientId);
}
Also used : NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) UdpPushService(com.alibaba.nacos.naming.push.UdpPushService)

Example 9 with IpPortBasedClient

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

the class InstanceOperatorClientImplTest method testHandleBeat.

@Test
public void testHandleBeat() throws NacosException {
    IpPortBasedClient ipPortBasedClient = Mockito.mock(IpPortBasedClient.class);
    Mockito.when(clientManager.getClient(Mockito.anyString())).thenReturn(ipPortBasedClient);
    Mockito.when(ipPortBasedClient.getAllPublishedService()).thenReturn(Collections.emptyList());
    int res = instanceOperatorClient.handleBeat("A", "C", "1.1.1.1", 8848, "D", new RsInfo(), BeatInfoInstanceBuilder.newBuilder());
    Assert.assertEquals(NamingResponseCode.OK, res);
}
Also used : RsInfo(com.alibaba.nacos.naming.healthcheck.RsInfo) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Test(org.junit.Test)

Example 10 with IpPortBasedClient

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

the class PersistentClientOperationServiceImplTest method testOnApply.

@Test
public void testOnApply() {
    PersistentClientOperationServiceImpl.InstanceStoreRequest request = new PersistentClientOperationServiceImpl.InstanceStoreRequest();
    Service service1 = Service.newService("A", "B", "C");
    request.setService(service1);
    request.setClientId("xxxx");
    request.setInstance(new Instance());
    Mockito.when(serializer.deserialize(Mockito.any())).thenReturn(request);
    Mockito.when(clientManager.contains(Mockito.anyString())).thenReturn(true);
    IpPortBasedClient ipPortBasedClient = Mockito.mock(IpPortBasedClient.class);
    Mockito.when(clientManager.getClient(Mockito.anyString())).thenReturn(ipPortBasedClient);
    WriteRequest writeRequest = WriteRequest.newBuilder().setOperation(DataOperation.ADD.name()).build();
    Response response = persistentClientOperationServiceImpl.onApply(writeRequest);
    Assert.assertTrue(response.getSuccess());
    writeRequest = WriteRequest.newBuilder().setOperation(DataOperation.DELETE.name()).build();
    response = persistentClientOperationServiceImpl.onApply(writeRequest);
    Assert.assertTrue(response.getSuccess());
    ServiceManager.getInstance().removeSingleton(service1);
    writeRequest = WriteRequest.newBuilder().setOperation(DataOperation.VERIFY.name()).build();
    response = persistentClientOperationServiceImpl.onApply(writeRequest);
    Assert.assertFalse(response.getSuccess());
}
Also used : Response(com.alibaba.nacos.consistency.entity.Response) Instance(com.alibaba.nacos.api.naming.pojo.Instance) WriteRequest(com.alibaba.nacos.consistency.entity.WriteRequest) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Test(org.junit.Test)

Aggregations

IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)11 Before (org.junit.Before)5 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)3 Test (org.junit.Test)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)2 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)2 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)2 RsInfo (com.alibaba.nacos.naming.healthcheck.RsInfo)2 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Response (com.alibaba.nacos.consistency.entity.Response)1 WriteRequest (com.alibaba.nacos.consistency.entity.WriteRequest)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)1 ClientBeatCheckTaskV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatCheckTaskV2)1 ClientBeatProcessorV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatProcessorV2)1 SwitchDomain (com.alibaba.nacos.naming.misc.SwitchDomain)1