-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to pass ThreadPool to Jetty embedded server via factory (…
…#853) * Added ability to pass thread pool through to jetty sever via embedded server factory useful for overriding default thread pool like io.dropwizard.metrics.InstrumentedQueuedThreadPool. * Forgot to remove temp @ignore for jetty tests during other test development.
- Loading branch information
1 parent
bd014ba
commit 2eecb4d
Showing
8 changed files
with
139 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
72 changes: 72 additions & 0 deletions
72
src/test/java/spark/embeddedserver/jetty/EmbeddedJettyFactoryTest.java
This file contains 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,72 @@ | ||
package spark.embeddedserver.jetty; | ||
|
||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import spark.embeddedserver.EmbeddedServer; | ||
import spark.route.Routes; | ||
import spark.staticfiles.StaticFilesConfiguration; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
public class EmbeddedJettyFactoryTest { | ||
private EmbeddedServer embeddedServer; | ||
|
||
@Test | ||
public void create() throws Exception { | ||
final JettyServerFactory jettyServerFactory = mock(JettyServerFactory.class); | ||
final StaticFilesConfiguration staticFilesConfiguration = mock(StaticFilesConfiguration.class); | ||
final Routes routes = mock(Routes.class); | ||
|
||
when(jettyServerFactory.create(100,10,10000)).thenReturn(new Server()); | ||
|
||
final EmbeddedJettyFactory embeddedJettyFactory = new EmbeddedJettyFactory(jettyServerFactory); | ||
embeddedServer = embeddedJettyFactory.create(routes, staticFilesConfiguration, false); | ||
|
||
embeddedServer.ignite("localhost", 8080, null, 100,10,10000); | ||
|
||
verify(jettyServerFactory, times(1)).create(100,10,10000); | ||
verifyNoMoreInteractions(jettyServerFactory); | ||
} | ||
|
||
@Test | ||
public void create_withThreadPool() throws Exception { | ||
final QueuedThreadPool threadPool = new QueuedThreadPool(100); | ||
final JettyServerFactory jettyServerFactory = mock(JettyServerFactory.class); | ||
final StaticFilesConfiguration staticFilesConfiguration = mock(StaticFilesConfiguration.class); | ||
final Routes routes = mock(Routes.class); | ||
|
||
when(jettyServerFactory.create(threadPool)).thenReturn(new Server(threadPool)); | ||
|
||
final EmbeddedJettyFactory embeddedJettyFactory = new EmbeddedJettyFactory(jettyServerFactory).withThreadPool(threadPool); | ||
embeddedServer = embeddedJettyFactory.create(routes, staticFilesConfiguration, false); | ||
|
||
embeddedServer.ignite("localhost", 8080, null, 0,0,0); | ||
|
||
verify(jettyServerFactory, times(1)).create(threadPool); | ||
verifyNoMoreInteractions(jettyServerFactory); | ||
} | ||
|
||
@Test | ||
public void create_withNullThreadPool() throws Exception { | ||
final JettyServerFactory jettyServerFactory = mock(JettyServerFactory.class); | ||
final StaticFilesConfiguration staticFilesConfiguration = mock(StaticFilesConfiguration.class); | ||
final Routes routes = mock(Routes.class); | ||
|
||
when(jettyServerFactory.create(100,10,10000)).thenReturn(new Server()); | ||
|
||
final EmbeddedJettyFactory embeddedJettyFactory = new EmbeddedJettyFactory(jettyServerFactory).withThreadPool(null); | ||
embeddedServer = embeddedJettyFactory.create(routes, staticFilesConfiguration, false); | ||
|
||
embeddedServer.ignite("localhost", 8080, null, 100,10,10000); | ||
|
||
verify(jettyServerFactory, times(1)).create(100,10,10000); | ||
verifyNoMoreInteractions(jettyServerFactory); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
if(embeddedServer != null) embeddedServer.extinguish(); | ||
} | ||
} |
This file contains 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