use of com.questdb.store.Journal in project questdb by bluestreak01.
the class HttpServerTest method testConcurrentImport.
@Test
public void testConcurrentImport() throws Exception {
final 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();
final CyclicBarrier barrier = new CyclicBarrier(2);
final CountDownLatch latch = new CountDownLatch(2);
try {
new Thread(() -> {
try {
barrier.await();
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null));
latch.countDown();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}).start();
new Thread(() -> {
try {
barrier.await();
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-nan.csv", "http://localhost:9000/imp", null, null));
latch.countDown();
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}).start();
latch.await();
try (Journal r = getFactory().reader("test-import.csv")) {
Assert.assertEquals("First failed", 129, r.size());
}
try (Journal r = getFactory().reader("test-import-nan.csv")) {
Assert.assertEquals("Second failed", 129, r.size());
}
} finally {
server.halt();
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class PlainTextLexerTest method testImport.
@Test
public void testImport() throws Exception {
String file = this.getClass().getResource("/csv/test-import.csv").getFile();
ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, null, false);
String location = "test-import.csv";
Assert.assertEquals(JournalConfiguration.EXISTS, getFactory().getConfiguration().exists(location));
try (Journal r = getFactory().reader(location)) {
JournalMetadata m = r.getMetadata();
Assert.assertEquals(10, m.getColumnCount());
Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(0).type);
Assert.assertEquals(ColumnType.INT, m.getColumnQuick(1).type);
Assert.assertEquals(ColumnType.INT, m.getColumnQuick(2).type);
Assert.assertEquals(ColumnType.DOUBLE, m.getColumnQuick(3).type);
Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(4).type);
Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(5).type);
Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(6).type);
Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(7).type);
Assert.assertEquals(ColumnType.BOOLEAN, m.getColumnQuick(8).type);
Assert.assertEquals(ColumnType.LONG, m.getColumnQuick(9).type);
}
File actual = new File(getFactory().getConfiguration().getJournalBase(), "exp.csv");
File expected = new File(this.getClass().getResource("/csv/test-export-expected.csv").getFile());
try (RecordSource rs = compile("'" + location + "'")) {
ExportManager.export(rs, getFactory(), actual, PlainTextDelimiter.CSV);
TestUtils.assertEquals(expected, actual);
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class PlainTextLexerTest method testImportMalformedQuote.
@Test
public void testImportMalformedQuote() throws Exception {
String file = this.getClass().getResource("/csv/test-import-malformed.csv").getFile();
ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, null, false);
String location = "test-import-malformed.csv";
Assert.assertEquals(JournalConfiguration.EXISTS, factoryContainer.getConfiguration().exists(location));
try (Journal r = getFactory().reader(location)) {
JournalMetadata m = r.getMetadata();
Assert.assertEquals(10, m.getColumnCount());
Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(0).type);
Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(1).type);
Assert.assertEquals(ColumnType.INT, m.getColumnQuick(2).type);
Assert.assertEquals(ColumnType.DOUBLE, m.getColumnQuick(3).type);
Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(4).type);
Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(5).type);
Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(6).type);
Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(7).type);
Assert.assertEquals(ColumnType.BOOLEAN, m.getColumnQuick(8).type);
Assert.assertEquals(ColumnType.LONG, m.getColumnQuick(9).type);
}
File actual = new File(factoryContainer.getConfiguration().getJournalBase(), "exp.csv");
File expected = new File(this.getClass().getResource("/csv/test-import-malformed-expected.csv").getFile());
try (RecordSource rs = compile("'" + location + "'")) {
ExportManager.export(rs, getFactory(), actual, PlainTextDelimiter.CSV);
TestUtils.assertEquals(expected, actual);
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class JournalServerAgent method close.
public void close() {
server.getBridge().removeAgentSequence(eventProcessor.getSequence());
journalClientStateConsumer.free();
commandConsumer.free();
setKeyRequestConsumer.free();
intResponseConsumer.free();
byteArrayResponseConsumer.free();
commandProducer.free();
stringResponseProducer.free();
intResponseProducer.free();
for (int i = 0, n = readers.size(); i < n; i++) {
Journal r = readers.getQuick(i);
if (r != null) {
r.close();
}
}
for (int i = 0, k = producers.size(); i < k; i++) {
producers.getQuick(i).free();
}
}
use of com.questdb.store.Journal in project questdb by bluestreak01.
the class DDLTests method testCreateDefaultPartitionBy.
@Test
public void testCreateDefaultPartitionBy() throws Exception {
exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100");
// validate journal
try (Journal r = getFactory().reader("x")) {
Assert.assertNotNull(r);
JournalMetadata m = r.getMetadata();
Assert.assertEquals(5, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(1, m.getColumn("a").getBucketCount());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertTrue(m.getColumn("z").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(63, m.getColumn("z").getBucketCount());
Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType());
Assert.assertTrue(m.getColumn("l").isIndexed());
// bucket is ceilPow2(value) - 1
Assert.assertEquals(511, m.getColumn("l").getBucketCount());
Assert.assertEquals(-1, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
}
}
Aggregations