Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -574,13 +575,24 @@ private void assertLargeRequestBuffer(Session session, int threshold) {
}
}

private void assertDiscoveryBufferThreshold(SessionPool pool, int threshold) {
private void assertDiscoveryBufferThreshold(SessionPool pool, int threshold)
throws InterruptedException {
NodesSupplier current = Whitebox.getInternalState(pool, "availableNodes");
current.run();
ThriftConnection connection = Whitebox.getInternalState(current, "client");
AutoScalingBufferWriteTransport output = assertTransportBufferThreshold(connection, threshold);
if (threshold == 0) {
assertEquals(32, output.getBuffer().length);
// The pool starts its first discovery refresh immediately, and run() returns at once while
// another refresh holds refreshLock. Holding the reentrant lock waits for that refresh and
// keeps the discovery connection idle while run() refreshes it and its buffers are checked.
ReentrantLock refreshLock = Whitebox.getInternalState(current, "refreshLock");
assertTrue(refreshLock.tryLock(10, TimeUnit.SECONDS));
try {
current.run();
ThriftConnection connection = Whitebox.getInternalState(current, "client");
AutoScalingBufferWriteTransport output =
assertTransportBufferThreshold(connection, threshold);
if (threshold == 0) {
assertEquals(32, output.getBuffer().length);
}
} finally {
refreshLock.unlock();
}
}

Expand Down
Loading