use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testWriteOverMapFailuresAndRead.
@Test
public void testWriteOverMapFailuresAndRead() throws Exception {
long used = Unsafe.getMemUsed();
Rnd rnd = new Rnd();
class X extends FilesFacadeImpl {
@Override
public long mmap(long fd, long len, long offset, int mode) {
if (rnd.nextBoolean()) {
return -1;
}
return super.mmap(fd, len, offset, mode);
}
}
int writeFailureCount = 0;
final X ff = new X();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (ReadWriteMemory mem = new ReadWriteMemory(ff, path, 2 * ff.getPageSize())) {
int i = 0;
while (i < N) {
try {
mem.putLong(i);
i++;
} catch (CairoException ignore) {
writeFailureCount++;
}
}
// read in place
for (i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
}
Assert.assertTrue(writeFailureCount > 0);
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testWriteAndReadWithReadOnlyMem.
@Test
public void testWriteAndReadWithReadOnlyMem() throws Exception {
long used = Unsafe.getMemUsed();
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (ReadWriteMemory mem = new ReadWriteMemory(FF, path, 2 * FF.getPageSize())) {
for (int i = 0; i < N; i++) {
mem.putLong(i);
}
Assert.assertEquals(8L * N, mem.getAppendOffset());
}
try (ReadOnlyMemory mem = new ReadOnlyMemory(FF, path, FF.getPageSize(), 8L * N)) {
for (int i = 0; i < N; i++) {
Assert.assertEquals(i, mem.getLong(i * 8));
}
}
}
Assert.assertEquals(used, Unsafe.getMemUsed());
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoMemoryTest method testVirtualMemoryJump.
private void testVirtualMemoryJump(VirtualMemoryFactory factory) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(temp.newFile().getAbsolutePath()).$()) {
try (VirtualMemory mem = factory.newInstance(path)) {
for (int i = 0; i < 100; i++) {
mem.putLong(i);
}
mem.jumpTo(0);
for (int i = 0; i < 50; i++) {
mem.putLong(50 - i);
}
// keep previously written data
mem.jumpTo(800);
}
try (ReadOnlyMemory roMem = new ReadOnlyMemory(FF, path, FF.getPageSize(), 800)) {
for (int i = 0; i < 50; i++) {
Assert.assertEquals(50 - i, roMem.getLong(i * 8));
}
for (int i = 50; i < 100; i++) {
Assert.assertEquals(i, roMem.getLong(i * 8));
}
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testLookupPerformance.
// @Test
// public void testLookupPerformanceOld() throws JournalException {
// int N = 100000000;
// int symbolCount = 1024;
// ObjList<String> symbols = new ObjList<>();
// MMappedSymbolTable tab = new MMappedSymbolTable(symbolCount, 256, 1, new File(configuration.getRoot().toString()), "x", JournalMode.APPEND, 0, 0, false, true);
// Rnd rnd = new Rnd();
// long prev = -1L;
// for (int i = 0; i < symbolCount; i++) {
// CharSequence cs = rnd.nextChars(10);
// long key = tab.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, tab.put(symbols.getQuick(key)));
// }
// System.out.println(System.nanoTime() - t);
// }
@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)) {
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 com.questdb.std.str.Path in project questdb by bluestreak01.
the class SymbolMapTest method testSimpleRead.
@Test
public void testSimpleRead() 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)) {
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.value(i));
Assert.assertEquals(i, reader.getQuick(cs));
}
Assert.assertEquals(N, reader.size());
Assert.assertNull(reader.value(-1));
Assert.assertNull(reader.value(N));
Assert.assertEquals(SymbolTable.VALUE_NOT_FOUND, reader.getQuick("hola"));
}
}
});
}
Aggregations