use of com.questdb.ServerConfiguration in project questdb by bluestreak01.
the class HttpServerTest method testImportAppend.
@Test
public void testImportAppend() throws Exception {
final AtomicInteger errors = new AtomicInteger();
getFactory().setEventListener((factoryType, thread, name, event, segment, position) -> {
if (event == FactoryEventListener.EV_UNEXPECTED_CLOSE) {
errors.incrementAndGet();
}
return true;
});
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 {
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", null, null));
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null));
StringSink sink = new StringSink();
RecordSourcePrinter printer = new RecordSourcePrinter(sink);
QueryCompiler qc = new QueryCompiler(env);
printer.print(qc.compile(getFactory(), "select count(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'"), getFactory());
TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink);
} finally {
server.halt();
}
Assert.assertEquals(0, errors.get());
}
use of com.questdb.ServerConfiguration 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();
}
}
use of com.questdb.ServerConfiguration in project questdb by bluestreak01.
the class HttpServerTest method testStartStop.
@Test
public void testStartStop() {
BootstrapEnv env = new BootstrapEnv();
env.configuration = new ServerConfiguration();
env.matcher = new SimpleUrlMatcher();
HttpServer server = new HttpServer(env);
server.start();
server.halt();
}
use of com.questdb.ServerConfiguration in project questdb by bluestreak01.
the class HttpServerTest method testImportWrongTypeStrictAtomicity.
@Test
public void testImportWrongTypeStrictAtomicity() 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));
}
};
env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
env.dateFormatFactory = DATE_FORMAT_FACTORY;
HttpServer server = new HttpServer(env);
server.start();
try {
Assert.assertEquals(400, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?atomicity=strict", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DATE\"}]", null));
StringSink sink = new StringSink();
RecordSourcePrinter printer = new RecordSourcePrinter(sink);
QueryCompiler qc = new QueryCompiler(env);
RecordSource src1 = qc.compile(env.factory, "select count() from 'test-import.csv'");
try {
printer.print(src1, env.factory);
TestUtils.assertEquals("0\n", sink);
} finally {
Misc.free(src1);
}
} finally {
server.halt();
}
}
use of com.questdb.ServerConfiguration 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();
}
}
Aggregations