Search in sources :

Example 1 with GrpcConnection

use of com.alibaba.nacos.core.remote.grpc.GrpcConnection in project nacos by alibaba.

the class CommunicationControllerTest method testGetSubClientConfig2x.

@Test
public void testGetSubClientConfig2x() throws Exception {
    SampleResult result = new SampleResult();
    result.setLisentersGroupkeyStatus(new HashMap<>());
    when(longPollingService.getCollectSubscribleInfo("test", "test", "test")).thenReturn(result);
    String groupKey = GroupKey2.getKey("test", "test", "test");
    Set<String> listenersClients = new HashSet<>();
    String connectionId = "127.0.0.1";
    listenersClients.add(connectionId);
    when(configChangeListenContext.getListeners(groupKey)).thenReturn(listenersClients);
    ConnectionMeta connectionMeta = new ConnectionMeta(connectionId, connectionId, connectionId, 8888, 9848, "GRPC", "", "", new HashMap<>());
    Connection client = new GrpcConnection(connectionMeta, null, null);
    when(connectionManager.getConnection(connectionId)).thenReturn(client);
    when(configChangeListenContext.getListenKeyMd5(connectionId, groupKey)).thenReturn("md5");
    MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.COMMUNICATION_CONTROLLER_PATH + "/configWatchers").param("dataId", "test").param("group", "test").param("tenant", "test");
    String actualValue = mockMvc.perform(builder).andReturn().getResponse().getContentAsString();
    Assert.assertEquals("{\"127.0.0.1\":\"md5\"}", JacksonUtils.toObj(actualValue).get("lisentersGroupkeyStatus").toString());
}
Also used : GrpcConnection(com.alibaba.nacos.core.remote.grpc.GrpcConnection) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) GrpcConnection(com.alibaba.nacos.core.remote.grpc.GrpcConnection) Connection(com.alibaba.nacos.core.remote.Connection) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) ConnectionMeta(com.alibaba.nacos.core.remote.ConnectionMeta) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with GrpcConnection

use of com.alibaba.nacos.core.remote.grpc.GrpcConnection in project nacos by alibaba.

the class CommunicationControllerTest method testGetSubClientConfigByIp.

@Test
public void testGetSubClientConfigByIp() throws Exception {
    String ip = "127.0.0.1";
    SampleResult result = new SampleResult();
    result.setLisentersGroupkeyStatus(new HashMap<>());
    when(longPollingService.getCollectSubscribleInfoByIp(ip)).thenReturn(result);
    ConnectionMeta connectionMeta = new ConnectionMeta(ip, ip, ip, 8888, 9848, "GRPC", "", "", new HashMap<>());
    Connection connection = new GrpcConnection(connectionMeta, null, null);
    List<Connection> connectionList = new ArrayList<>();
    connectionList.add(connection);
    when(connectionManager.getConnectionByIp(ip)).thenReturn(connectionList);
    Map<String, String> map = new HashMap<>();
    map.put("test", "test");
    when(configChangeListenContext.getListenKeys(ip)).thenReturn(map);
    MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.COMMUNICATION_CONTROLLER_PATH + "/watcherConfigs").param("ip", ip);
    String actualValue = mockMvc.perform(builder).andReturn().getResponse().getContentAsString();
    Assert.assertEquals("{\"test\":\"test\"}", JacksonUtils.toObj(actualValue).get("lisentersGroupkeyStatus").toString());
}
Also used : HashMap(java.util.HashMap) GrpcConnection(com.alibaba.nacos.core.remote.grpc.GrpcConnection) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) GrpcConnection(com.alibaba.nacos.core.remote.grpc.GrpcConnection) Connection(com.alibaba.nacos.core.remote.Connection) ArrayList(java.util.ArrayList) SampleResult(com.alibaba.nacos.config.server.model.SampleResult) ConnectionMeta(com.alibaba.nacos.core.remote.ConnectionMeta) Test(org.junit.Test)

Example 3 with GrpcConnection

use of com.alibaba.nacos.core.remote.grpc.GrpcConnection in project nacos by alibaba.

the class RpcAckCallbackInitorOrCleanerTest method testInitAndCleaner.

@Test
public void testInitAndCleaner() {
    String connectId = "11";
    ConnectionMeta meta = new ConnectionMeta(connectId, "", "", 80, 80, "GRPC", "", "", new HashMap<>());
    Connection connection = new GrpcConnection(meta, null, null);
    RpcAckCallbackInitorOrCleaner initorOrCleaner = new RpcAckCallbackInitorOrCleaner();
    initorOrCleaner.clientConnected(connection);
    initorOrCleaner.clientDisConnected(connection);
}
Also used : GrpcConnection(com.alibaba.nacos.core.remote.grpc.GrpcConnection) GrpcConnection(com.alibaba.nacos.core.remote.grpc.GrpcConnection) Connection(com.alibaba.nacos.core.remote.Connection) ConnectionMeta(com.alibaba.nacos.core.remote.ConnectionMeta) Test(org.junit.Test)

Aggregations

Connection (com.alibaba.nacos.core.remote.Connection)3 ConnectionMeta (com.alibaba.nacos.core.remote.ConnectionMeta)3 GrpcConnection (com.alibaba.nacos.core.remote.grpc.GrpcConnection)3 Test (org.junit.Test)3 SampleResult (com.alibaba.nacos.config.server.model.SampleResult)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1