|
12 | 12 | import static org.awaitility.Awaitility.await; |
13 | 13 | import static org.mockito.Mockito.mock; |
14 | 14 |
|
| 15 | +import java.io.ByteArrayOutputStream; |
| 16 | +import java.io.IOException; |
| 17 | +import java.io.PrintStream; |
15 | 18 | import java.net.URI; |
16 | 19 | import java.net.http.HttpClient; |
17 | 20 | import java.net.http.HttpRequest; |
|
29 | 32 | import java.util.function.Function; |
30 | 33 | import java.util.stream.Collectors; |
31 | 34 |
|
| 35 | +import io.modelcontextprotocol.spec.McpClientTransport; |
32 | 36 | import org.junit.jupiter.params.ParameterizedTest; |
33 | 37 | import org.junit.jupiter.params.provider.ValueSource; |
34 | 38 |
|
@@ -66,6 +70,8 @@ public abstract class AbstractMcpClientServerIntegrationTests { |
66 | 70 |
|
67 | 71 | protected ConcurrentHashMap<String, McpClient.SyncSpec> clientBuilders = new ConcurrentHashMap<>(); |
68 | 72 |
|
| 73 | + protected ConcurrentHashMap<String, McpClientTransport> clientTransportBuilders = new ConcurrentHashMap<>(); |
| 74 | + |
69 | 75 | abstract protected void prepareClients(int port, String mcpEndpoint); |
70 | 76 |
|
71 | 77 | abstract protected McpServer.AsyncSpecification<?> prepareAsyncServerBuilder(); |
@@ -836,7 +842,7 @@ void testThrowingToolCallIsCaughtBeforeTimeout(String clientType) { |
836 | 842 |
|
837 | 843 | @ParameterizedTest(name = "{0} : {displayName} ") |
838 | 844 | @ValueSource(strings = { "httpclient", "webflux" }) |
839 | | - void testToolCallSuccessWithTranportContextExtraction(String clientType) { |
| 845 | + void testToolCallSuccessWithTransportContextExtraction(String clientType) { |
840 | 846 |
|
841 | 847 | var clientBuilder = clientBuilders.get(clientType); |
842 | 848 |
|
@@ -999,6 +1005,32 @@ void testInitialize(String clientType) { |
999 | 1005 | mcpServer.close(); |
1000 | 1006 | } |
1001 | 1007 |
|
| 1008 | + @ParameterizedTest(name = "{0} : {displayName} ") |
| 1009 | + @ValueSource(strings = { "httpclient", "webflux" }) |
| 1010 | + void testListeningStreamWillClosedWhenNew(String clientType) throws IOException { |
| 1011 | + var clientTransport = clientTransportBuilders.get(clientType); |
| 1012 | + if (clientTransport == null) { |
| 1013 | + return; |
| 1014 | + } |
| 1015 | + PrintStream originalOut = System.out; |
| 1016 | + ByteArrayOutputStream capturedOutput = new ByteArrayOutputStream(); |
| 1017 | + System.setOut(new PrintStream(capturedOutput)); |
| 1018 | + |
| 1019 | + var clientBuilder = clientBuilders.get(clientType); |
| 1020 | + var mcpServer = prepareSyncServerBuilder().build(); |
| 1021 | + var mcpClient = clientBuilder.build(); |
| 1022 | + InitializeResult initResult = mcpClient.initialize(); |
| 1023 | + assertThat(initResult).isNotNull(); |
| 1024 | + clientTransport.connect(message -> Mono.empty()).subscribe(); |
| 1025 | + await().atMost(Duration.ofSeconds(1)).untilAsserted(() -> { |
| 1026 | + assertThat(capturedOutput.toString().contains("Listening stream already exists for this session")).isTrue(); |
| 1027 | + }); |
| 1028 | + System.setOut(originalOut); |
| 1029 | + capturedOutput.close(); |
| 1030 | + mcpClient.close(); |
| 1031 | + mcpServer.close(); |
| 1032 | + } |
| 1033 | + |
1002 | 1034 | // --------------------------------------- |
1003 | 1035 | // Logging Tests |
1004 | 1036 | // --------------------------------------- |
|
0 commit comments