Search in sources :

Example 1 with JettyServerFactory

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());
}
Also used : EmbeddedJettyFactory(spark.embeddedserver.jetty.EmbeddedJettyFactory) Server(org.eclipse.jetty.server.Server) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) JettyServerFactory(spark.embeddedserver.jetty.JettyServerFactory) File(java.io.File) Test(org.junit.Test)

Example 2 with JettyServerFactory

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);
}
Also used : EmbeddedJettyFactory(spark.embeddedserver.jetty.EmbeddedJettyFactory) Server(org.eclipse.jetty.server.Server) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) JettyServerFactory(spark.embeddedserver.jetty.JettyServerFactory) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)2 NCSARequestLog (org.eclipse.jetty.server.NCSARequestLog)2 Server (org.eclipse.jetty.server.Server)2 Test (org.junit.Test)2 EmbeddedJettyFactory (spark.embeddedserver.jetty.EmbeddedJettyFactory)2 JettyServerFactory (spark.embeddedserver.jetty.JettyServerFactory)2 ThreadPool (org.eclipse.jetty.util.thread.ThreadPool)1