Search in sources :

Example 1 with ConfigChangeBatchListenResponse

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();
    }
}
Also used : ConfigChangeBatchListenResponse(com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse) ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 2 with ConfigChangeBatchListenResponse

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;
}
Also used : ConfigChangeBatchListenResponse(com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse) ConfigBatchListenRequest(com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest) Secured(com.alibaba.nacos.auth.annotation.Secured) TpsControl(com.alibaba.nacos.core.remote.control.TpsControl)

Aggregations

ConfigBatchListenRequest (com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest)2 ConfigChangeBatchListenResponse (com.alibaba.nacos.api.config.remote.response.ConfigChangeBatchListenResponse)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Secured (com.alibaba.nacos.auth.annotation.Secured)1 TpsControl (com.alibaba.nacos.core.remote.control.TpsControl)1 Test (org.junit.Test)1