Search in sources :

Example 16 with MemoryARW

use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.

the class MemoryCARWImplTest method testBinSequence0.

static void testBinSequence0(long mem1Size, long mem2Size) {
    Rnd rnd = new Rnd();
    int n = 999;
    final TestBinarySequence binarySequence = new TestBinarySequence();
    final byte[] buffer = new byte[600];
    final long bufAddr = Unsafe.malloc(buffer.length, MemoryTag.NATIVE_DEFAULT);
    binarySequence.of(buffer);
    try (MemoryARW mem = new MemoryCARWImpl(mem1Size, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        Assert.assertEquals(Numbers.ceilPow2(mem1Size), mem.size());
        long offset1 = 8;
        for (int i = 0; i < n; i++) {
            long o;
            if (rnd.nextPositiveInt() % 16 == 0) {
                o = mem.putBin(null);
                Assert.assertEquals(offset1, o);
                offset1 += 8;
                continue;
            }
            int sz = buffer.length;
            for (int j = 0; j < sz; j++) {
                buffer[j] = rnd.nextByte();
                Unsafe.getUnsafe().putByte(bufAddr + j, buffer[j]);
            }
            o = mem.putBin(binarySequence);
            Assert.assertEquals(offset1 + sz, o);
            offset1 += 8 + sz;
            o = mem.putBin(bufAddr, sz);
            Assert.assertEquals(offset1 + sz, o);
            offset1 += 8 + sz;
        }
        try (MemoryARW mem2 = new MemoryCARWImpl(mem2Size, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
            Assert.assertEquals(Numbers.ceilPow2(mem2Size), mem2.size());
            offset1 = 0;
            for (int i = 0; i < n; i++) {
                BinarySequence sequence = mem.getBin(offset1);
                if (sequence == null) {
                    offset1 += 8;
                } else {
                    offset1 += 2 * (sequence.length() + 8);
                }
                mem2.putBin(sequence);
            }
            offset1 = 0;
            long offset2 = 0;
            // compare
            for (int i = 0; i < n; i++) {
                BinarySequence sequence1 = mem.getBin(offset1);
                BinarySequence sequence2 = mem2.getBin(offset2);
                if (sequence1 == null) {
                    assertNull(sequence2);
                    Assert.assertEquals(TableUtils.NULL_LEN, mem2.getBinLen(offset2));
                    offset1 += 8;
                    offset2 += 8;
                } else {
                    assertNotNull(sequence2);
                    assertEquals(mem.getBinLen(offset1), mem2.getBinLen(offset2));
                    assertEquals(sequence1.length(), sequence2.length());
                    for (long l = 0, len = sequence1.length(); l < len; l++) {
                        assertEquals(sequence1.byteAt(l), sequence2.byteAt(l));
                    }
                    offset1 += sequence1.length() + 8;
                    sequence1 = mem.getBin(offset1);
                    assertNotNull(sequence1);
                    assertEquals(sequence1.length(), sequence2.length());
                    for (long l = 0, len = sequence1.length(); l < len; l++) {
                        assertEquals(sequence1.byteAt(l), sequence2.byteAt(l));
                    }
                    offset1 += sequence1.length() + 8;
                    offset2 += sequence1.length() + 8;
                }
            }
        }
    }
    Unsafe.free(bufAddr, buffer.length, MemoryTag.NATIVE_DEFAULT);
}
Also used : TestBinarySequence(io.questdb.griffin.engine.TestBinarySequence) TestBinarySequence(io.questdb.griffin.engine.TestBinarySequence) MemoryARW(io.questdb.cairo.vm.api.MemoryARW)

Example 17 with MemoryARW

use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.

the class MemoryCARWImplTest method testFloat.

@Test
public void testFloat() {
    try (MemoryARW mem = new MemoryCARWImpl(11, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        Rnd rnd = new Rnd();
        int n = 999;
        mem.putByte((byte) 1);
        for (int i = 0; i < n; i++) {
            mem.putFloat(rnd.nextFloat());
        }
        rnd.reset();
        long o = 1;
        assertEquals(1, mem.getByte(0));
        for (int i = 0; i < n; i++) {
            assertEquals(rnd.nextFloat(), mem.getFloat(o), 0.00001f);
            o += 4;
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 18 with MemoryARW

use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.

the class MemoryCARWImplTest method testByte.

@Test
public void testByte() {
    try (MemoryARW mem = new MemoryCARWImpl(11, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        int n = 120;
        for (int i = 0; i < n; i++) {
            mem.putByte((byte) i);
        }
        long o = 0;
        for (int i = 0; i < n; i++) {
            assertEquals(i, mem.getByte(o++));
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 19 with MemoryARW

use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.

the class MemoryCARWImplTest method testJumpTo2.

@Test
public void testJumpTo2() {
    try (MemoryARW mem = new MemoryCARWImpl(11, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        mem.jumpTo(8);
        int n = 999;
        for (int i = n; i > 0; i--) {
            mem.putLong(i);
        }
        long o = 8;
        for (int i = n; i > 0; i--) {
            assertEquals(i, mem.getLong(o));
            o += 8;
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 20 with MemoryARW

use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.

the class MemoryCARWImplTest method testLong256FullStr.

@Test
public void testLong256FullStr() {
    String expected = "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060";
    long pageSize = 128;
    Long256Impl long256 = new Long256Impl();
    Long256Impl long256a = new Long256Impl();
    try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        mem.putLong256(expected);
        mem.putLong256(expected);
        mem.getLong256(0, long256);
        String actual = "0x" + Long.toHexString(long256.getLong3()) + Long.toHexString(long256.getLong2()) + Long.toHexString(long256.getLong1()) + Long.toHexString(long256.getLong0());
        Assert.assertEquals(expected, actual);
        mem.getLong256(Long256.BYTES, long256a);
        String actual2 = "0x" + Long.toHexString(long256a.getLong3()) + Long.toHexString(long256a.getLong2()) + Long.toHexString(long256a.getLong1()) + Long.toHexString(long256a.getLong0());
        Assert.assertEquals(expected, actual2);
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Aggregations

MemoryARW (io.questdb.cairo.vm.api.MemoryARW)52 Test (org.junit.Test)46 Path (io.questdb.std.str.Path)4 CairoException (io.questdb.cairo.CairoException)2 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)2 TestBinarySequence (io.questdb.griffin.engine.TestBinarySequence)2 TestRecord (io.questdb.cairo.TestRecord)1 RecordMetadata (io.questdb.cairo.sql.RecordMetadata)1 MemoryCMRImpl (io.questdb.cairo.vm.MemoryCMRImpl)1 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)1 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)1 FilesFacade (io.questdb.std.FilesFacade)1 StringSink (io.questdb.std.str.StringSink)1