Search in sources :

Example 11 with MemoryARW

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

the class MemoryCARWImplTest method testBulkCopy.

@Test
public void testBulkCopy() {
    int N = 1000;
    try (MemoryARW mem = new MemoryCARWImpl(128, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        for (int i = 0; i < N; i++) {
            mem.putShort((short) i);
        }
        long target = N * 2;
        long offset = 0;
        short i = 0;
        while (target > 0) {
            long len = mem.size() - offset;
            target -= len;
            long address = mem.addressOf(offset);
            offset += len;
            while (len > 0 & i < N) {
                assertEquals(i++, Unsafe.getUnsafe().getShort(address));
                address += 2;
                len -= 2;
            }
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 12 with MemoryARW

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

the class MemoryCARWImplTest method testLong256Obj.

@Test
public void testLong256Obj() {
    long pageSize = 64;
    Rnd rnd = new Rnd();
    Long256Impl long256 = new Long256Impl();
    try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        for (int i = 0; i < 1000; i++) {
            long256.fromRnd(rnd);
            mem.putLong256(long256);
        }
        rnd.reset();
        long offset = 0;
        for (int i = 0; i < 1000; i++) {
            mem.getLong256(offset, long256);
            offset += Long256.BYTES;
            Assert.assertEquals(rnd.nextLong(), long256.getLong0());
            Assert.assertEquals(rnd.nextLong(), long256.getLong1());
            Assert.assertEquals(rnd.nextLong(), long256.getLong2());
            Assert.assertEquals(rnd.nextLong(), long256.getLong3());
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 13 with MemoryARW

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

the class MemoryCARWImplTest method testMaxPages.

@Test
public void testMaxPages() {
    int pageSize = 256;
    int maxPages = 3;
    int sz = 256 * 3;
    try (MemoryARW mem = new MemoryCARWImpl(pageSize, maxPages, MemoryTag.NATIVE_DEFAULT)) {
        Assert.assertEquals(pageSize, mem.size());
        int n = 0;
        try {
            while (n <= sz) {
                mem.putByte((byte) n);
                n++;
            }
            Assert.fail();
        } catch (CairoException ex) {
            Assert.assertTrue(ex.getMessage().contains("breached"));
        }
        Assert.assertEquals(sz, n);
        for (n = 0; n < sz; n++) {
            byte b = mem.getByte(n);
            Assert.assertEquals((byte) n, b);
        }
    }
}
Also used : CairoException(io.questdb.cairo.CairoException) MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 14 with MemoryARW

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

the class MemoryCARWImplTest method testChar.

@Test
public void testChar() {
    try (MemoryARW mem = new MemoryCARWImpl(7, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        char n = 999;
        long o = 0;
        for (char i = n; i > 0; i--) {
            mem.putChar(i);
            o += 2;
            Assert.assertEquals(o, mem.getAppendOffset());
        }
        o = 0;
        for (char i = n; i > 0; i--) {
            assertEquals(i, mem.getChar(o));
            o += 2;
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 15 with MemoryARW

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

the class MemoryCARWImplTest method testLong256PartialStr.

@Test
public void testLong256PartialStr() {
    final String expected = "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed";
    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";
        if (long256.getLong3() != 0) {
            actual += Long.toHexString(long256.getLong3());
        }
        if (long256.getLong2() != 0) {
            actual += Long.toHexString(long256.getLong2());
        }
        if (long256.getLong1() != 0) {
            actual += Long.toHexString(long256.getLong1());
        }
        if (long256.getLong0() != 0) {
            actual += Long.toHexString(long256.getLong0());
        }
        Assert.assertEquals(expected, actual);
        mem.getLong256(Long256.BYTES, long256a);
        String actual2 = "0x";
        if (long256a.getLong3() != 0) {
            actual2 += Long.toHexString(long256a.getLong3());
        }
        if (long256a.getLong2() != 0) {
            actual2 += Long.toHexString(long256a.getLong2());
        }
        if (long256a.getLong1() != 0) {
            actual2 += Long.toHexString(long256a.getLong1());
        }
        if (long256a.getLong0() != 0) {
            actual2 += Long.toHexString(long256a.getLong0());
        }
        Assert.assertEquals(expected, actual2);
        long o = mem.getAppendOffset();
        mem.putLong256(expected, 2, expected.length());
        Assert.assertEquals(long256, mem.getLong256A(o));
        String padded = "JUNK" + expected + "MOREJUNK";
        mem.putLong256(padded, 6, 4 + expected.length());
        Assert.assertEquals(long256, mem.getLong256A(o));
        try {
            mem.putLong256(padded);
            Assert.fail();
        } catch (CairoException ex) {
            Assert.assertTrue(ex.getMessage().contains("invalid long256"));
            Assert.assertTrue(ex.getMessage().contains(padded));
        }
    }
}
Also used : CairoException(io.questdb.cairo.CairoException) 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