Skip to content

Commit 7b69546

Browse files
committed
Context detaches when runnin in event-loop and returns a Context
1 parent 7127648 commit 7b69546

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

jooby/src/main/java/io/jooby/internal/Pipeline.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public static Handler compute(ClassLoader loader, Route route, ExecutionMode mod
135135
}
136136
/** Context: */
137137
if (Context.class.isAssignableFrom(type)) {
138+
if (executor == null && mode == ExecutionMode.EVENT_LOOP) {
139+
return next(mode, executor, new DetachHandler(route.getPipeline()), false);
140+
}
138141
return next(mode, executor, new SendDirect(route.getPipeline()), true);
139142
}
140143
/** InputStream: */

modules/jooby-jetty/src/main/java/io/jooby/jetty/Jetty.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package io.jooby.jetty;
77

8-
import io.jooby.ExecutionMode;
98
import io.jooby.Jooby;
109
import io.jooby.ServerOptions;
1110
import io.jooby.SneakyThrows;
@@ -63,8 +62,6 @@ public class Jetty extends io.jooby.Server.Base {
6362
System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize",
6463
Long.toString(options.getMaxRequestSize()));
6564

66-
/** Jetty only support worker executor: */
67-
application.setExecutionMode(ExecutionMode.WORKER);
6865
applications.add(application);
6966

7067
addShutdownHook();

tests/src/test/java/io/jooby/FeaturedTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import okhttp3.RequestBody;
1818
import okhttp3.Response;
1919
import okhttp3.ResponseBody;
20+
import org.junit.jupiter.api.DisplayName;
2021
import org.junit.jupiter.api.Test;
2122
import reactor.core.publisher.Flux;
2223
import reactor.core.publisher.Mono;
@@ -45,6 +46,7 @@
4546
import java.util.Map;
4647
import java.util.Optional;
4748
import java.util.Scanner;
49+
import java.util.concurrent.CompletableFuture;
4850
import java.util.concurrent.atomic.AtomicInteger;
4951
import java.util.function.Consumer;
5052
import java.util.stream.Collectors;
@@ -2459,6 +2461,23 @@ public void templateEngines() {
24592461
});
24602462
}
24612463

2464+
@Test
2465+
@DisplayName("Context detaches when running in event-loop and returns a Context")
2466+
public void detachOnEventLoop() {
2467+
new JoobyRunner(app -> {
2468+
app.get("/detach", ctx -> {
2469+
CompletableFuture.runAsync(() -> {
2470+
ctx.send(ctx.pathString());
2471+
});
2472+
return ctx;
2473+
});
2474+
}).mode(ExecutionMode.EVENT_LOOP).ready(client -> {
2475+
client.get("/detach", rsp -> {
2476+
assertEquals("/detach", rsp.body().string().trim());
2477+
});
2478+
});
2479+
}
2480+
24622481
private static String readText(Path file) {
24632482
try {
24642483
return new String(Files.readAllBytes(file), StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)