use of io.pravega.shared.protocol.netty.WireCommands.KeepAlive in project pravega by pravega.
the class AppendEncodeDecodeTest method sendAndVerifyEvents.
private void sendAndVerifyEvents(String segment, UUID writerId, int numEvents, int eventSize, int expectedMessages) throws Exception {
@Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer();
ArrayList<Object> received = setupAppend(segment, writerId, fakeNetwork);
for (int i = 0; i < numEvents; i++) {
append(segment, writerId, eventSize * (i + 1L), i, eventSize, fakeNetwork);
read(fakeNetwork, received);
}
KeepAlive keepAlive = new KeepAlive();
encoder.encode(null, keepAlive, fakeNetwork);
read(fakeNetwork, received);
assertEquals(expectedMessages + 1, received.size());
assertEquals(received.get(received.size() - 1), keepAlive);
received.remove(received.size() - 1);
verify(received, numEvents, eventSize);
}
use of io.pravega.shared.protocol.netty.WireCommands.KeepAlive in project pravega by pravega.
the class AppendEncodeDecodeTest method testAppendAtBlockBound.
@Test
public void testAppendAtBlockBound() throws Exception {
int size = appendBlockSize;
@Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer();
ArrayList<Object> received = setupAppend(streamName, writerId, fakeNetwork);
append(streamName, writerId, size, 1, size, fakeNetwork);
read(fakeNetwork, received);
assertEquals(1, received.size());
append(streamName, writerId, size + size / 2, 2, size / 2, fakeNetwork);
read(fakeNetwork, received);
assertEquals(1, received.size());
KeepAlive keepAlive = new KeepAlive();
encoder.encode(null, keepAlive, fakeNetwork);
read(fakeNetwork, received);
assertEquals(3, received.size());
Append one = (Append) received.get(0);
Append two = (Append) received.get(1);
assertEquals(size + TYPE_PLUS_LENGTH_SIZE, one.getData().readableBytes());
assertEquals(size / 2 + TYPE_PLUS_LENGTH_SIZE, two.getData().readableBytes());
KeepAlive three = (KeepAlive) received.get(2);
assertEquals(keepAlive, three);
}
use of io.pravega.shared.protocol.netty.WireCommands.KeepAlive in project pravega by pravega.
the class AppendEncodeDecodeTest method testFlush.
private void testFlush(int size) throws Exception {
@Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer();
ArrayList<Object> received = setupAppend(streamName, writerId, fakeNetwork);
append(streamName, writerId, size, 0, size, fakeNetwork);
read(fakeNetwork, received);
KeepAlive keepAlive = new KeepAlive();
encoder.encode(null, keepAlive, fakeNetwork);
read(fakeNetwork, received);
assertEquals(2, received.size());
Append one = (Append) received.get(0);
assertEquals(size + TYPE_PLUS_LENGTH_SIZE, one.getData().readableBytes());
KeepAlive two = (KeepAlive) received.get(1);
assertEquals(keepAlive, two);
}
use of io.pravega.shared.protocol.netty.WireCommands.KeepAlive in project pravega by pravega.
the class SegmentOutputStreamImpl method flush.
/**
* @see SegmentOutputStream#flush()
*/
@Override
public void flush() throws SegmentSealedException {
if (!state.isInflightEmpty()) {
log.debug("Flushing writer: {}", writerId);
try {
ClientConnection connection = Futures.getThrowingException(getConnection());
connection.send(new KeepAlive());
} catch (Exception e) {
failConnection(e);
}
state.waitForInflight();
Exceptions.checkNotClosed(state.isClosed(), this);
if (state.isAlreadySealed()) {
throw new SegmentSealedException(segmentName + " sealed");
}
}
}
Aggregations