use of com.questdb.BootstrapEnv 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();
}
}
use of com.questdb.BootstrapEnv in project questdb by bluestreak01.
the class HttpServerTest method testUpload.
@Test
public void testUpload() throws Exception {
final File dir = temp.newFolder();
BootstrapEnv env = new BootstrapEnv();
env.configuration = new ServerConfiguration();
env.matcher = new SimpleUrlMatcher() {
{
put("/upload", new UploadHandler(dir));
}
};
HttpServer server = new HttpServer(env);
server.start();
File expected = resourceFile("/csv/test-import.csv");
File actual = new File(dir, "test-import.csv");
upload(expected);
TestUtils.assertEquals(expected, actual);
server.halt();
}
use of com.questdb.BootstrapEnv 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);
}
use of com.questdb.BootstrapEnv in project questdb by bluestreak01.
the class HttpServerTest method testImportNumericHeader.
@Test
public void testImportNumericHeader() throws Exception {
BootstrapEnv env = new BootstrapEnv();
env.configuration = new ServerConfiguration();
env.factory = getFactory();
env.typeProbeCollection = TYPE_PROBE_COLLECTION;
env.matcher = new SimpleUrlMatcher() {
{
put("/imp", new ImportHandler(env));
}
};
HttpServer server = new HttpServer(env);
server.start();
try {
StringSink sink = new StringSink();
RecordSourcePrinter printer = new RecordSourcePrinter(sink);
QueryCompiler qc = new QueryCompiler(env);
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-numeric-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true&forceHeader=true", null, null));
printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory());
// expect first line to be treated as header
TestUtils.assertEquals("2\n", sink);
} finally {
server.halt();
}
}
use of com.questdb.BootstrapEnv in project questdb by bluestreak01.
the class HttpServerTest method downloadChunked.
private File downloadChunked(ServerConfiguration conf, final int count, final int sz, boolean ssl, final boolean compressed) throws Exception {
BootstrapEnv env = new BootstrapEnv();
env.configuration = conf;
env.matcher = new SimpleUrlMatcher() {
{
put("/test", new ContextHandler() {
private int counter = -1;
@Override
public void handle(IOContext context) throws IOException {
ChunkedResponse r = context.chunkedResponse();
r.setCompressed(compressed);
r.status(200, "text/plain; charset=utf-8");
r.sendHeader();
counter = -1;
resume(context);
}
@Override
public void resume(IOContext context) throws IOException {
ChunkedResponse r = context.chunkedResponse();
for (int i = counter + 1; i < count; i++) {
counter = i;
try {
for (int k = 0; k < sz; k++) {
Numbers.append(r, i);
}
r.put(Misc.EOL);
} catch (ResponseContentBufferTooSmallException ignore) {
// ignore, send as much as we can in one chunk
LOG.error().$("Response content buffer is too small").$();
}
r.sendChunk();
}
r.done();
}
@Override
public void setupThread() {
}
});
}
};
HttpServer server = new HttpServer(env);
File out = temp.newFile();
server.start();
try {
HttpTestUtils.download(clientBuilder(ssl), (ssl ? "https" : "http") + "://localhost:9000/test", out);
} finally {
server.halt();
}
return out;
}
Aggregations