Search in sources :

Example 31 with MemoryARW

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

the class MemoryCARWImplTest method testShortRnd.

@Test
public void testShortRnd() {
    try (MemoryARW mem = new MemoryCARWImpl(7, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        long o = 1;
        mem.putByte(0, (byte) 1);
        short n = 999;
        for (short i = n; i > 0; i--) {
            mem.putShort(o, i);
            o += 2;
        }
        assertEquals(1, mem.getByte(0));
        o = 1;
        for (short i = n; i > 0; i--) {
            assertEquals(i, mem.getShort(o));
            o += 2;
        }
    }
}
Also used : MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 32 with MemoryARW

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

the class MemoryCARWImplTest method testBinSequenceOnEdge.

@Test
public void testBinSequenceOnEdge() {
    final Rnd rnd = new Rnd();
    try (MemoryARW mem = new MemoryCARWImpl(32, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        TestRecord.ArrayBinarySequence seq = new TestRecord.ArrayBinarySequence();
        int N = 33;
        int O = 10;
        seq.of(rnd.nextBytes(N));
        mem.putBin(seq);
        BinarySequence actual = mem.getBin(0);
        assertNotNull(actual);
        TestUtils.assertEquals(seq, actual, N);
        long buffer = Unsafe.malloc(1024, MemoryTag.NATIVE_DEFAULT);
        try {
            // supply length of our buffer
            // blob content would be shorter
            Vect.memset(buffer, 1024, 5);
            actual.copyTo(buffer, 0, 1024);
            for (int i = 0; i < N; i++) {
                assertEquals(seq.byteAt(i), Unsafe.getUnsafe().getByte(buffer + i));
            }
            // rest of the buffer must not be overwritten
            for (int i = N; i < 1024; i++) {
                assertEquals(5, Unsafe.getUnsafe().getByte(buffer + i));
            }
            // copy from middle
            Vect.memset(buffer, 1024, 5);
            actual.copyTo(buffer, O, 1024);
            for (int i = 0; i < N - O; i++) {
                assertEquals(seq.byteAt(i + O), Unsafe.getUnsafe().getByte(buffer + i));
            }
            // rest of the buffer must not be overwritten
            for (int i = N - O; i < 1024; i++) {
                assertEquals(5, Unsafe.getUnsafe().getByte(buffer + i));
            }
        } finally {
            Unsafe.free(buffer, 1024, MemoryTag.NATIVE_DEFAULT);
        }
    }
}
Also used : TestBinarySequence(io.questdb.griffin.engine.TestBinarySequence) TestRecord(io.questdb.cairo.TestRecord) MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 33 with MemoryARW

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

the class MemoryCARWImplTest method testCharWithOffset.

@Test
public void testCharWithOffset() {
    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(o, i);
            o += 2;
        }
        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 34 with MemoryARW

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

the class MemoryCARWImplTest method testFloatRnd.

@Test
public void testFloatRnd() {
    try (MemoryARW mem = new MemoryCARWImpl(11, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        Rnd rnd = new Rnd();
        int n = 999;
        long o = 1;
        mem.putByte((byte) 1);
        for (int i = 0; i < n; i++) {
            mem.putFloat(o, rnd.nextFloat());
            o += 4;
        }
        rnd.reset();
        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 35 with MemoryARW

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

the class MemoryCARWImplTest method testLong256DirectExternallySequenced.

@Test
public void testLong256DirectExternallySequenced() {
    long pageSize = 64;
    Rnd rnd = new Rnd();
    Long256Impl sink = new Long256Impl();
    try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        long offset = 0;
        for (int i = 0; i < 1000; i++) {
            mem.putLong256(offset, rnd.nextLong(), rnd.nextLong(), rnd.nextLong(), rnd.nextLong());
            offset += Long256.BYTES;
        }
        rnd.reset();
        offset = 0;
        for (int i = 0; i < 1000; i++) {
            mem.getLong256(offset, sink);
            offset += Long256.BYTES;
            Assert.assertEquals(rnd.nextLong(), sink.getLong0());
            Assert.assertEquals(rnd.nextLong(), sink.getLong1());
            Assert.assertEquals(rnd.nextLong(), sink.getLong2());
            Assert.assertEquals(rnd.nextLong(), sink.getLong3());
        }
    }
}
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