use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.
the class HttpServerTest method testImportIntoBusyJournal.
@Test
public void testImportIntoBusyJournal() throws Exception {
try (JournalWriter ignored = getFactory().writer(new JournalStructure("test-import.csv").$int("x").$())) {
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();
StringBuilder response = new StringBuilder();
try {
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", null, response));
TestUtils.assertEquals("{\"status\":\"Journal exists and column count does not match\"}", response);
} catch (IOException e) {
Assert.assertTrue(e.getMessage().contains("Connection reset"));
} finally {
server.halt();
}
}
}
use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.
the class HttpServerTest method testImportNumberPrefixedColumn.
@Test
public void testImportNumberPrefixedColumn() throws Exception {
final ServerConfiguration configuration = new ServerConfiguration();
BootstrapEnv env = new BootstrapEnv();
env.configuration = configuration;
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-num-prefix.csv", "http://localhost:9000/imp?fmt=json", null, null));
StringSink sink = new StringSink();
RecordSourcePrinter printer = new RecordSourcePrinter(sink);
QueryCompiler qc = new QueryCompiler(env);
try (RecordSource rs = qc.compile(env.factory, "select count(StrSym), count(IntSym), count(_1IntCol), count(long), count() from 'test-import-num-prefix.csv'")) {
printer.print(rs, env.factory);
}
TestUtils.assertEquals("126\t126\t128\t129\t129\n", sink);
} finally {
server.halt();
}
}
use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.
the class HttpServerTest method testImportIntoBusyJournal2.
@Test
public void testImportIntoBusyJournal2() throws Exception {
WriterFactory f = getFactory();
try (JournalWriter w = f.writer(new JournalStructure("small.csv").$int("X").$int("Y").$())) {
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, 3);
ew.putInt(1, 30);
ew.append();
w.commit();
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();
StringBuilder response = new StringBuilder();
try {
Assert.assertEquals(200, HttpTestUtils.upload("/csv/small.csv", "http://localhost:9000/imp?fmt=json", null, response));
Assert.assertTrue(Chars.startsWith(response, "{\"status\":\"com.questdb.ex.WriterBusyException\"}"));
} catch (IOException e) {
Assert.assertTrue(e.getMessage().contains("Connection reset"));
} finally {
server.halt();
}
}
}
Aggregations