Search in sources :

Example 1 with KeepAlive

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);
}
Also used : KeepAlive(io.pravega.shared.protocol.netty.WireCommands.KeepAlive) ByteBuf(io.netty.buffer.ByteBuf) Cleanup(lombok.Cleanup)

Example 2 with KeepAlive

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);
}
Also used : SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) KeepAlive(io.pravega.shared.protocol.netty.WireCommands.KeepAlive) ByteBuf(io.netty.buffer.ByteBuf) Cleanup(lombok.Cleanup) Test(org.junit.Test)

Example 3 with KeepAlive

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);
}
Also used : SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) KeepAlive(io.pravega.shared.protocol.netty.WireCommands.KeepAlive) ByteBuf(io.netty.buffer.ByteBuf) Cleanup(lombok.Cleanup)

Example 4 with KeepAlive

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");
        }
    }
}
Also used : KeepAlive(io.pravega.shared.protocol.netty.WireCommands.KeepAlive) ClientConnection(io.pravega.client.netty.impl.ClientConnection) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException)

Aggregations

KeepAlive (io.pravega.shared.protocol.netty.WireCommands.KeepAlive)4 ByteBuf (io.netty.buffer.ByteBuf)3 Cleanup (lombok.Cleanup)3 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)2 ClientConnection (io.pravega.client.netty.impl.ClientConnection)1 AuthenticationException (io.pravega.common.auth.AuthenticationException)1 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)1 Test (org.junit.Test)1