/** * Marks the start of a query identified by the provided correlationId, with additional query type and data parameters * * @param query - Query data * @param correlationId - Identifier * @param type - allows queries to be grouped by type * @return Start event to pass to the Events systems EventBus */ public static <T> AddQuery<T> start(T query, long correlationId, String type) { return start(query, correlationId, type, null); }
/** * Marks the start of a query identified by the provided correlationId * * @param query - Query data * @param correlationId - Identifier * @return Start event to pass to the Events systems EventBus */ public static <T> AddQuery<T> start(T query, long correlationId) { return start(query, correlationId, "default", null); }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try{ return "ok"; }finally{ bus.post(RequestEvents.finish("get",1l)); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try { return "ok"; } finally { bus.post(RequestEvents.finish("get", 1l)); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try { return "ok"; } finally { bus.post(RequestEvents.finish("get", 1l)); } }
@GET @Produces("text/plain") @Path("/ping-custom") public String pingCustom() { RequestEvents.start("get", 1l, bus, "typeA", "custom"); try { return "ok"; } finally { RequestEvents.finish("get", 1l, bus, "typeA", "custom"); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { bus.post(RequestEvents.start("get", 1l)); try{ return "ok"; }finally{ bus.post(RequestEvents.finish("get",1l)); } }
@GET @Produces("text/plain") @Path("/ping-custom") public String pingCustom() { bus.post(RequestEvents.start("get", 1l, "custom")); try { return "ok"; } finally { bus.post(RequestEvents.finish("get", 1l, "custom")); } }
@GET @Produces("text/plain") @Path("/ping") public String ping() { RequestEvents.start("get", 1l, bus, "typeA", "custom"); try { return "ok"; } finally { RequestEvents.finish("get", 1l, bus, "typeA", "custom"); } }
@Test public void oneEventSize() { bus.post(RequestEvents.start("data", 100l)); assertThat(requests.size(), is(1)); }
@Test public void oneEvent() { bus.post(RequestEvents.start("data", 100l)); assertThat(requests.events(), is(1)); }
@Test public void testToString() { bus.post(RequestEvents.start("data", 100l)); bus.post(RequestEvents.start("data", 120l)); bus.post(RequestEvents.finish("data", 120l)); System.out.println(requests.toString()); assertThat(requests.toString(), containsString("\"removed\":1")); assertThat(requests.toString(), containsString("\"added\":2")); }
@Test public void twoEventsDifferentTypesOneFinishedDefaultTypeIsIgnored() { requests = new RequestsBeingExecuted( bus, "typeA"); types.getMap() .put("typeA", requests); bus.post(RequestEvents.start("data", 130l)); bus.post(RequestEvents.start("data", 120l, "typeA", "data2")); bus.post(RequestEvents.finish("data", 120l, "typeA")); assertThat(requests.events(), is(1)); assertThat(requests.size(), is(0)); }
@Test public void whenQueriesWithTheSameIdToDifferentTypesEventsIs1ForBoth() { bus.post(RequestEvents.start("query", 1l)); bus.post(RequestEvents.start("query", 1l, "partition", ImmutableMap.of())); MockAsyncResponse<String> response = new MockAsyncResponse<>(); active.activeRequests(response, null); assertThat(convert(response.response()).get("events"), is(1)); active.activeRequests(response, "partition"); assertThat(convert(response.response()).get("events"), is(1)); }
@Test public void whenQueriesWithTheSameIdButSameTypesEventsIs2ButSizeIs1() { bus.post(RequestEvents.start("query", 1l)); bus.post(RequestEvents.start("query", 1l)); MockAsyncResponse<String> response = new MockAsyncResponse<>(); active.activeRequests(response, null); assertThat(convert(response.response()).get("events"), is(2)); active.activeRequests(response, null); Map map = convert(response.response()); assertThat(((Map) map.get("active")).size(), is(1)); }