Search in sources :

Example 16 with SetupAppend

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

the class AppendProcessorTest method testInvalidOffset.

@Test
public void testInvalidOffset() {
    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, 100, store);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    try {
        processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 100));
    verify(connection, atLeast(0)).resumeReading();
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UUID(java.util.UUID) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) Test(org.junit.Test)

Example 17 with SetupAppend

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

the class AppendProcessorTest method testAppendFails.

@Test
public void testAppendFails() {
    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 = new CompletableFuture<>();
    result.completeExceptionally(new RuntimeException("Fake exception for testing"));
    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));
    try {
        processor.append(new Append(streamSegmentName, clientId, data.length * 2, Unpooled.wrappedBuffer(data), null));
        fail();
    } catch (IllegalStateException e) {
    // Expected
    }
    verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).close();
    verify(store, atMost(1)).append(any(), any(), any(), any());
    verifyNoMoreInteractions(connection);
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with SetupAppend

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

the class AppendProcessorTest method testEventNumbers.

@Test
public void testEventNumbers() {
    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);
    CompletableFuture<SegmentProperties> propsFuture = CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).build());
    when(store.getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT)).thenReturn(propsFuture);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    verify(store).getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT);
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    int eventCount = 100;
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, 100, SegmentMetadata.NULL_ATTRIBUTE_VALUE, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName, clientId, 100, eventCount, Unpooled.wrappedBuffer(data), null));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 100, SegmentMetadata.NULL_ATTRIBUTE_VALUE, eventCount), AppendProcessor.TIMEOUT);
    Map<UUID, Long> map = new HashMap<>();
    map.put(clientId, 100L);
    map.put(EVENT_COUNT, 100L);
    propsFuture = CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).attributes(map).build());
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName, clientId, 200, eventCount, Unpooled.wrappedBuffer(data), null));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with SetupAppend

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

the class AppendProcessorTest method testEventNumbersOldClient.

@Test
public void testEventNumbersOldClient() {
    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);
    CompletableFuture<SegmentProperties> propsFuture = CompletableFuture.completedFuture(StreamSegmentInformation.builder().name(streamSegmentName).attributes(Collections.singletonMap(clientId, 100L)).build());
    when(store.getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT)).thenReturn(propsFuture);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    verify(store).getStreamSegmentInfo(streamSegmentName, true, AppendProcessor.TIMEOUT);
    int eventCount = 10;
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName, clientId, 200, eventCount, Unpooled.wrappedBuffer(data), null));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT);
    when(store.append(streamSegmentName, data, updateEventNumber(clientId, 300, 200, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName, clientId, 300, eventCount, Unpooled.wrappedBuffer(data), null));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 300, 200, eventCount), AppendProcessor.TIMEOUT);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) Append(io.pravega.shared.protocol.netty.Append) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with SetupAppend

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

the class AppendProcessorTest method testConditionalAppendFailure.

@Test
public void testConditionalAppendFailure() {
    String streamSegmentName = "testConditionalAppendFailure";
    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, 1), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
    processor.append(new Append(streamSegmentName, clientId, 1, Unpooled.wrappedBuffer(data), null));
    result = Futures.failedFuture(new BadOffsetException(streamSegmentName, data.length, 0));
    when(store.append(streamSegmentName, 0, data, updateEventNumber(clientId, 2, 1, 1), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName, clientId, 2, Unpooled.wrappedBuffer(data), 0L));
    verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 1), AppendProcessor.TIMEOUT);
    verify(store).append(streamSegmentName, 0L, data, updateEventNumber(clientId, 2, 1, 1), AppendProcessor.TIMEOUT);
    verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
    verify(connection, atLeast(0)).resumeReading();
    verify(connection).send(new DataAppended(clientId, 1, 0));
    verify(connection).send(new ConditionalCheckFailed(clientId, 2));
    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) ConditionalCheckFailed(io.pravega.shared.protocol.netty.WireCommands.ConditionalCheckFailed) 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) BadOffsetException(io.pravega.segmentstore.contracts.BadOffsetException) UUID(java.util.UUID) Test(org.junit.Test)

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