CoreQueryManager implements QueryManager { DateRange buildShiftedRange(DateRange rawRange, long cadence, long now) { if (rawRange.getStart() > now) { throw new IllegalArgumentException("start is greater than now"); } final DateRange rounded = rawRange.rounded(cadence); final long nowDelta = now - rounded.getEnd(); if (nowDelta > SHIFT_TOLERANCE) { return rounded; } final long diff = Math.abs(Math.min(nowDelta, 0)) + SHIFT_TOLERANCE; return rounded.shift(-toleranceShiftPeriod(diff, cadence)); } @Inject  CoreQueryManager(
        @Named("features") final Features features,
        final AsyncFramework async,
        final Clock clock,
        final ClusterManager cluster,
        final QueryParser parser,
        final QueryCache queryCache,
        final AggregationFactory aggregations,
        @Named("groupLimit") final OptionalLimit groupLimit,
        @Named("smallQueryThreshold") final long smallQueryThreshold,
        final QueryReporter reporter,
        final Optional<ConditionalFeatures> conditionalFeatures,
        final QueryLoggerFactory queryLoggerFactory
    ); @Override QueryManager.Group useOptionalGroup(final Optional<String> group); @Override QueryBuilder newQueryFromString(final String queryString); static final long SHIFT_TOLERANCE; static final QueryTrace.Identifier QUERY_SHARD; static final QueryTrace.Identifier QUERY; static final long INTERVAL_GOAL; }
@Test public void testEndRangeIsNow() { final DateRange range = DateRange.create(50_000L, 150_000L); final DateRange shiftedRange = manager.buildShiftedRange(range, 5_000, 150_000L); assertEquals(DateRange.create(40_000L, 140_000L), shiftedRange); }
@Test public void testEndRangeIsTooCloseToNow() { final DateRange range = DateRange.create(50_000L, 153_000L); final DateRange shiftedRange = manager.buildShiftedRange(range, 5_000, 154_000L); assertEquals(DateRange.create(40_000L, 140_000L), shiftedRange); }
@Test public void testEndRangeIsOk() { final DateRange range = DateRange.create(50_000L, 153_000L); final DateRange shiftedRange = manager.buildShiftedRange(range, 5_000, 184_000L); assertEquals(DateRange.create(50_000L, 150_000L), shiftedRange); }
@Test public void testEndRangeIsInTheFuture() { final DateRange range = DateRange.create(50_000L, 180_000L); final DateRange shiftedRange = manager.buildShiftedRange(range, 5_000, 150_000L); assertEquals(DateRange.create(10_000L, 140_000L), shiftedRange); }
@Test(expected = IllegalArgumentException.class) public void testStartRangeIsInTheFuture() { final DateRange range = DateRange.create(50_000L, 153_000L); manager.buildShiftedRange(range, 5_000, 40_000L); }