This repository was archived by the owner on Mar 3, 2026. It is now read-only.
forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatchTest.java
More file actions
84 lines (70 loc) · 2.14 KB
/
Copy pathDispatchTest.java
File metadata and controls
84 lines (70 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package apps;
import io.jooby.App;
import io.jooby.AppTest;
import io.jooby.Context;
import io.jooby.Route;
import io.jooby.WebClient;
import io.reactivex.Flowable;
import io.reactivex.schedulers.Schedulers;
import org.jooby.funzy.Throwing;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.concurrent.ForkJoinPool;
@AppTest
public class DispatchTest extends App {
{
get("/def-worker", ctx -> {
/**
* Dispatch to default executor:
*/
ctx.dispatch();
return Thread.currentThread().getName();
});
get("/custom-worker", ctx -> {
/**
* Dispatch to custom executor:
*/
ctx.dispatch(ForkJoinPool.commonPool());
return Thread.currentThread().getName();
});
before("/pipe/**", ctx -> {
ctx.header("p1", "1:" + ctx.isInIoThread());
});
before("/pipe/2", ctx -> {
ctx.dispatch();
ctx.header("p2", "2:" + ctx.isInIoThread());
});
before("/pipe/**", ctx -> {
ctx.header("p3", "3:" + ctx.isInIoThread());
});
get("/pipe/:id", ctx -> {
ctx.header("p4", "4:" + ctx.isInIoThread());
return "pipe-with-dispatch";
});
}
@Test
public void dispathToDefaultWorker(WebClient client) throws IOException {
client.get("/def-worker", rsp -> {
assertTrue(rsp.body().string().toLowerCase().startsWith("defaulteventexecutor"));
});
}
@Test
public void dispathToCustomWorker(WebClient client) throws IOException {
client.get("/custom-worker", rsp -> {
assertTrue(rsp.body().string().toLowerCase().startsWith("forkjoinpool"));
});
}
@Test
public void ableToDispatchWillExecutingAPipeline(WebClient client) throws IOException {
client.get("/pipe/2", rsp -> {
assertEquals("1:true", rsp.header("p1"));
assertEquals("2:false", rsp.header("p2"));
assertEquals("3:false", rsp.header("p3"));
assertEquals("4:false", rsp.header("p4"));
assertEquals("pipe-with-dispatch", rsp.body().string());
});
}
}