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 @@ -78,6 +78,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -186,6 +187,8 @@ public boolean isValidateHostnames()
throw new RuntimeException(e);
}

final int ephemeralPort = ThreadLocalRandom.current().nextInt(49152, 65535);

latchedRequestState = new LatchedRequestStateHolder();
injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(),
Expand All @@ -198,7 +201,7 @@ public void configure(Binder binder)
JsonConfigProvider.bindInstance(
binder,
Key.get(DruidNode.class, Self.class),
new DruidNode("test", "localhost", false, 9988, 9999, true, true)
new DruidNode("test", "localhost", false, ephemeralPort, ephemeralPort + 1, true, true)
);
binder.bind(TLSServerConfig.class).toInstance(tlsConfig);
binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
Expand Down Expand Up @@ -450,6 +453,7 @@ public void testNumConnectionsMetricHttp() throws Exception

JettyServerModule jsm = injector.getInstance(JettyServerModule.class);
latchedRequestState.reset();
waitForJettyServerModuleActiveConnectionsZero(jsm);

Assert.assertEquals(0, jsm.getActiveConnections());
ListenableFuture<InputStream> go = client.go(
Expand Down Expand Up @@ -489,6 +493,7 @@ public void testNumConnectionsMetricHttps() throws Exception
JettyServerModule jsm = injector.getInstance(JettyServerModule.class);
latchedRequestState.reset();

waitForJettyServerModuleActiveConnectionsZero(jsm);
Assert.assertEquals(0, jsm.getActiveConnections());
ListenableFuture<InputStream> go = client.go(
request,
Expand All @@ -511,5 +516,8 @@ private void waitForJettyServerModuleActiveConnectionsZero(JettyServerModule jsm
while (jsm.getActiveConnections() > 0 && count++ < totalSleeps) {
Thread.sleep(sleepTimeMills);
}
if (jsm.getActiveConnections() > 0) {
throw new RuntimeException("Connections greater than 0");
}
}
}