Search in sources :

Example 6 with StaticContentHandler

use of com.questdb.net.http.handlers.StaticContentHandler in project questdb by bluestreak01.

the class HttpServerTest method testConnectionCount.

@Test
public void testConnectionCount() throws Exception {
    final BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    env.configuration.setHttpMaxConnections(10);
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        CloseableHttpClient c1 = clientBuilder(true).build();
        CloseableHttpClient c2 = clientBuilder(true).build();
        CloseableHttpClient c3 = clientBuilder(true).build();
        CloseableHttpClient c4 = clientBuilder(true).build();
        Assert.assertNotNull(c1.execute(new HttpGet("https://localhost:9000/upload.html")));
        Assert.assertEquals(1, server.getConnectionCount());
        Assert.assertNotNull(c2.execute(new HttpGet("https://localhost:9000/upload.html")));
        Assert.assertEquals(2, server.getConnectionCount());
        Assert.assertNotNull(c3.execute(new HttpGet("https://localhost:9000/upload.html")));
        Assert.assertEquals(3, server.getConnectionCount());
        Assert.assertNotNull(c4.execute(new HttpGet("https://localhost:9000/upload.html")));
        Assert.assertEquals(4, server.getConnectionCount());
        c1.close();
        c2.close();
        Thread.sleep(300);
        Assert.assertEquals(2, server.getConnectionCount());
        c3.close();
        c4.close();
        Thread.sleep(300);
        Assert.assertEquals(0, server.getConnectionCount());
    } finally {
        server.halt();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) HttpGet(org.apache.http.client.methods.HttpGet) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 7 with StaticContentHandler

use of com.questdb.net.http.handlers.StaticContentHandler in project questdb by bluestreak01.

the class HttpServerTest method testSslConcurrentDownload.

@Test
public void testSslConcurrentDownload() throws Exception {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    env.configuration.getSslConfig().setSecure(true);
    env.configuration.getSslConfig().setKeyStore(new FileInputStream(resourceFile("/keystore/singlekey.ks")), "changeit");
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    final MimeTypes mimeTypes = new MimeTypes(env.configuration.getMimeTypes());
    HttpServer server = new HttpServer(env);
    server.start();
    assertConcurrentDownload(mimeTypes, server, "https");
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 8 with StaticContentHandler

use of com.questdb.net.http.handlers.StaticContentHandler in project questdb by bluestreak01.

the class HttpServerTest method testDefaultDirIndex.

@Test
public void testDefaultDirIndex() throws Exception {
    final BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    env.configuration.getSslConfig().setSecure(false);
    env.typeProbeCollection = TYPE_PROBE_COLLECTION;
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        HttpTestUtils.download(clientBuilder(false), "http://localhost:9000/", new File(temp.getRoot(), "index.html"));
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 9 with StaticContentHandler

use of com.questdb.net.http.handlers.StaticContentHandler in project questdb by bluestreak01.

the class HttpServerTest method testNativeConcurrentDownload.

@Test
public void testNativeConcurrentDownload() throws Exception {
    final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = configuration;
    env.configuration.getSslConfig().setSecure(false);
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    final MimeTypes mimeTypes = new MimeTypes(env.configuration.getMimeTypes());
    HttpServer server = new HttpServer(env);
    server.start();
    assertConcurrentDownload(mimeTypes, server, "http");
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Aggregations

BootstrapEnv (com.questdb.BootstrapEnv)9 ServerConfiguration (com.questdb.ServerConfiguration)9 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)9 StaticContentHandler (com.questdb.net.http.handlers.StaticContentHandler)9 Test (org.junit.Test)9 SocketException (java.net.SocketException)2 HttpGet (org.apache.http.client.methods.HttpGet)2 ResponseContentBufferTooSmallException (com.questdb.ex.ResponseContentBufferTooSmallException)1 UploadHandler (com.questdb.net.http.handlers.UploadHandler)1 Socket (java.net.Socket)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Ignore (org.junit.Ignore)1