@VisibleForTesting
    static void findStartPointLoop(Position p, long start, long end,
                                           CompletableFuture<Long> promise,
                                           AsyncLoadingCache<Long, MessageIdData> cache) {
        long midpoint = start + ((end - start) / 2);

        CompletableFuture<MessageIdData> startEntry = cache.get(start);
        CompletableFuture<MessageIdData> middleEntry = cache.get(midpoint);
        CompletableFuture<MessageIdData> endEntry = cache.get(end);

        CompletableFuture.allOf(startEntry, middleEntry, endEntry).thenRun(
                () -> {
                    if (comparePositionAndMessageId(p, startEntry.join()) <= 0) {
                        promise.complete(start);
                    } else if (comparePositionAndMessageId(p, middleEntry.join()) <= 0) {
                        findStartPointLoop(p, start + 1, midpoint, promise, cache);
                    } else if (comparePositionAndMessageId(p, endEntry.join()) <= 0) {
                        findStartPointLoop(p, midpoint + 1, end, promise, cache);
                    } else {
                        promise.complete(NEWER_THAN_COMPACTED);
                    }
                }).exceptionally((exception) -> {
                        promise.completeExceptionally(exception);
                        return null;
                    });
    }
@Test(dataProvider = "argsForFindStartPointLoop")
    public void testFindStartPointLoop(long start, long end, long targetMessageId) {
        AtomicLong bingoMarker = new AtomicLong();
        // Mock cache.
        AsyncLoadingCache<Long, MessageIdData> cache = Caffeine.newBuilder()
                .buildAsync(mockCacheLoader(start, end, targetMessageId, bingoMarker));
        // Do test.
        Position targetPosition = PositionFactory.create(DEFAULT_LEDGER_ID, targetMessageId);
        CompletableFuture<Long> promise = new CompletableFuture<>();
        CompactedTopicImpl.findStartPointLoop(targetPosition, start, end, promise, cache);
        long result = promise.join();
        assertEquals(result, bingoMarker.get());
    }