@@ -103,6 +103,9 @@ public class StreamPerfTest implements Callable<Integer> {
103103 @ CommandLine .Mixin
104104 private final CommandLine .HelpCommand helpCommand = new CommandLine .HelpCommand ();
105105
106+ // for testing
107+ private final AddressResolver addressResolver ;
108+
106109 int streamDispatching = 0 ;
107110
108111 @ CommandLine .Option (
@@ -334,10 +337,14 @@ public class StreamPerfTest implements Callable<Integer> {
334337
335338 // constructor for completion script generation
336339 public StreamPerfTest () {
337- this (null , null , null );
340+ this (null , null , null , null );
338341 }
339342
340- public StreamPerfTest (String [] arguments , PrintStream consoleOut , PrintStream consoleErr ) {
343+ public StreamPerfTest (
344+ String [] arguments ,
345+ PrintStream consoleOut ,
346+ PrintStream consoleErr ,
347+ AddressResolver addressResolver ) {
341348 this .arguments = arguments ;
342349 if (consoleOut == null ) {
343350 consoleOut = System .out ;
@@ -347,16 +354,22 @@ public StreamPerfTest(String[] arguments, PrintStream consoleOut, PrintStream co
347354 }
348355 this .out = new PrintWriter (consoleOut , true );
349356 this .err = new PrintWriter (consoleErr , true );
357+ this .addressResolver = addressResolver ;
350358 }
351359
352360 public static void main (String [] args ) throws IOException {
353361 LogUtils .configureLog ();
354- int exitCode = run (args , System .out , System .err );
362+ int exitCode = run (args , System .out , System .err , null );
355363 System .exit (exitCode );
356364 }
357365
358- static int run (String [] args , PrintStream consoleOut , PrintStream consoleErr ) {
359- StreamPerfTest streamPerfTest = new StreamPerfTest (args , consoleOut , consoleErr );
366+ static int run (
367+ String [] args ,
368+ PrintStream consoleOut ,
369+ PrintStream consoleErr ,
370+ AddressResolver addressResolver ) {
371+ StreamPerfTest streamPerfTest =
372+ new StreamPerfTest (args , consoleOut , consoleErr , addressResolver );
360373 CommandLine commandLine =
361374 new CommandLine (streamPerfTest ).setOut (streamPerfTest .out ).setErr (streamPerfTest .err );
362375
@@ -497,7 +510,7 @@ public Integer call() throws Exception {
497510 closeStep ("Closing environment executor" , () -> envExecutor .shutdownNow ()));
498511
499512 boolean tls = isTls (this .uris );
500- AddressResolver addressResolver ;
513+ AddressResolver addrResolver ;
501514 if (loadBalancer ) {
502515 int defaultPort = tls ? Client .DEFAULT_TLS_PORT : Client .DEFAULT_PORT ;
503516 List <Address > addresses =
@@ -518,16 +531,20 @@ public Integer call() throws Exception {
518531 uriItem .getPort () == -1 ? defaultPort : uriItem .getPort ()))
519532 .collect (Collectors .toList ());
520533 AtomicInteger connectionAttemptCount = new AtomicInteger (0 );
521- addressResolver =
534+ addrResolver =
522535 address -> addresses .get (connectionAttemptCount .getAndIncrement () % addresses .size ());
523536 } else {
524- addressResolver = address -> address ;
537+ if (this .addressResolver == null ) {
538+ addrResolver = address -> address ;
539+ } else {
540+ addrResolver = this .addressResolver ; // should happen only in tests
541+ }
525542 }
526543
527544 EnvironmentBuilder environmentBuilder =
528545 Environment .builder ()
529546 .uris (this .uris )
530- .addressResolver (addressResolver )
547+ .addressResolver (addrResolver )
531548 .scheduledExecutorService (envExecutor )
532549 .metricsCollector (metricsCollector )
533550 .byteBufAllocator (byteBufAllocator )
0 commit comments