Skip to content

Commit d8bfdc0

Browse files
Add unit tests for server worker executor.
1 parent 97696ef commit d8bfdc0

5 files changed

Lines changed: 38 additions & 20 deletions

File tree

jooby-jetty/src/test/java/org/jooby/internal/jetty/JettyServerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.jooby.internal.jetty;
22

3+
import static org.easymock.EasyMock.expect;
34
import static org.easymock.EasyMock.expectLastCall;
45
import static org.easymock.EasyMock.isA;
6+
import static org.junit.Assert.assertNotNull;
7+
import static org.junit.Assert.assertTrue;
58

69
import java.util.Map;
710

@@ -109,6 +112,8 @@ public class JettyServerTest {
109112
server.stop();
110113

111114
unit.registerMock(Server.class, server);
115+
116+
expect(server.getThreadPool()).andReturn(unit.get(QueuedThreadPool.class)).anyTimes();
112117
};
113118

114119
private MockUnit.Block httpConf = unit -> {
@@ -194,7 +199,9 @@ public void startStopServer() throws Exception {
194199
JettyServer server = new JettyServer(unit.get(HttpHandler.class), config,
195200
unit.get(Provider.class));
196201

202+
assertNotNull(server.executor());
197203
server.start();
204+
assertTrue(server.executor().isPresent());
198205
server.join();
199206
server.stop();
200207
});

jooby-netty/src/test/java/org/jooby/internal/netty/NettyServerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.jooby.internal.netty;
22

3+
import static org.junit.Assert.assertNotNull;
4+
import static org.junit.Assert.assertTrue;
5+
36
import static org.easymock.EasyMock.expect;
47
import static org.easymock.EasyMock.isA;
58

@@ -117,7 +120,9 @@ public void defaultServer() throws Exception {
117120
.run(unit -> {
118121
NettyServer server = new NettyServer(unit.get(HttpHandler.class), config);
119122
try {
123+
assertNotNull(server.executor());
120124
server.start();
125+
assertTrue(server.executor().isPresent());
121126
server.join();
122127
} finally {
123128
server.stop();

jooby-undertow/src/test/java/org/jooby/internal/undertow/UndertowServerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.jooby.internal.undertow;
22

3+
import static org.junit.Assert.assertNotNull;
4+
import static org.junit.Assert.assertTrue;
5+
36
import javax.inject.Provider;
47

58
import org.jooby.spi.HttpHandler;
@@ -37,7 +40,9 @@ public void server() throws Exception {
3740
UndertowServer server = new UndertowServer(unit.get(HttpHandler.class), config,
3841
unit.get(Provider.class));
3942
try {
43+
assertNotNull(server.executor());
4044
server.start();
45+
assertTrue(server.executor().isPresent());
4146
server.join();// NOOP
4247
} finally {
4348
server.stop();

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,24 +2359,6 @@ public Jooby executor(final Executor executor) {
23592359
return this;
23602360
}
23612361

2362-
/**
2363-
* Set a named executor to use from {@link Deferred Deferred API}. Useful for override the
2364-
* default/global executor.
2365-
*
2366-
* Default executor runs each task in the thread that invokes {@link Executor#execute execute},
2367-
* that's a Jooby worker thread. A worker thread in Jooby can block.
2368-
*
2369-
* @param name Name of the executor.
2370-
* @param provider Provider for the executor.
2371-
* @return This jooby instance.
2372-
*/
2373-
public Jooby executor(final String name, final Class<? extends javax.inject.Provider<Executor>> provider) {
2374-
this.executors.add(binder -> {
2375-
binder.bind(Key.get(Executor.class, Names.named(name))).toProvider(provider).in(Singleton.class);
2376-
});
2377-
return this;
2378-
}
2379-
23802362
/**
23812363
* Set a named executor to use from {@link Deferred Deferred API}. Useful for override the
23822364
* default/global executor.
@@ -2434,6 +2416,24 @@ public Jooby executor(final String name) {
24342416
return this;
24352417
}
24362418

2419+
/**
2420+
* Set a named executor to use from {@link Deferred Deferred API}. Useful for override the
2421+
* default/global executor.
2422+
*
2423+
* Default executor runs each task in the thread that invokes {@link Executor#execute execute},
2424+
* that's a Jooby worker thread. A worker thread in Jooby can block.
2425+
*
2426+
* @param name Name of the executor.
2427+
* @param provider Provider for the executor.
2428+
* @return This jooby instance.
2429+
*/
2430+
private Jooby executor(final String name, final Class<? extends Provider<Executor>> provider) {
2431+
this.executors.add(binder -> {
2432+
binder.bind(Key.get(Executor.class, Names.named(name))).toProvider(provider).in(Singleton.class);
2433+
});
2434+
return this;
2435+
}
2436+
24372437
/**
24382438
* If the application fails to start all the services are shutdown. Also, the exception is logged
24392439
* and usually the application is going to exit.

jooby/src/main/java/org/jooby/internal/ServerExecutorProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
import com.google.common.util.concurrent.MoreExecutors;
2222
import com.google.inject.Inject;
23+
import com.google.inject.Provider;
2324
import org.jooby.spi.Server;
2425

25-
import javax.inject.Provider;
2626
import java.util.concurrent.Executor;
2727

2828
import static java.util.Objects.requireNonNull;
2929

30-
public class ServerExecutorProvider implements Provider<Executor> {
30+
public class ServerExecutorProvider implements Provider<Executor>
31+
{
3132

3233
private Executor executor;
3334

0 commit comments

Comments
 (0)