AnalyticsResource { @POST @Path("/async") public AsyncDataToken runSyncAsync(final ActionRequest request) { try { return queryExecutor.executeAsync(request); } catch (QueryStoreException e) { logger.error(String.format("Error running async request %s", request), e); throw new WebApplicationException( Response.serverError().entity(Collections.singletonMap("error", e.getMessage())).build()); } } AnalyticsResource(QueryExecutor queryExecutor); @POST ActionResponse runSync(final ActionRequest request); @POST @Path("/async") AsyncDataToken runSyncAsync(final ActionRequest request);  }
@Test public void testRunSyncAsync() throws Exception { GroupRequest groupRequest = new GroupRequest(); groupRequest.setTable(TestUtils.TEST_TABLE_NAME); groupRequest.setNesting(Arrays.asList("os", "device", "version")); Map<String, Object> expectedResponse = new LinkedHashMap<String, Object>(); final Map<String, Object> nexusResponse = new LinkedHashMap<String, Object>(){{ put("1", 2); put("2", 2); put("3", 1); }}; final Map<String, Object> galaxyResponse = new LinkedHashMap<String, Object>(){{ put("2", 1); put("3", 1); }}; expectedResponse.put("android", new LinkedHashMap<String, Object>() {{ put("nexus", nexusResponse); put("galaxy", galaxyResponse); }}); final Map<String, Object> nexusResponse2 = new LinkedHashMap<String, Object>(){{ put("2", 1);}}; final Map<String, Object> iPadResponse = new LinkedHashMap<String, Object>(){{ put("2", 2); }}; final Map<String, Object> iPhoneResponse = new LinkedHashMap<String, Object>(){{ put("1", 1); }}; expectedResponse.put("ios", new LinkedHashMap<String, Object>() {{ put("nexus", nexusResponse2); put("ipad", iPadResponse); put("iphone", iPhoneResponse); }}); WebResource webResource = client().resource("/v1/analytics/async"); AsyncDataToken response = webResource.type(MediaType.APPLICATION_JSON_TYPE).post(AsyncDataToken.class, groupRequest); Thread.sleep(2000); GroupResponse actualResponse = GroupResponse.class.cast(CacheUtils.getCacheFor(response.getAction()).get(response.getKey())); assertEquals(expectedResponse, actualResponse.getResult()); }