Repository navigation
MCP: admit calls chained on another's end, match only in-range stdio ids #1666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
org.restlet.ext.mcp/src/test/java/org/restlet/ext/mcp/McpWorkersTestCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /** | ||
| * Copyright 2005-2026 Qlik | ||
| *<p> | ||
| * The content of this file is subject to the terms of the Apache 2.0 open | ||
| * source license available at https://www.opensource.org/licenses/apache-2.0 | ||
| *<p> | ||
| * Restlet is a registered trademark of QlikTech International AB. | ||
| */ | ||
| package org.restlet.ext.mcp; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.restlet.ext.mcp.internal.McpWorkers; | ||
|
|
||
| /** The admission workers shared by the MCP transports. */ | ||
| class McpWorkersTestCase { | ||
|
|
||
| /** A call chained on the end of another is admitted, with a single slot. */ | ||
| @Test | ||
| void aChainedCallIsAdmittedWithOneSlot() throws Exception { | ||
| McpWorkers workers = new McpWorkers(1, Duration.ofSeconds(5)); | ||
| AtomicInteger calls = new AtomicInteger(); | ||
| try { | ||
| assertDoesNotThrow( | ||
| () -> | ||
| workers.submit(calls::incrementAndGet, () -> {}) | ||
| .then(workers.submit(calls::incrementAndGet, () -> {})) | ||
| .block(Duration.ofSeconds(5))); | ||
| assertEquals(2, calls.get()); | ||
| } finally { | ||
| workers.close(); | ||
| } | ||
| } | ||
|
|
||
| /** A call failing with an Error ends with it, and no longer counts as running. */ | ||
| @Test | ||
| void aCallFailingWithAnErrorEnds() throws Exception { | ||
| McpWorkers workers = new McpWorkers(1, Duration.ofSeconds(5)); | ||
| try { | ||
| reactor.core.publisher.Mono<Void> call = | ||
| workers.submit( | ||
| () -> { | ||
| throw new AssertionError("broken"); | ||
| }, | ||
| () -> {}); | ||
| RuntimeException blocked = | ||
| org.junit.jupiter.api.Assertions.assertThrows( | ||
|
Check warning on line 55 in org.restlet.ext.mcp/src/test/java/org/restlet/ext/mcp/McpWorkersTestCase.java
|
||
| RuntimeException.class, () -> call.block(Duration.ofSeconds(5))); | ||
| Throwable failure = reactor.core.Exceptions.unwrap(blocked); | ||
| assertTrue(failure instanceof AssertionError, failure.toString()); | ||
| assertEquals("broken", failure.getMessage()); | ||
| assertTrue(workers.awaitIdle(Duration.ofSeconds(5))); | ||
| } finally { | ||
| workers.close(); | ||
| } | ||
| } | ||
|
|
||
| /** A call is running until the subscribers of its end are done. */ | ||
| @Test | ||
| void awaitIdleWaitsForTheSubscribersOfTheEnd() throws Exception { | ||
| McpWorkers workers = new McpWorkers(1, Duration.ofSeconds(5)); | ||
| CountDownLatch entered = new CountDownLatch(1); | ||
| CountDownLatch release = new CountDownLatch(1); | ||
| try { | ||
| workers.submit(() -> {}, () -> {}) | ||
| .doOnSuccess( | ||
| ignored -> { | ||
| entered.countDown(); | ||
| try { | ||
| release.await(5, TimeUnit.SECONDS); | ||
| } catch (InterruptedException _) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| }) | ||
| .subscribe(); | ||
| assertTrue(entered.await(5, TimeUnit.SECONDS)); | ||
|
|
||
| assertFalse(workers.awaitIdle(Duration.ofMillis(50))); | ||
| release.countDown(); | ||
| assertTrue(workers.awaitIdle(Duration.ofSeconds(5))); | ||
| } finally { | ||
| workers.close(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.