Search in sources :

Example 21 with Path

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

Example 22 with Path

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

Example 23 with Path

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

Example 24 with Path

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

Example 25 with Path

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

Aggregations

Path (io.questdb.std.str.Path)141 Test (org.junit.Test)89 File (java.io.File)14 FilesFacade (io.questdb.std.FilesFacade)13 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)10 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)10 Rnd (io.questdb.std.Rnd)10 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)7 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)7 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)6 NativeLPSZ (io.questdb.std.str.NativeLPSZ)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)5 LPSZ (io.questdb.std.str.LPSZ)5 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RowCursor (io.questdb.cairo.sql.RowCursor)4 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)4 RingQueue (io.questdb.mp.RingQueue)4