Search in sources :

Example 41 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore 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)

Example 42 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class AppendProcessorTest method testSwitchingSegment.

@Test
public void testSwitchingSegment() {
    String streamSegmentName1 = "testAppendSegment1";
    String streamSegmentName2 = "testAppendSegment2";
    UUID clientId = UUID.randomUUID();
    byte[] data = new byte[] { 1, 2, 3, 4, 6, 7, 8, 9 };
    StreamSegmentStore store = mock(StreamSegmentStore.class);
    InOrder verifier = Mockito.inOrder(store);
    ServerConnection connection = mock(ServerConnection.class);
    AppendProcessor processor = new AppendProcessor(store, connection, new FailingRequestProcessor(), null);
    setupGetStreamSegmentInfo(streamSegmentName1, clientId, store);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName1, ""));
    verifier.verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName1, data, updateEventNumber(clientId, 10), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName1, clientId, 10, Unpooled.wrappedBuffer(data), null));
    verifier.verify(store).append(streamSegmentName1, data, updateEventNumber(clientId, 10), AppendProcessor.TIMEOUT);
    setupGetStreamSegmentInfo(streamSegmentName2, clientId, store);
    processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName2, ""));
    verifier.verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    CompletableFuture<Void> result2 = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName2, data, updateEventNumber(clientId, 2000), AppendProcessor.TIMEOUT)).thenReturn(result2);
    processor.append(new Append(streamSegmentName2, clientId, 2000, Unpooled.wrappedBuffer(data), null));
    verifier.verify(store).append(streamSegmentName2, data, updateEventNumber(clientId, 2000), AppendProcessor.TIMEOUT);
    CompletableFuture<Void> result3 = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName1, data, updateEventNumber(clientId, 20, 10, 1), AppendProcessor.TIMEOUT)).thenReturn(result3);
    processor.append(new Append(streamSegmentName1, clientId, 20, Unpooled.wrappedBuffer(data), null));
    verifier.verify(store).append(streamSegmentName1, data, updateEventNumber(clientId, 20, 10, 1), AppendProcessor.TIMEOUT);
    verifyNoMoreInteractions(store);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) InOrder(org.mockito.InOrder) 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) Test(org.junit.Test)

Example 43 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class AppendProcessorTest method testSetupSkipped.

@Test
public void testSetupSkipped() {
    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);
    try {
        processor.append(new Append(streamSegmentName, clientId, data.length, Unpooled.wrappedBuffer(data), null));
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UUID(java.util.UUID) Test(org.junit.Test)

Example 44 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class AppendProcessorTest method testConditionalAppendSuccess.

@Test
public void testConditionalAppendSuccess() {
    String streamSegmentName = "testConditionalAppendSuccess";
    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 = CompletableFuture.completedFuture(null);
    when(store.append(streamSegmentName, data.length, data, updateEventNumber(clientId, 2, 1, 1), AppendProcessor.TIMEOUT)).thenReturn(result);
    processor.append(new Append(streamSegmentName, clientId, 2, Unpooled.wrappedBuffer(data), (long) data.length));
    verify(store).getStreamSegmentInfo(anyString(), eq(true), eq(AppendProcessor.TIMEOUT));
    verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 1), AppendProcessor.TIMEOUT);
    verify(store).append(streamSegmentName, data.length, 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 DataAppended(clientId, 2, 1));
    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 45 with StreamSegmentStore

use of io.pravega.segmentstore.contracts.StreamSegmentStore in project pravega by pravega.

the class AppendProcessorTest method testUnsupportedOperation.

@Test
public void testUnsupportedOperation() {
    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 = Futures.failedFuture(new UnsupportedOperationException());
    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 OperationUnsupported(data.length, "appending data"));
    verifyNoMoreInteractions(connection);
    verifyNoMoreInteractions(store);
}
Also used : FailingRequestProcessor(io.pravega.shared.protocol.netty.FailingRequestProcessor) OperationUnsupported(io.pravega.shared.protocol.netty.WireCommands.OperationUnsupported) 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) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

StreamSegmentStore (io.pravega.segmentstore.contracts.StreamSegmentStore)75 Test (org.junit.Test)52 PravegaConnectionListener (io.pravega.segmentstore.server.host.handler.PravegaConnectionListener)45 Cleanup (lombok.Cleanup)40 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)25 UUID (java.util.UUID)23 TestingServerStarter (io.pravega.test.common.TestingServerStarter)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 MockStreamManager (io.pravega.client.stream.mock.MockStreamManager)19 MockClientFactory (io.pravega.client.stream.mock.MockClientFactory)18 Before (org.junit.Before)17 ControllerWrapper (io.pravega.test.integration.demo.ControllerWrapper)16 SetupAppend (io.pravega.shared.protocol.netty.WireCommands.SetupAppend)15 Append (io.pravega.shared.protocol.netty.Append)14 CompletableFuture (java.util.concurrent.CompletableFuture)12 FailingRequestProcessor (io.pravega.shared.protocol.netty.FailingRequestProcessor)11 WireCommands (io.pravega.shared.protocol.netty.WireCommands)11 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)10 Controller (io.pravega.client.stream.impl.Controller)10 JavaSerializer (io.pravega.client.stream.impl.JavaSerializer)10