|
13 | 13 | package io.nats; |
14 | 14 |
|
15 | 15 | import org.junit.jupiter.api.Test; |
| 16 | +import org.junit.jupiter.api.parallel.Isolated; |
16 | 17 | import org.junit.jupiter.params.ParameterizedTest; |
17 | 18 | import org.junit.jupiter.params.provider.Arguments; |
18 | 19 | import org.junit.jupiter.params.provider.MethodSource; |
19 | 20 |
|
20 | 21 | import java.io.IOException; |
| 22 | +import java.nio.file.Files; |
21 | 23 | import java.nio.file.Path; |
22 | 24 | import java.nio.file.Paths; |
23 | 25 | import java.util.*; |
|
31 | 33 | import static io.nats.NatsServerRunner.getDefaultOutputSupplier; |
32 | 34 | import static org.junit.jupiter.api.Assertions.*; |
33 | 35 |
|
| 36 | +@Isolated |
34 | 37 | public class NatsServerRunnerTest extends TestBase { |
35 | 38 |
|
36 | 39 | private static Stream<Arguments> debugAndJetStreamArgs() { |
@@ -386,9 +389,38 @@ public void testBadConfig() throws Exception { |
386 | 389 | .output(new ConsoleOutput()) |
387 | 390 | .build()) |
388 | 391 | { |
| 392 | + fail("Config was bad, should have exceptioned."); |
389 | 393 | } |
390 | 394 | catch (Exception e) { |
391 | 395 | assertTrue(e.getMessage().contains("nats-server: Parse error on line 2")); |
392 | 396 | } |
393 | 397 | } |
| 398 | + |
| 399 | + @Test |
| 400 | + public void testBuilderPortTakesPrecedence() throws Exception { |
| 401 | + String[] configInserts = new String[] {"port:4777"}; |
| 402 | + |
| 403 | + NatsServerRunner.Builder b = NatsServerRunner.builder() |
| 404 | + .debug(false) |
| 405 | + .jetstream(true) |
| 406 | + .configInserts(configInserts) |
| 407 | + .port(4242) |
| 408 | + .connectCheckTries(0) |
| 409 | + ; |
| 410 | + |
| 411 | + try (NatsServerRunner runner = b.build()) { |
| 412 | + List<String> lines = Files.readAllLines(Paths.get(runner.getConfigFile())); |
| 413 | + int portCount = 0; |
| 414 | + int portFound = -1; |
| 415 | + for (String line : lines) { |
| 416 | + if (line.startsWith("port:")) { |
| 417 | + portCount++; |
| 418 | + portFound = Integer.parseInt(line.substring(5).trim()); |
| 419 | + } |
| 420 | + } |
| 421 | + assertEquals(4242, runner.getPort()); |
| 422 | + assertEquals(1, portCount); |
| 423 | + assertEquals(4242, portFound); |
| 424 | + } |
| 425 | + } |
394 | 426 | } |
0 commit comments