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);
}
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;
}
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);
}
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);
}
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());
}
Aggregations