void verify(Bucket bucket) throws UnsupportedEncodingException { // verify System.out.println("Starting verification procedure"); for (Map.Entry<String, byte[]> cacheEntry : verificationCache.entrySet()) { Object doc = bucket.get(cacheEntry.getKey(), recordClass); if (doc instanceof TupleDocument) { ByteBuf returnedBuf = (((TupleDocument) doc).content()).value1(); byte[] returnedBytes = new byte[returnedBuf.readableBytes()]; returnedBuf.getBytes(0, returnedBytes); Assert.assertEquals(returnedBytes, cacheEntry.getValue(), "Returned content for TupleDoc should be equal"); } else if (doc instanceof RawJsonDocument) { byte[] returnedBytes = ((RawJsonDocument) doc).content().getBytes("UTF-8"); Assert.assertEquals(returnedBytes, cacheEntry.getValue(), "Returned content for JsonDoc should be equal"); } else { Assert.fail("Returned type was neither TupleDocument nor RawJsonDocument"); } } System.out.println("Verification success!"); } }
void onWrite(AbstractDocument doc) throws UnsupportedEncodingException { recordClass = doc.getClass(); if (doc instanceof TupleDocument) { ByteBuf outgoingBuf = (((TupleDocument) doc).content()).value1(); byte[] outgoingBytes = new byte[outgoingBuf.readableBytes()]; outgoingBuf.getBytes(0, outgoingBytes); verificationCache.put(doc.id(), outgoingBytes); } else if (doc instanceof RawJsonDocument) { verificationCache.put(doc.id(), ((RawJsonDocument) doc).content().getBytes("UTF-8")); } else { throw new UnsupportedOperationException("Can only support TupleDocument or RawJsonDocument at this time"); } }
byteBuf.getBytes(byteBuf.readerIndex(), out, byteBuf.readableBytes()); byteBuf.release(); };
@Override public ByteBuf getBytes(int index, byte[] dst) { buf.getBytes(index, dst); return this; }
@Override public ByteBuf getBytes(int index, ByteBuffer dst) { buf.getBytes(index, dst); return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { buf.getBytes(index, dst, dstIndex, length); return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int length) { buf.getBytes(index, dst, length); return this; }
@Override public ByteBuf getBytes(int index, byte[] dst) { buf.getBytes(index, dst); return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { unwrap().getBytes(index, dst, dstIndex, length); return this; }
@Override public ByteBuf getBytes(int index, ByteBuffer dst) { unwrap().getBytes(index, dst); return this; }
@Override public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) { unwrap().getBytes(index, dst, dstIndex, length); return this; }
@Override public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { unwrap().getBytes(index, out, length); return this; }
@Override public int getBytes(int index, GatheringByteChannel out, int length) throws IOException { return unwrap().getBytes(index, out, length); }
@Override public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { unwrap().getBytes(index, out, length); return this; }
@Override public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) { checkIndex(index, length); buffer.getBytes(index, dst, dstIndex, length); return this; }
@Override public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException { unwrap().getBytes(index, out, length); return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { unwrap().getBytes(index, dst, dstIndex, length); return this; }
@Override public ByteBuf getBytes(int index, ByteBuffer dst) { checkIndex0(index, dst.remaining()); unwrap().getBytes(idx(index), dst); return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { checkIndex0(index, length); unwrap().getBytes(idx(index), dst, dstIndex, length); return this; }
@Override public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { checkIndex0(index, length); unwrap().getBytes(idx(index), dst, dstIndex, length); return this; }