Search in sources :

Example 1 with MockWrite

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();
}
Also used : MockWrite(com.github.ambry.store.MockWrite)

Example 2 with MockWrite

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);
}
Also used : MockWrite(com.github.ambry.store.MockWrite) ArrayList(java.util.ArrayList) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) MockId(com.github.ambry.store.MockId) MessageInfo(com.github.ambry.store.MessageInfo) Test(org.junit.Test)

Aggregations

MockWrite (com.github.ambry.store.MockWrite)2 MessageInfo (com.github.ambry.store.MessageInfo)1 MockId (com.github.ambry.store.MockId)1 ByteBufferInputStream (com.github.ambry.utils.ByteBufferInputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1