use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testReadEmptySymbolMap.
@Test
public void testReadEmptySymbolMap() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 10000;
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", N, true);
try (SymbolMapReaderImpl reader = new SymbolMapReaderImpl(configuration, path, "x", 0)) {
Assert.assertEquals(N, reader.getSymbolCapacity());
Assert.assertNull(reader.valueOf(-1));
Assert.assertEquals(SymbolTable.VALUE_IS_NULL, reader.keyOf(null));
}
}
});
}
use of io.questdb.std.str.Path 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.str.Path 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));
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TxnScoreboardTest method testCrawl.
@Test
public void testCrawl() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (final Path shmPath = new Path()) {
try (final TxnScoreboard scoreboard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 1024)) {
for (int i = 0; i < 1500; i++) {
scoreboard.acquireTxn(i);
scoreboard.releaseTxn(i);
}
Assert.assertEquals(1499, scoreboard.getMin());
// increase scoreboard size
try (final TxnScoreboard scoreboard2 = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 2048)) {
Assert.assertEquals(1499, scoreboard2.getMin());
for (int i = 1500; i < 3000; i++) {
scoreboard2.acquireTxn(i);
scoreboard2.releaseTxn(i);
}
Assert.assertEquals(2999, scoreboard2.getMin());
Assert.assertEquals(2999, scoreboard.getMin());
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TxnScoreboardTest method testDoesNotCleanOnNonExclusiveOpen.
@Test
public void testDoesNotCleanOnNonExclusiveOpen() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (final Path shmPath = new Path()) {
try (final TxnScoreboard rootBoard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 2048)) {
try (final TxnScoreboard scoreboard = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 1024)) {
for (int i = 0; i < 1500; i++) {
scoreboard.acquireTxn(i);
scoreboard.releaseTxn(i);
}
Assert.assertEquals(1499, scoreboard.getMin());
}
try (final TxnScoreboard scoreboard2 = new TxnScoreboard(FilesFacadeImpl.INSTANCE, shmPath.of(root), 2048)) {
Assert.assertEquals(1499, scoreboard2.getMin());
for (int i = 1500; i < 3000; i++) {
scoreboard2.acquireTxn(i);
scoreboard2.releaseTxn(i);
}
Assert.assertEquals(2999, scoreboard2.getMin());
}
Assert.assertEquals(2999, rootBoard.getMin());
}
}
});
}
Aggregations