use of com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse in project nacos by alibaba.
the class ConfigChangeBatchListenRequestHandlerTest method testHandle.
@Test
public void testHandle() {
String dataId = "dataId";
String group = "group";
String tenant = "tenant";
String groupKey = GroupKey2.getKey(dataId, group, tenant);
groupKey = StringPool.get(groupKey);
when(ConfigCacheService.isUptodate(eq(groupKey), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(false);
ConfigBatchListenRequest configChangeListenRequest = new ConfigBatchListenRequest();
configChangeListenRequest.addConfigListenContext(group, dataId, tenant, " ");
try {
ConfigChangeBatchListenResponse configChangeBatchListenResponse = configQueryRequestHandler.handle(configChangeListenRequest, requestMeta);
boolean hasChange = false;
for (ConfigChangeBatchListenResponse.ConfigContext changedConfig : configChangeBatchListenResponse.getChangedConfigs()) {
if (changedConfig.getDataId().equals(dataId)) {
hasChange = true;
break;
}
}
assertTrue(hasChange);
} catch (NacosException e) {
e.printStackTrace();
}
}
use of com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse in project nacos by alibaba.
the class ConfigChangeBatchListenRequestHandler method handle.
@Override
@TpsControl(pointName = "ConfigListen")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG)
public ConfigChangeBatchListenResponse handle(ConfigBatchListenRequest configChangeListenRequest, RequestMeta meta) throws NacosException {
String connectionId = StringPool.get(meta.getConnectionId());
String tag = configChangeListenRequest.getHeader(Constants.VIPSERVER_TAG);
ConfigChangeBatchListenResponse configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
for (ConfigBatchListenRequest.ConfigListenContext listenContext : configChangeListenRequest.getConfigListenContexts()) {
String groupKey = GroupKey2.getKey(listenContext.getDataId(), listenContext.getGroup(), listenContext.getTenant());
groupKey = StringPool.get(groupKey);
String md5 = StringPool.get(listenContext.getMd5());
if (configChangeListenRequest.isListen()) {
configChangeListenContext.addListen(groupKey, md5, connectionId);
boolean isUptoDate = ConfigCacheService.isUptodate(groupKey, md5, meta.getClientIp(), tag);
if (!isUptoDate) {
configChangeBatchListenResponse.addChangeConfig(listenContext.getDataId(), listenContext.getGroup(), listenContext.getTenant());
}
} else {
configChangeListenContext.removeListen(groupKey, connectionId);
}
}
return configChangeBatchListenResponse;
}
Aggregations