ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer { private void getMode(Request req) { dispatchRpcRequest(req, () -> { req.returnValues().add(new StringValue(proxyServer.getMode().name())); req.returnRequest(); }); } ConfigProxyRpcServer(ProxyServer proxyServer, Supervisor supervisor, Spec spec); void run(); @Override void notifyTargetInvalid(Target target); void returnOkResponse(JRTServerConfigRequest request, RawConfig config); void returnErrorResponse(JRTServerConfigRequest request, int errorCode, String message);  }
@Test public void testRpcMethodGetModeAndSetMode() { Request req = new Request("getMode"); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); assertThat(req.returnValues().size(), is(1)); assertThat(req.returnValues().get(0).asString(), is("default")); req = new Request("setMode"); String mode = "memorycache"; req.parameters().add(new StringValue(mode)); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); assertThat(req.returnValues().size(), is(1)); String[] ret = req.returnValues().get(0).asStringArray(); assertThat(ret.length, is(2)); assertThat(ret[0], is("0")); assertThat(ret[1], is("success")); assertThat(server.proxyServer().getMode().name(), is(mode)); req = new Request("getMode"); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); assertThat(req.returnValues().size(), is(1)); assertThat(req.returnValues().get(0).asString(), is(mode)); req = new Request("setMode"); String oldMode = mode; mode = "invalid"; req.parameters().add(new StringValue(mode)); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); ret = req.returnValues().get(0).asStringArray(); assertThat(ret.length, is(2)); assertThat(ret[0], is("1")); assertThat(ret[1], is("Unrecognized mode '" + mode + "' supplied. Legal modes are '" + Mode.modes() + "'")); assertThat(server.proxyServer().getMode().name(), is(oldMode)); }