@Subscribe public void processing(AddQuery<T> data) { String id = buildId(data.getData()); String key = data.getData().type; map.computeIfAbsent(key, k -> new RequestsBeingExecuted<T>( bus, k)).events.active(id, data.getData()); }
private Object executeScheduledJob(final ProceedingJoinPoint pjp, final String type) throws Throwable { addTypeToStatCounter(type); JobExecutingData data = new JobExecutingData( type, statCounter.count(type)); String id = buildId(type, data.getProcessingThread()); events.active(id, data); SystemData retVal = null; long correlationId = r.nextLong(); eventBus.post(new JobStartEvent( correlationId, type)); try { retVal = Optional.ofNullable(((SystemData) pjp.proceed())) .map(sd -> sd.withCorrelationId(id)) .orElse(null); return retVal; } finally { logSystemEvent(pjp, type, data, retVal); retVal = Optional.ofNullable(retVal) .orElse(SystemData.builder() .correlationId("" + correlationId) .errors(0l) .processed(0l) .build()); eventBus.post(new JobCompleteEvent( correlationId, type, retVal.getErrors(), retVal.getProcessed())); } }
@Test public void testOneEvent() { activeEvents.active("hello", new BaseEventInfo()); assertThat(activeEvents.events(), is(1)); }
@Test public void testFinishedStringImmutableMap() { activeEvents.active("hello", new BaseEventInfo()); activeEvents.finished("hello", ImmutableMap.of("hello", "world")); assertThat(activeEvents.events(), is(1)); assertThat(activeEvents.size(), is(0)); assertThat(activeEvents.toString(), containsString("world")); }
@Test public void testFinishedString() { activeEvents.active("hello", new BaseEventInfo()); activeEvents.finished("hello"); assertThat(activeEvents.events(), is(1)); assertThat(activeEvents.size(), is(0)); }
@Subscribe public void processing(AddQuery<T> data) { String id = buildId(data.getData()); String key = data.getData().type; map.computeIfAbsent(key, k -> new RequestsBeingExecuted<T>( bus, k)).events.active(id, data.getData()); }
private Object executeScheduledJob(final ProceedingJoinPoint pjp, final String type) throws Throwable { addTypeToStatCounter(type); JobExecutingData data = new JobExecutingData( type, statCounter.count(type)); String id = buildId(type, data.getProcessingThread()); events.active(id, data); SystemData retVal = null; long correlationId = r.nextLong(); eventBus.post(new JobStartEvent( correlationId, type)); try { retVal = Optional.ofNullable(((SystemData) pjp.proceed())) .map(sd -> sd.withCorrelationId(id)) .orElse(null); return retVal; } finally { logSystemEvent(pjp, type, data, retVal); retVal = Optional.ofNullable(retVal) .orElse(SystemData.builder() .correlationId("" + correlationId) .errors(0l) .processed(0l) .build()); eventBus.post(new JobCompleteEvent( correlationId, type, retVal.getErrors(), retVal.getProcessed())); } }