CoreIngestionGroup implements IngestionGroup { protected AsyncFuture<Ingestion> doWrite(final Request request) { final Span span = tracer.spanBuilder("CoreIngestionGroup.doWrite").startSpan(); final List<AsyncFuture<Ingestion>> futures = new ArrayList<>(); final Supplier<DateRange> range = rangeSupplier(request); metric.map(m -> doMetricWrite(m, request, span)).ifPresent(futures::add); metadata.map(m -> doMetadataWrite(m, request, range.get(), span)) .ifPresent(futures::add); suggest.map(s -> doSuggestWrite(s, request, range.get(), span)).ifPresent(futures::add); return async.collect(futures, Ingestion.reduce()).onFinished(span::end); } CoreIngestionGroup(
        final AsyncFramework async,
        final Supplier<Filter> filter,
        final Semaphore writePermits,
        final IngestionManagerReporter reporter,
        final LongAdder ingested,
        final Optional<MetricBackend> metric,
        final Optional<MetadataBackend> metadata,
        final Optional<SuggestBackend> suggest
    ); @Override Groups groups(); @Override AsyncFuture<Ingestion> write(final Request request); @Override boolean isEmpty();  }
@Test public void testDoWrite() { final CoreIngestionGroup group = setupIngestionGroup(of(metric), of(metadata), of(suggest)); final List<AsyncFuture<Ingestion>> futures = ImmutableList.of(other, other, other); doReturn(rangeSupplier).when(group).rangeSupplier(request); doReturn(expected).when(async).collect(futures, Ingestion.reduce()); doReturn(other).when(group).doMetricWrite(eq(metric), eq(request), any()); doReturn(other).when(group).doMetadataWrite(eq(metadata), eq(request), eq(range), any()); doReturn(other).when(group).doSuggestWrite(eq(suggest), eq(request), eq(range), any()); assertEquals(expected, group.doWrite(request)); verify(group).rangeSupplier(request); verify(group).doMetricWrite(eq(metric), eq(request), any()); verify(group).doMetadataWrite(eq(metadata), eq(request), eq(range), any()); verify(group).doSuggestWrite(eq(suggest), eq(request), eq(range), any()); verify(rangeSupplier, times(2)).get(); }