use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testSimpleAdd.
@Test
public void testSimpleAdd() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1000000;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, false);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
Rnd rnd = new Rnd();
long prev = -1L;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testTransactionalRead.
@Test
public void testTransactionalRead() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1000000;
Rnd rnd = new Rnd();
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, false);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
long prev = -1L;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
prev = key;
}
rnd.reset();
try (SymbolMapReaderImpl reader = new SymbolMapReaderImpl(configuration, path, "x", N)) {
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
TestUtils.assertEquals(cs, reader.valueOf(i));
Assert.assertEquals(i, reader.keyOf(cs));
}
Assert.assertNull(reader.valueOf(N));
Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.keyOf("hola"));
Assert.assertEquals(N, writer.put("XYZ"));
// must not be able to read new symbol
Assert.assertNull(reader.valueOf(N));
Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.keyOf("XYZ"));
reader.updateSymbolCount(N + 1);
TestUtils.assertEquals("XYZ", reader.valueOf(N));
Assert.assertEquals(N, reader.keyOf("XYZ"));
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testTruncate.
@Test
public void testTruncate() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1024;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, true);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
Rnd rnd = new Rnd();
long prev = -1L;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
Assert.assertEquals(N, writer.getSymbolCount());
writer.truncate();
Assert.assertEquals(0, writer.getSymbolCount());
// reset RND to exercise symbol cache
rnd.reset();
prev = -1;
for (int i = 0; i < N; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
Assert.assertEquals(prev + 1, key);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
Assert.assertEquals(N, writer.getSymbolCount());
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testLookupPerformance.
@Test
public void testLookupPerformance() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 10000000;
int symbolCount = 1024;
ObjList<String> symbols = new ObjList<>();
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", symbolCount, true);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
Rnd rnd = new Rnd();
long prev = -1L;
for (int i = 0; i < symbolCount; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
symbols.add(cs.toString());
Assert.assertEquals(prev + 1, key);
prev = key;
}
long t = System.nanoTime();
for (int i = 0; i < N; i++) {
int key = rnd.nextPositiveInt() % symbolCount;
Assert.assertEquals(key, writer.put(symbols.getQuick(key)));
}
System.out.println("SymbolMapWriter lookup performance [10M <500ms]: " + (System.nanoTime() - t) / 1000000);
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testRollbackAndRetry.
@Test
public void testRollbackAndRetry() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1024;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, true);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0, -1, NOOP_COLLECTOR)) {
Assert.assertEquals(0, writer.put("A1"));
Assert.assertEquals(1, writer.put("A2"));
Assert.assertEquals(2, writer.put("A3"));
Assert.assertEquals(3, writer.put("A4"));
Assert.assertEquals(4, writer.put("A5"));
Assert.assertEquals(5, writer.put("A6"));
Assert.assertEquals(6, writer.put("A7"));
Assert.assertEquals(7, writer.put("A8"));
Assert.assertEquals(8, writer.put("A9"));
Assert.assertEquals(9, writer.put("A10"));
writer.rollback(5);
Assert.assertEquals(5, writer.put("A6"));
Assert.assertEquals(6, writer.put("A7"));
Assert.assertEquals(7, writer.put("A8"));
Assert.assertEquals(8, writer.put("A9"));
Assert.assertEquals(9, writer.put("A10"));
}
}
});
}
Aggregations