DefaultEventLoopScheduler implements EventLoopScheduler { int acquisitionStartIndex(int need) { for (;;) { final int current = acquisitionStartIndex; final int next = (current + need) % eventLoops.size(); if (acquisitionStartIndexUpdater.compareAndSet(this, current, next)) { return current; } } } DefaultEventLoopScheduler(EventLoopGroup eventLoopGroup, int maxNumEventLoopsPerEndpoint,
                              int maxNumEventLoopsPerHttp1Endpoint,
                              List<ToIntFunction<Endpoint>> maxNumEventLoopsFunctions); @Override ReleasableHolder<EventLoop> acquire(SessionProtocol sessionProtocol,
                                               EndpointGroup endpointGroup,
                                               @Nullable Endpoint endpoint);  }
@Test void acquisitionStartIndexIsRandomUnderEventLoopSize() { final List<Integer> startIndices = new ArrayList<>(); for (int i = 0; i < 30; i++) { final DefaultEventLoopScheduler s = new DefaultEventLoopScheduler(group, 0, 0, ImmutableList.of()); startIndices.add(s.acquisitionStartIndex(1)); } assertThat(startIndices).contains(0, 1, 2); assertThat(startIndices).doesNotContain(3); }