use of spark.embeddedserver.jetty.JettyServerFactory in project spark by perwendel.
the class EmbeddedServersTest method testAdd_whenConfigureRoutes_createsCustomServer.
@Test
public void testAdd_whenConfigureRoutes_createsCustomServer() throws Exception {
File requestLogDir = temporaryFolder.newFolder();
File requestLogFile = new File(requestLogDir, "request.log");
// Register custom server
EmbeddedServers.add(EmbeddedServers.Identifiers.JETTY, new EmbeddedJettyFactory(new JettyServerFactory() {
@Override
public Server create(int maxThreads, int minThreads, int threadTimeoutMillis) {
Server server = new Server();
server.setRequestLog(new NCSARequestLog(requestLogFile.getAbsolutePath()));
return server;
}
@Override
public Server create(ThreadPool threadPool) {
return null;
}
}));
Spark.get("/", (request, response) -> "OK");
Spark.awaitInitialization();
assertTrue(requestLogFile.exists());
}
use of spark.embeddedserver.jetty.JettyServerFactory in project spark by perwendel.
the class EmbeddedServersTest method testAddAndCreate_whenCreate_createsCustomServer.
@Test
public void testAddAndCreate_whenCreate_createsCustomServer() throws Exception {
// Create custom Server
Server server = new Server();
File requestLogDir = temporaryFolder.newFolder();
File requestLogFile = new File(requestLogDir, "request.log");
server.setRequestLog(new NCSARequestLog(requestLogFile.getAbsolutePath()));
JettyServerFactory serverFactory = mock(JettyServerFactory.class);
when(serverFactory.create(0, 0, 0)).thenReturn(server);
String id = "custom";
// Register custom server
EmbeddedServers.add(id, new EmbeddedJettyFactory(serverFactory));
EmbeddedServer embeddedServer = EmbeddedServers.create(id, null, null, false);
assertNotNull(embeddedServer);
embeddedServer.ignite("localhost", 0, null, 0, 0, 0);
assertTrue(requestLogFile.exists());
embeddedServer.extinguish();
verify(serverFactory).create(0, 0, 0);
}
Aggregations