Search in sources :

Example 1 with StaticContentHandler

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

the class HttpServerTest method testMaxConnections.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Assert.assertNotNull(clientBuilder(true).build().execute(new HttpGet("https://localhost:9000/upload.html")));
        try {
            clientBuilder(true).build().execute(new HttpGet("https://localhost:9000/upload.html"));
            Assert.fail("Expected server to reject connection");
        } catch (Exception ignored) {
        }
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) HttpGet(org.apache.http.client.methods.HttpGet) ResponseContentBufferTooSmallException(com.questdb.ex.ResponseContentBufferTooSmallException) SocketException(java.net.SocketException) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 2 with StaticContentHandler

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

the class HttpServerTest method testNativeNotModified.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    assertNotModified(env.configuration, server);
}
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 3 with StaticContentHandler

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

the class HttpServerTest method testIdleTimeout.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Socket socket = new Socket("127.0.0.1", 9000);
        OutputStream os = socket.getOutputStream();
        Thread.sleep(600);
        try {
            os.write(request.getBytes());
            for (int i = 0; i < 4096; i++) {
                os.write('c');
            }
            os.flush();
            Assert.fail("Expected exception due to connection timeout");
        } catch (SocketException ignored) {
        }
    } finally {
        server.halt();
    }
}
Also used : SocketException(java.net.SocketException) BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) Socket(java.net.Socket) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 4 with StaticContentHandler

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

the class HttpServerTest method testCompressedDownload.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        HttpTestUtils.download(clientBuilder(true), "https://localhost:9000/upload.html", new File(temp.getRoot(), "upload.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 5 with StaticContentHandler

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

the class HttpServerTest method testRangesNative.

@Test
// fix is in server, which would allow limited number of this iterations after which connection is closed.
@Ignore
public void testRangesNative() throws Exception {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration(new File(HttpServerTest.class.getResource("/site").getPath(), "conf/questdb.conf")) {

        @Override
        public File getHttpPublic() {
            return temp.getRoot();
        }
    };
    env.configuration.setHttpThreads(1);
    env.configuration.setHttpSoRetries(10);
    env.configuration.getSslConfig().setSecure(false);
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/upload", new UploadHandler(env.configuration.getHttpPublic()));
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    assertRanges(new HttpServer(env));
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) UploadHandler(com.questdb.net.http.handlers.UploadHandler) Ignore(org.junit.Ignore) 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