use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class ConfigSubService method getCollectSampleResultByIp.
public SampleResult getCollectSampleResultByIp(String ip, int sampleTime) {
List<SampleResult> resultList = new ArrayList<>(10);
String url = Constants.COMMUNICATION_CONTROLLER_PATH + "/watcherConfigs";
Map<String, String> params = new HashMap<>(50);
params.put("ip", ip);
BlockingQueue<Future<SampleResult>> queue = new LinkedBlockingDeque<>(memberManager.getServerList().size());
CompletionService<SampleResult> completionService = new ExecutorCompletionService<>(ConfigExecutor.getConfigSubServiceExecutor(), queue);
SampleResult sampleCollectResult = new SampleResult();
for (int i = 0; i < sampleTime; i++) {
List<SampleResult> sampleResults = runCollectionJob(url, params, completionService, resultList);
sampleCollectResult = mergeSampleResult(sampleCollectResult, sampleResults);
}
return sampleCollectResult;
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class LongPollingService method mergeSampleResult.
/**
* Aggregate the sampling IP and monitoring configuration information in the sampling results. There is no problem
* for the merging strategy to cover the previous one with the latter.
*
* @param sampleResults sample Results.
* @return Results.
*/
public SampleResult mergeSampleResult(List<SampleResult> sampleResults) {
SampleResult mergeResult = new SampleResult();
Map<String, String> lisentersGroupkeyStatus = new HashMap<String, String>(50);
for (SampleResult sampleResult : sampleResults) {
Map<String, String> lisentersGroupkeyStatusTmp = sampleResult.getLisentersGroupkeyStatus();
for (Map.Entry<String, String> entry : lisentersGroupkeyStatusTmp.entrySet()) {
lisentersGroupkeyStatus.put(entry.getKey(), entry.getValue());
}
}
mergeResult.setLisentersGroupkeyStatus(lisentersGroupkeyStatus);
return mergeResult;
}
use of com.alibaba.nacos.config.server.model.SampleResult 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());
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class CommunicationControllerTest method testGetSubClientConfig1x.
@Test
public void testGetSubClientConfig1x() throws Exception {
SampleResult result = new SampleResult();
Map<String, String> lisentersGroupkeyStatus = new HashMap<>();
lisentersGroupkeyStatus.put("test", "test");
result.setLisentersGroupkeyStatus(lisentersGroupkeyStatus);
when(longPollingService.getCollectSubscribleInfo("test", "test", "test")).thenReturn(result);
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("{\"test\":\"test\"}", JacksonUtils.toObj(actualValue).get("lisentersGroupkeyStatus").toString());
}
use of com.alibaba.nacos.config.server.model.SampleResult in project nacos by alibaba.
the class ConfigControllerTest method testGetListeners.
@Test
public void testGetListeners() throws Exception {
Map<String, String> listenersGroupkeyStatus = new HashMap<>();
listenersGroupkeyStatus.put("test", "test");
SampleResult sampleResult = new SampleResult();
sampleResult.setLisentersGroupkeyStatus(listenersGroupkeyStatus);
when(configSubService.getCollectSampleResult("test", "test", "", 1)).thenReturn(sampleResult);
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.CONFIG_CONTROLLER_PATH + "/listener").param("dataId", "test").param("group", "test").param("tenant", "").param("sampleTime", "1");
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
GroupkeyListenserStatus groupkeyListenserStatus = JacksonUtils.toObj(actualValue, GroupkeyListenserStatus.class);
Assert.assertEquals(200, groupkeyListenserStatus.getCollectStatus());
Assert.assertEquals(1, groupkeyListenserStatus.getLisentersGroupkeyStatus().size());
Assert.assertEquals("test", groupkeyListenserStatus.getLisentersGroupkeyStatus().get("test"));
}
Aggregations