DatabusRequest implements Callable<DatabusRequest>, Future<DatabusRequest> { @Override public String toString() { StringBuilder res = new StringBuilder(); res.append("{\"name\":\""); res.append(_name); res.append("\", \"method\":\""); res.append(_requestType); res.append("\" "); for (Object key:_params.keySet()) { Object value = _params.get(key); res.append(", \""); res.append(key.toString()); res.append("\":\""); res.append(null != value ? value.toString() : "null"); res.append("\""); } res.append("}"); return res.toString(); } DatabusRequest(String name, HttpMethod requestType, SocketAddress remoteAddress,
                        Properties params, ServerContainer.RuntimeConfig config);  DatabusRequest(String name, HttpMethod requestType, SocketAddress remoteAddress,
                        ServerContainer.RuntimeConfig config); String getName(); Properties getParams(); @Override String toString(); ChunkedWritableByteChannel getResponseContent(); Throwable getResponseThrowable(); @Override DatabusRequest call(); RequestProcessor getProcessor(); void setProcessor(RequestProcessor processor); void setError(Throwable throwable); PhysicalPartition getCursorPartition(); void setCursorPartition(PhysicalPartition cursorPartition); HttpMethod getRequestType(); ServerContainer.RuntimeConfig getConfig(); int getRequiredIntParam(String paramName); int getOptionalIntParam(String paramName, int defaultValue); long getRequiredLongParam(String paramName); long getOptionalLongParam(String paramName, long defaultValue); String getRequiredStringParam(String paramName); @Override boolean cancel(boolean arg0); @Override DatabusRequest get(); @Override DatabusRequest get(long arg0, TimeUnit arg1); @Override boolean isCancelled(); @Override boolean isDone(); void setResponseContent(ChunkedWritableByteChannel responseContent); long getId(); long getCreateTimestampMs(); SocketAddress getRemoteAddress(); static final String MODULE; static final Logger LOG; static final String DATA_PARAM_NAME; static final String PATH_PARAM_NAME; }
@Test public void testToString() throws Exception { DatabusRequest req = makeRequest(); String jsonStr = req.toString(); Map<String, String> jsonMap = _objectMapper.readValue(jsonStr.getBytes(Charset.defaultCharset()), new TypeReference<Map<String, String>>() {}); Assert.assertEquals(reqName, jsonMap.get("name")); Assert.assertEquals(method.toString(), jsonMap.get("method")); Assert.assertEquals(propval1, jsonMap.get(prop1)); Assert.assertEquals(propval2, jsonMap.get(prop2)); Assert.assertEquals(4, jsonMap.size()); Assert.assertEquals(req, req.call()); PhysicalPartition pp = new PhysicalPartition(15, "SomePartition"); req.setCursorPartition(pp); Assert.assertEquals(pp, req.getCursorPartition()); Assert.assertFalse(req.cancel(true)); Assert.assertFalse(req.cancel(false)); Assert.assertEquals(req, req.get()); Assert.assertEquals(req, req.get(89L, TimeUnit.HOURS)); Assert.assertFalse(req.isCancelled()); InetSocketAddress remoteAddress = (InetSocketAddress)req.getRemoteAddress(); Assert.assertEquals(port, remoteAddress.getPort()); Assert.assertEquals(InetAddress.getByAddress(ipAddr), remoteAddress.getAddress()); }