private static ByteBuffer serialize(WritableSupplier<ColumnarInts> writableSupplier) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect((int) writableSupplier.getSerializedSize()); WritableByteChannel channel = new WritableByteChannel() { @Override public int write(ByteBuffer src) { int size = src.remaining(); buffer.put(src); return size; } @Override public boolean isOpen() { return true; } @Override public void close() { } }; writableSupplier.writeTo(channel, null); buffer.rewind(); return buffer; }
@Test public void testSerde() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); columnarMultiIntsSupplier.writeTo(Channels.newChannel(baos), null); final byte[] bytes = baos.toByteArray(); Assert.assertEquals(columnarMultiIntsSupplier.getSerializedSize(), bytes.length); WritableSupplier<ColumnarMultiInts> deserializedColumnarMultiInts = fromByteBuffer(ByteBuffer.wrap(bytes)); assertSame(vals, deserializedColumnarMultiInts.get()); }
@Test public void testSanity() { assertSame(vals, columnarMultiIntsSupplier.get()); }
@Test(expected = IllegalArgumentException.class) public void testGetInvalidElementInRow() { columnarMultiIntsSupplier.get().get(3).get(15); }
private static ByteBuffer serialize(WritableSupplier<ColumnarMultiInts> writableSupplier) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect((int) writableSupplier.getSerializedSize()); WritableByteChannel channel = new WritableByteChannel() { @Override public int write(ByteBuffer src) { int size = src.remaining(); buffer.put(src); return size; } @Override public boolean isOpen() { return true; } @Override public void close() { } }; writableSupplier.writeTo(channel, null); buffer.rewind(); return buffer; }
@Test public void testIterators() { Iterator<IndexedInts> iterator = columnarMultiIntsSupplier.get().iterator(); int row = 0; while (iterator.hasNext()) { final int[] ints = vals.get(row); final IndexedInts vSizeIndexedInts = iterator.next(); Assert.assertEquals(ints.length, vSizeIndexedInts.size()); for (int i = 0, size = vSizeIndexedInts.size(); i < size; i++) { Assert.assertEquals(ints[i], vSizeIndexedInts.get(i)); } row++; } }