AsyncDataWriter implements DataWriter<T> { @Override public Future<Void> saveAndIncrement(T data) { String correlationId = "" + System.currentTimeMillis() + ":" + r.nextLong(); Supplier<MapX<String, String>> dataMap = () -> MapX.fromMap(HashMapBuilder.map(MANIFEST_COMPARATOR_DATA_WRITER_KEY, comparator.toString()) .build()); return Future.<Void> of(() -> { comparator.saveAndIncrement(data); return null; } , executorService) .peek(t -> bus.post(SystemData.<String, String> builder() .correlationId(correlationId) .dataMap(dataMap.get()) .errors(0) .processed(1) .build())); }  static AsyncDataWriter<T> asyncDataWriter(Executor executorService, ManifestComparator<T> comparator); static AsyncDataWriter<T> asyncDataWriter(Executor executorService, ManifestComparator<T> comparator,
            EventBus bus); @Override Future<T> loadAndGet(); @Override Future<Void> saveAndIncrement(T data); @Override Future<Boolean> isOutOfDate(); static final String MANIFEST_COMPARATOR_DATA_LOADER_KEY; static final String MANIFEST_COMPARATOR_DATA_WRITER_KEY; }
@Test public void testSaveAndIncrement() { assertThat(eventRecieved.get(), equalTo(0)); writer.saveAndIncrement("boo!"); Future<String> res = writer.loadAndGet(); assertThat(res.get(), equalTo(Try.success("boo!"))); assertThat(eventRecieved.get(), equalTo(2)); }