use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.
the class MemoryCARWImplTest method testStrRnd.
private void testStrRnd(long offset, long pageSize) {
Rnd rnd = new Rnd();
int N = 1000;
final int M = 4;
try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
long o = offset;
for (int i = 0; i < N; i++) {
int flag = rnd.nextInt();
if ((flag % 4) == 0) {
mem.putStr(o, null);
o += 4;
} else if ((flag % 2) == 0) {
mem.putStr(o, "");
o += 4;
} else {
mem.putStr(o, rnd.nextChars(M));
o += M * 2 + 4;
}
}
rnd.reset();
o = offset;
for (int i = 0; i < N; i++) {
int flag = rnd.nextInt();
if ((flag % 4) == 0) {
assertNull(mem.getStr(o));
o += 4;
} else if ((flag % 2) == 0) {
TestUtils.assertEquals("", mem.getStr(o));
o += 4;
} else {
TestUtils.assertEquals(rnd.nextChars(M), mem.getStr(o));
o += M * 2 + 4;
}
}
}
}
use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.
the class MemoryCARWImplTest method testLong256ObjExternallySequenced.
@Test
public void testLong256ObjExternallySequenced() {
long pageSize = 64;
Rnd rnd = new Rnd();
long offset = 0;
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(offset, long256);
offset += Long256.BYTES;
}
rnd.reset();
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());
}
}
}
use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.
the class MemoryCARWImplTest method testIntCompatibility.
@Test
public void testIntCompatibility() {
long pageSize = 64;
try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
mem.putInt(1024);
mem.putInt(2048);
assertEquals(1024, mem.getInt(0));
assertEquals(2048, mem.getInt(4));
}
}
use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.
the class MemoryCARWImplTest method testDoubleRnd.
@Test
public void testDoubleRnd() {
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.putDouble(o, rnd.nextDouble());
o += 8;
}
rnd.reset();
o = 1;
assertEquals(1, mem.getByte(0));
for (int i = 0; i < n; i++) {
assertEquals(rnd.nextDouble(), mem.getDouble(o), 0.00001);
o += 8;
}
}
}
use of io.questdb.cairo.vm.api.MemoryARW in project questdb by bluestreak01.
the class MemoryCARWImplTest method testLongCompatibility.
@Test
public void testLongCompatibility() {
long pageSize = 64;
try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
mem.putLong(8980980284302834L);
mem.putLong(897928374972983477L);
assertEquals(8980980284302834L, mem.getLong(0));
assertEquals(897928374972983477L, mem.getLong(8));
}
}
Aggregations