use of io.questdb.std.Rnd 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.Rnd 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.Rnd 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.Rnd in project questdb by bluestreak01.
the class SymbolMapTest method testRollback.
@Test
public void testRollback() 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;
}
writer.rollback(N / 2);
prev = N / 2 - 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;
}
}
}
});
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class SymbolMapTest method testAppend.
@Test
public void testAppend() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 1000;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, true);
Rnd rnd = new Rnd();
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);
Assert.assertEquals(key, writer.put(cs));
prev = key;
}
}
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", N, -1, NOOP_COLLECTOR)) {
long prev = N - 1;
// append second batch and check that symbol keys start with N
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;
}
// try append first batch - this should return symbol keys starting with 0
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);
prev = key;
}
Assert.assertEquals(SymbolTable.VALUE_IS_NULL, writer.put(null));
}
}
});
}
Aggregations