Search in sources :

Example 11 with SetupAppend

use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.

the class SegmentOutputStreamTest method testConnectAndFailedSetupAppend.

@Test(timeout = 10000)
public void testConnectAndFailedSetupAppend() throws Exception {
    UUID cid = UUID.randomUUID();
    PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
    MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
    ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
    // Ensure task submitted to executor is run inline.
    implementAsDirectExecutor(executor);
    cf.setExecutor(executor);
    MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
    ClientConnection connection = mock(ClientConnection.class);
    doThrow(ConnectionFailedException.class).doNothing().when(connection).send(any(SetupAppend.class));
    cf.provideConnection(uri, connection);
    SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
    output.reconnect();
    verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
    verify(connection).send(new SetupAppend(2, cid, SEGMENT, ""));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) MockConnectionFactoryImpl(io.pravega.client.stream.mock.MockConnectionFactoryImpl) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) MockController(io.pravega.client.stream.mock.MockController) ClientConnection(io.pravega.client.netty.impl.ClientConnection) UUID(java.util.UUID) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Test(org.junit.Test)

Example 12 with SetupAppend

use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.

the class AppendProcessorTest method testAppend.

@Test
public void testAppend() {
    String streamSegmentName = "testAppendSegment";
    UUID clientId = UUID.randomUUID();
    byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    ServerConnection connection = mock(ServerConnection.class);
    AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
    setupGetStreamSegmentInfo(streamSegmentName, clientId, store);
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
    verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, data.length), AppendProcessor.TIMEOUT);
    verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).send(new DataAppended(clientId, data.length, 0L));
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with SetupAppend

use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.

the class AppendProcessorTest method testSwitchingStream.

@Test
public void testSwitchingStream() {
    String segment1 = "segment1";
    String segment2 = "segment2";
    UUID clientId1 = UUID.randomUUID();
    UUID clientId2 = UUID.randomUUID();
    byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    ServerConnection connection = mock(ServerConnection.class);
    AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
    setupGetStreamSegmentInfo(segment1, clientId1, store);
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    when(store.append(segment1, data, updateEventNumber(clientId1, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    setupGetStreamSegmentInfo(segment2, clientId2, store);
    result = CompletableFuture.completedFuture(null);
    when(store.append(segment2, data, updateEventNumber(clientId2, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.setupAppend(new SetupAppend(1, clientId1, segment1, ""));
    processor.append(new Append(segment1, clientId1, data.length, Unpooled.wrappedBuffer(data), null));
    processor.setupAppend(new SetupAppend(2, clientId2, segment2, ""));
    processor.append(new Append(segment2, clientId2, data.length, Unpooled.wrappedBuffer(data), null));
    verify(store).getStreamSegmentInfo(eq(segment1), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(segment1, data, updateEventNumber(clientId1, data.length), AppendProcessor.TIMEOUT);
    verify(store).getStreamSegmentInfo(eq(segment2), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(segment2, data, updateEventNumber(clientId2, data.length), AppendProcessor.TIMEOUT);
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).send(new AppendSetup(1, segment1, clientId1, 0));
    verify(connection).send(new DataAppended(clientId1, data.length, 0));
    verify(connection).send(new AppendSetup(2, segment2, clientId2, 0));
    verify(connection).send(new DataAppended(clientId2, data.length, 0));
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with SetupAppend

use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.

the class AppendTest method testMultipleAppends.

@Test(timeout = 10000)
public void testMultipleAppends() throws Exception {
    String segment = "123";
    ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
    StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
    @Cleanup EmbeddedChannel channel = createChannel(store);
    SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, ""));
    assertEquals(segment, created.getSegment());
    UUID uuid = UUID.randomUUID();
    AppendSetup setup = (AppendSetup) sendRequest(channel, new SetupAppend(2, uuid, segment, ""));
    assertEquals(segment, setup.getSegment());
    assertEquals(uuid, setup.getWriterId());
    data.retain();
    DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, 1, data, null));
    assertEquals(uuid, ack.getWriterId());
    assertEquals(1, ack.getEventNumber());
    assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
    DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, data, null));
    assertEquals(uuid, ack2.getWriterId());
    assertEquals(2, ack2.getEventNumber());
    assertEquals(1, ack2.getPreviousEventNumber());
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) SegmentCreated(io.pravega.shared.protocol.netty.WireCommands.SegmentCreated) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) UUID(java.util.UUID) Cleanup(lombok.Cleanup) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) Test(org.junit.Test)

Example 15 with SetupAppend

use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.

the class AppendEncodeDecodeTest method setupAppend.

private ArrayList<Object> setupAppend(String testStream, UUID writerId, ByteBuf fakeNetwork) throws Exception {
    SetupAppend setupAppend = new SetupAppend(1, writerId, testStream, "");
    encoder.encode(null, setupAppend, fakeNetwork);
    ArrayList<Object> received = new ArrayList<>();
    WireCommand command = CommandDecoder.parseCommand(fakeNetwork);
    assertTrue(appendDecoder.acceptInboundMessage(command));
    assertEquals(setupAppend, appendDecoder.processCommand(command));
    return received;
}
Also used : SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) ArrayList(java.util.ArrayList)

Aggregations

SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)39 Test (org.junit.Test)35 UUID (java.util.UUID)34 AppendSetup (io.pravega.shared.protocol.netty.WireCommands.AppendSetup)27 Append (io.pravega.shared.protocol.netty.Append)26 ClientConnection (io.pravega.client.netty.impl.ClientConnection)20 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)20 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)19 MockController (io.pravega.client.stream.mock.MockController)19 CompletableFuture (java.util.concurrent.CompletableFuture)17 Cleanup (lombok.Cleanup)17 PendingEvent (io.pravega.client.stream.impl.PendingEvent)15 StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 InOrder (org.mockito.InOrder)13 FailingRequestProcessor (io.pravega.shared.protocol.netty.FailingRequestProcessor)11 WireCommands (io.pravega.shared.protocol.netty.WireCommands)11 ByteBuffer (java.nio.ByteBuffer)11 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11