use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend 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);
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend 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);
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend 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);
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class AppendProcessorTest method testDelayedDataAppended.
/**
* Test to ensure newer appends are processed only after successfully sending the DataAppended acknowledgement
* back to client. This test tests the following:
* - If sending first DataAppended is blocked, ensure future appends are not written to store.
* - Once the first DataAppended is sent ensure the remaining appends are written to store and DataAppended ack'ed
* back.
*/
@Test(timeout = 15 * 1000)
public void testDelayedDataAppended() throws Exception {
ReusableLatch firstStoreAppendInvoked = new ReusableLatch();
ReusableLatch completeFirstDataAppendedAck = new ReusableLatch();
ReusableLatch secondStoreAppendInvoked = new ReusableLatch();
@Cleanup("shutdownNow") ScheduledExecutorService nettyExecutor = ExecutorServiceHelpers.newScheduledThreadPool(1, "Netty-threadPool");
String streamSegmentName = "testDelayedAppend";
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);
// Ensure the first DataAppended is hung/delayed.
doAnswer(invocation -> {
firstStoreAppendInvoked.release();
// wait, simulating a hung/delayed dataAppended acknowledgement.
completeFirstDataAppendedAck.await();
return null;
}).doAnswer(invocation -> {
secondStoreAppendInvoked.release();
return null;
}).when(connection).send(any(DataAppended.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);
// Trigger the first append, here the sending of DataAppended ack will be delayed/hung.
nettyExecutor.submit(() -> processor.append(new Append(streamSegmentName, clientId, 100, eventCount, Unpooled.wrappedBuffer(data), null)));
firstStoreAppendInvoked.await();
verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 100, SegmentMetadata.NULL_ATTRIBUTE_VALUE, eventCount), AppendProcessor.TIMEOUT);
/* Trigger the next append. This should be completed immediately and should not cause a store.append to be
invoked as the previous DataAppended ack is still not sent. */
processor.append(new Append(streamSegmentName, clientId, 200, eventCount, Unpooled.wrappedBuffer(data), null));
// Since the first Ack was never sent the next append should not be written to the store.
verifyNoMoreInteractions(store);
// Setup mock for check behaviour after the delayed/hung dataAppended completes.
when(store.append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT)).thenReturn(result);
// Now ensure the dataAppended sent
completeFirstDataAppendedAck.release();
// wait until the next store append is invoked.
secondStoreAppendInvoked.await();
// Verify that the next store append invoked.
verify(store).append(streamSegmentName, data, updateEventNumber(clientId, 200, 100, eventCount), AppendProcessor.TIMEOUT);
// Verify two DataAppended acks are sent out.
verify(connection, times(2)).send(any(DataAppended.class));
verify(connection).send(new DataAppended(clientId, 100, Long.MIN_VALUE));
verify(connection).send(new DataAppended(clientId, 200, 100));
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class AppendTest method testSetupOnNonExistentSegment.
@Test
public void testSetupOnNonExistentSegment() throws Exception {
String segment = "123";
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
UUID uuid = UUID.randomUUID();
NoSuchSegment setup = (NoSuchSegment) sendRequest(channel, new SetupAppend(1, uuid, segment, ""));
assertEquals(segment, setup.getSegment());
}
Aggregations