Skip to content

Instantly share code, notes, and snippets.

@antofar
Created January 31, 2017 10:35
Show Gist options
  • Save antofar/c41eba1fecc45794775b8467ce6fcb30 to your computer and use it in GitHub Desktop.
Save antofar/c41eba1fecc45794775b8467ce6fcb30 to your computer and use it in GitHub Desktop.
private static final int DEFAULT_BUFFER_SIZE = 1024 * 1024 * 4;
/**
* Test that bytes are written to the provided WriteStream correctly and the callback returns
* the excepted result.
*/
@Test
public void happyPathWriteWithNotAlignedBuffer() {
byte[] bytes = "123456789ABCDEF".getBytes();
ByteBuffer byteBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
byteBuffer.put(bytes);
byteBuffer.flip();
ResultCallback<Integer> resultCallback = new ResultCallback<>();
WriteStreamMock writeStreamMock = new WriteStreamMock();
GridFSOutputStream outputStream = GridFSOutputStream.create(writeStreamMock);
outputStream.write(byteBuffer, resultCallback);
Assert.assertTrue(resultCallback.succeeded());
Assert.assertEquals(bytes.length, resultCallback.getResult(), 0);
Assert.assertTrue(Arrays.equals(writeStreamMock.buffer.getBytes(), bytes));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment