use of com.questdb.std.DirectInputStream in project questdb by bluestreak01.
the class VariableColumnTest method testCopyBinaryColumnData.
@Test
public void testCopyBinaryColumnData() throws Exception {
int bitHint = 8;
try (MemoryFile smallFile = new MemoryFile(new File(temporaryFolder.getRoot(), "small.d"), bitHint, JournalMode.APPEND, false)) {
VariableColumn col1 = new VariableColumn(smallFile, indexFile);
int max = (int) Math.pow(2, bitHint) * 10 + 1;
OutputStream writeStream = col1.putBin();
for (int i = 0; i < max; i++) {
writeStream.write(i % 255);
}
writeStream.flush();
col1.commit();
int shift = (int) Math.ceil(max / 4.0);
for (int offset = 0; offset < max; offset += shift) {
int readLen = max - offset;
DirectInputStream readStream = col1.getBin(0);
long readAddress = Unsafe.malloc(readLen);
readStream.copyTo(readAddress, offset, readLen);
for (int i = 0; i < readLen; i++) {
byte expected = (byte) ((offset + i) % 255);
byte actual = Unsafe.getUnsafe().getByte(readAddress + i);
Assert.assertEquals(String.format("difference at index %d with read offset %d", i, offset), expected, actual);
}
Unsafe.free(readAddress, readLen);
}
}
}
use of com.questdb.std.DirectInputStream in project questdb by bluestreak01.
the class VariableColumnTest method testBin1.
@Test
public void testBin1() throws Exception {
int N = 1000;
int SZ = 4096;
ByteBuffer buf = ByteBuffer.allocateDirect(SZ);
long addr = ByteBuffers.getAddress(buf);
try {
Rnd rnd = new Rnd();
try (MemoryFile smallFile = new MemoryFile(new File(temporaryFolder.getRoot(), "small.d"), 8, JournalMode.APPEND, false)) {
try (VariableColumn col = new VariableColumn(smallFile, indexFile)) {
for (int i = 0; i < N; i++) {
long p = addr;
int n = (rnd.nextPositiveInt() % (SZ - 1)) / 8;
for (int j = 0; j < n; j++) {
Unsafe.getUnsafe().putLong(p, rnd.nextLong());
p += 8;
}
buf.limit(n * 8);
col.putBin(buf);
col.commit();
buf.clear();
}
Assert.assertEquals(N, col.size());
rnd = new Rnd();
for (int i = 0; i < N; i++) {
long len = col.getBinLen(i);
DirectInputStream is = col.getBin(i);
is.copyTo(addr, 0, len);
long p = addr;
int n = (rnd.nextPositiveInt() % (SZ - 1)) / 8;
for (int j = 0; j < n; j++) {
Assert.assertEquals(rnd.nextLong(), Unsafe.getUnsafe().getLong(p));
p += 8;
}
}
}
}
} finally {
ByteBuffers.release(buf);
}
}
use of com.questdb.std.DirectInputStream in project questdb by bluestreak01.
the class VariableColumnTest method testReadBinaryColumnData.
@Test
public void testReadBinaryColumnData() throws Exception {
int bitHint = 8;
try (MemoryFile smallFile = new MemoryFile(new File(temporaryFolder.getRoot(), "small.d"), bitHint, JournalMode.APPEND, false)) {
VariableColumn col1 = new VariableColumn(smallFile, indexFile);
int max = (int) Math.pow(2, bitHint) * 10 + 1;
Rnd rnd = new Rnd();
OutputStream writeStream = col1.putBin();
for (int i = 0; i < max; i++) {
writeStream.write(rnd.nextInt());
}
writeStream.flush();
col1.commit();
DirectInputStream readStream = col1.getBin(0);
byte b;
int count = 0;
Rnd exp = new Rnd();
while ((b = (byte) readStream.read()) != -1) {
Assert.assertEquals(String.format("difference at index %d", count), (byte) exp.nextInt(), b);
count++;
}
}
}
Aggregations