use of com.alibaba.nacos.api.remote.response.ServerReloadResponse in project nacos by alibaba.
the class ServerReloaderRequestHandlerTest method testHandle.
@Test
public void testHandle() {
Mockito.when(connectionManager.currentClientsCount(Mockito.any())).thenReturn(2);
ServerReloadRequest reloadRequest = new ServerReloadRequest();
reloadRequest.setReloadCount(2);
reloadRequest.setReloadServer("test");
RequestMeta meta = new RequestMeta();
meta.setClientIp("1.1.1.1");
try {
ServerReloadResponse reloadResponse = handler.handle(reloadRequest, meta);
Assert.assertEquals("ignore", reloadResponse.getMessage());
} catch (NacosException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
reloadRequest.setReloadCount(1);
try {
ServerReloadResponse reloadResponse = handler.handle(reloadRequest, meta);
Assert.assertEquals("ok", reloadResponse.getMessage());
} catch (NacosException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.alibaba.nacos.api.remote.response.ServerReloadResponse in project nacos by alibaba.
the class ServerReloaderRequestHandler method handle.
@Override
public ServerReloadResponse handle(ServerReloadRequest request, RequestMeta meta) throws NacosException {
ServerReloadResponse response = new ServerReloadResponse();
Loggers.REMOTE.info("server reload request receive,reload count={},redirectServer={},requestIp={}", request.getReloadCount(), request.getReloadServer(), meta.getClientIp());
int reloadCount = request.getReloadCount();
Map<String, String> filter = new HashMap<String, String>(2);
filter.put(RemoteConstants.LABEL_SOURCE, RemoteConstants.LABEL_SOURCE_SDK);
int sdkCount = connectionManager.currentClientsCount(filter);
if (sdkCount <= reloadCount) {
response.setMessage("ignore");
} else {
reloadCount = (int) Math.max(reloadCount, sdkCount * (1 - RemoteUtils.LOADER_FACTOR));
connectionManager.loadCount(reloadCount, request.getReloadServer());
response.setMessage("ok");
}
return response;
}
Aggregations