Search in sources :

Example 26 with Path

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());
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 27 with Path

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());
}
Also used : Path(com.questdb.std.str.Path) Test(org.junit.Test)

Example 28 with Path

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));
                }
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path)

Example 29 with Path

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);
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) ObjList(com.questdb.std.ObjList) Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 30 with Path

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"));
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Aggregations

Path (com.questdb.std.str.Path)74 Test (org.junit.Test)46 File (java.io.File)8 Rnd (com.questdb.std.Rnd)7 LPSZ (com.questdb.std.str.LPSZ)6 NativeLPSZ (com.questdb.std.str.NativeLPSZ)5 NumericException (com.questdb.common.NumericException)3 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)3 DirectCharSequence (com.questdb.std.str.DirectCharSequence)3 StringSink (com.questdb.std.str.StringSink)3 RowCursor (com.questdb.common.RowCursor)2 CreateTableModel (com.questdb.griffin.lexer.model.CreateTableModel)2 ObjList (com.questdb.std.ObjList)2 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)2 TestMicroClock (com.questdb.test.tools.TestMicroClock)2 ByteBuffer (java.nio.ByteBuffer)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 Chars (com.questdb.std.Chars)1 FilesFacade (com.questdb.std.FilesFacade)1