ConfigProxyRpcServer implements Runnable, TargetWatcher, RpcServer { private void setMode(Request req) { dispatchRpcRequest(req, () -> { String suppliedMode = req.parameters().get(0).asString(); String[] s = new String[2]; try { proxyServer.setMode(suppliedMode); s[0] = "0"; s[1] = "success"; } catch (Exception e) { s[0] = "1"; s[1] = e.getMessage(); } req.returnValues().add(new StringArray(s)); 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 testRpcMethodUpdateSources() { Request req = new Request("updateSources"); String spec1 = "tcp/a:19070"; String spec2 = "tcp/b:19070"; req.parameters().add(new StringValue(spec1 + "," + spec2)); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); assertThat(req.returnValues().size(), is(1)); assertThat(req.returnValues().get(0).asString(), is("Updated config sources to: " + spec1 + "," + spec2)); server.proxyServer().setMode(Mode.ModeName.MEMORYCACHE.name()); req = new Request("updateSources"); req.parameters().add(new StringValue(spec1 + "," + spec2)); client.invoke(req); assertFalse(req.errorMessage(), req.isError()); assertThat(req.returnValues().size(), is(1)); assertThat(req.returnValues().get(0).asString(), is("Cannot update sources when in '" + Mode.ModeName.MEMORYCACHE.name().toLowerCase() + "' mode")); }