use of com.github.ambry.store.MockWrite in project ambry by linkedin.
the class AmbryServerRequestsTest method getDataInWriteSet.
/**
* Gets the data of size in the {@code messageWriteSet} into a {@link ByteBuffer}
* @param messageWriteSet the {@link MessageWriteSet} to read from
* @param size the size of data to read. If this size is greater than the amount of data in {@code messageWriteSet},
* then this function will loop infinitely
* @return a {@link ByteBuffer} containing data of size {@code size} from {@code messageWriteSet}
* @throws StoreException
*/
private ByteBuffer getDataInWriteSet(MessageWriteSet messageWriteSet, int size) throws StoreException {
MockWrite write = new MockWrite(size);
long sizeWritten = 0;
while (sizeWritten < size) {
sizeWritten += messageWriteSet.writeTo(write);
}
return write.getBuffer();
}
use of com.github.ambry.store.MockWrite in project ambry by linkedin.
the class MessageFormatWriteSetTest method writeSetTest.
@Test
public void writeSetTest() throws IOException, StoreException {
byte[] buf = new byte[2000];
MessageInfo info1 = new MessageInfo(new MockId("id1"), 1000, 123, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), System.currentTimeMillis() + TestUtils.RANDOM.nextInt());
MessageInfo info2 = new MessageInfo(new MockId("id2"), 1000, 123, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), System.currentTimeMillis() + TestUtils.RANDOM.nextInt());
List<MessageInfo> infoList = new ArrayList<MessageInfo>();
infoList.add(info1);
infoList.add(info2);
ByteBufferInputStream byteBufferInputStream = new ByteBufferInputStream(ByteBuffer.wrap(buf));
MessageFormatWriteSet set = new MessageFormatWriteSet(byteBufferInputStream, infoList, false);
MockWrite write = new MockWrite(2000);
long written = set.writeTo(write);
Assert.assertEquals(written, 2000);
Assert.assertEquals(write.getBuffer().limit(), 2000);
Assert.assertArrayEquals(write.getBuffer().array(), buf);
}
Aggregations