use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class AppendProcessorTest method testConditionalAppendSuccess.
@Test
public void testConditionalAppendSuccess() {
String streamSegmentName = "scope/stream/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);
val mockedRecorder = Mockito.mock(SegmentStatsRecorder.class);
ConnectionTracker tracker = mock(ConnectionTracker.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).statsRecorder(mockedRecorder).build();
setupGetAttributes(streamSegmentName, clientId, store);
val ac1 = interceptAppend(store, streamSegmentName, updateEventNumber(clientId, 1), CompletableFuture.completedFuture((long) data.length));
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
processor.append(new Append(streamSegmentName, clientId, 1, 1, Unpooled.wrappedBuffer(data), null, requestId));
val ac2 = interceptAppend(store, streamSegmentName, data.length, updateEventNumber(clientId, 2, 1, 1), CompletableFuture.completedFuture(Long.valueOf(2 * data.length)));
processor.append(new Append(streamSegmentName, clientId, 2, 1, Unpooled.wrappedBuffer(data), (long) data.length, requestId));
verify(store).getAttributes(anyString(), eq(Collections.singleton(AttributeId.fromUUID(clientId))), eq(true), eq(AppendProcessor.TIMEOUT));
verifyStoreAppend(ac1, data);
verifyStoreAppend(ac2, data);
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
verify(tracker, times(2)).updateOutstandingBytes(connection, data.length, data.length);
verify(connection).send(new DataAppended(requestId, clientId, 1, 0, data.length));
verify(connection).send(new DataAppended(requestId, clientId, 2, 1, 2 * data.length));
verify(tracker, times(2)).updateOutstandingBytes(connection, -data.length, 0);
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
verify(mockedRecorder, times(2)).recordAppend(eq(streamSegmentName), eq(8L), eq(1), any());
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class AppendProcessorTest method testAppendPipelining.
/**
* Verifies that appends are "pipelined" into the underlying store and that acks are sent as appropriate via the
* connection when they complete.
*/
@Test(timeout = 15 * 1000)
public void testAppendPipelining() {
String streamSegmentName = "scope/stream/testAppendSegment";
UUID clientId = UUID.randomUUID();
byte[] data1 = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
byte[] data2 = new byte[] { 1, 2, 3, 4, 5 };
StreamSegmentStore store = mock(StreamSegmentStore.class);
ServerConnection connection = mock(ServerConnection.class);
ConnectionTracker tracker = mock(ConnectionTracker.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).build();
setupGetAttributes(streamSegmentName, clientId, store);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
verify(store).getAttributes(anyString(), eq(Collections.singleton(AttributeId.fromUUID(clientId))), eq(true), eq(AppendProcessor.TIMEOUT));
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
// Initiate two appends in short sequence, and simulate the Store blocking on both of them.
val store1 = new CompletableFuture<Long>();
val ac1 = interceptAppend(store, streamSegmentName, updateEventNumber(clientId, 1, 0, 1), store1);
processor.append(new Append(streamSegmentName, clientId, 1, 1, Unpooled.wrappedBuffer(data1), null, requestId));
val store2 = new CompletableFuture<Long>();
val ac2 = interceptAppend(store, streamSegmentName, updateEventNumber(clientId, 2, 1, 1), store2);
processor.append(new Append(streamSegmentName, clientId, 2, 1, Unpooled.wrappedBuffer(data2), null, requestId));
verifyStoreAppend(ac1, data1);
verifyStoreAppend(ac2, data2);
verify(tracker).updateOutstandingBytes(connection, data1.length, data1.length);
verify(tracker).updateOutstandingBytes(connection, data2.length, data1.length + data2.length);
// Complete the second one (this simulates acks arriving out of order from the store).
store2.complete(100L);
// Verify an ack is sent for both appends (because of pipelining guarantees), but only the second append's length
// is subtracted from the outstanding bytes.
verify(connection).send(new DataAppended(requestId, clientId, 2, 0L, 100L));
verify(tracker).updateOutstandingBytes(connection, -data2.length, data1.length);
verifyNoMoreInteractions(connection);
// Complete the first one, and verify that no additional acks are sent via the connection, but the first append's
// length is subtracted from the outstanding bytes.
store1.complete(50L);
verify(tracker).updateOutstandingBytes(connection, -data1.length, 0);
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class AppendProcessorTest method testSwitchingSegment.
@Test
public void testSwitchingSegment() {
String streamSegmentName1 = "scope/stream/testAppendSegment1";
String streamSegmentName2 = "scope/stream/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);
ConnectionTracker tracker = mock(ConnectionTracker.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).build();
setupGetAttributes(streamSegmentName1, clientId, store);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName1, ""));
verifier.verify(store).getAttributes(anyString(), eq(Collections.singleton(AttributeId.fromUUID(clientId))), eq(true), eq(AppendProcessor.TIMEOUT));
val ac1 = interceptAppend(store, streamSegmentName1, updateEventNumber(clientId, 10), CompletableFuture.completedFuture(1L));
processor.append(new Append(streamSegmentName1, clientId, 10, 1, Unpooled.wrappedBuffer(data), null, requestId));
verifyStoreAppend(verifier, ac1, data);
setupGetAttributes(streamSegmentName2, clientId, store);
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName2, ""));
verifier.verify(store).getAttributes(anyString(), eq(Collections.singleton(AttributeId.fromUUID(clientId))), eq(true), eq(AppendProcessor.TIMEOUT));
val ac2 = interceptAppend(store, streamSegmentName2, updateEventNumber(clientId, 2000), CompletableFuture.completedFuture(2L));
processor.append(new Append(streamSegmentName2, clientId, 2000, 1, Unpooled.wrappedBuffer(data), null, requestId));
verifyStoreAppend(verifier, ac2, data);
val ac3 = interceptAppend(store, streamSegmentName1, updateEventNumber(clientId, 20, 10, 1), CompletableFuture.completedFuture(3L));
processor.append(new Append(streamSegmentName1, clientId, 20, 1, Unpooled.wrappedBuffer(data), null, requestId));
verifyStoreAppend(verifier, ac3, data);
verifyNoMoreInteractions(store);
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class AppendProcessorTest method testMultipleSetupAppendDueToConnectionFailure.
@Test
public void testMultipleSetupAppendDueToConnectionFailure() {
String streamSegmentName = "scope/stream/testMultipleSetupAppend";
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);
val mockedRecorder = Mockito.mock(SegmentStatsRecorder.class);
ConnectionTracker tracker = mock(ConnectionTracker.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).statsRecorder(mockedRecorder).build();
// Setup mock to enusure both the SetupAppends return the newer values.
val clientIdAttribute = AttributeId.fromUUID(clientId);
when(store.getAttributes(streamSegmentName, Collections.singleton(clientIdAttribute), true, AppendProcessor.TIMEOUT)).thenReturn(CompletableFuture.completedFuture(Collections.singletonMap(clientIdAttribute, 0L))).thenReturn(CompletableFuture.completedFuture(Collections.singletonMap(clientIdAttribute, 1L)));
val ac1 = interceptAppend(store, streamSegmentName, 0, updateEventNumber(clientId, 1), CompletableFuture.completedFuture((long) data.length));
// First conditional Append.
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
processor.append(new Append(streamSegmentName, clientId, 1, 1, Unpooled.wrappedBuffer(data), 0L, 1L));
// Simulate a connection drop on the client side and the client resends a SetupAppend followed by conditional Append.
val ac2 = interceptAppend(store, streamSegmentName, data.length, updateEventNumber(clientId, 2, 1, 1), CompletableFuture.completedFuture((long) data.length * 2));
processor.setupAppend(new SetupAppend(2, clientId, streamSegmentName, ""));
processor.append(new Append(streamSegmentName, clientId, 2, 1, Unpooled.wrappedBuffer(data), (long) data.length, 2));
verify(store, times(2)).getAttributes(anyString(), eq(Collections.singleton(clientIdAttribute)), eq(true), eq(AppendProcessor.TIMEOUT));
verifyStoreAppend(ac1, data);
verifyStoreAppend(ac2, data);
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
verify(tracker, times(2)).updateOutstandingBytes(connection, data.length, data.length);
verify(connection).send(new DataAppended(1, clientId, 1, 0, data.length));
// verify that the second SetupAppend is responded by the AppendProcessor.
verify(connection).send(new AppendSetup(2, streamSegmentName, clientId, 1));
verify(connection).send(new DataAppended(2, clientId, 2, 1, data.length * 2));
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
verify(mockedRecorder, times(2)).recordAppend(eq(streamSegmentName), eq(8L), eq(1), any());
}
use of io.pravega.shared.protocol.netty.Append in project pravega by pravega.
the class AppendProcessorTest method testUnsupportedOperation.
@Test
public void testUnsupportedOperation() {
String streamSegmentName = "scope/stream/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);
ConnectionTracker tracker = mock(ConnectionTracker.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).build();
setupGetAttributes(streamSegmentName, clientId, store);
val ac = interceptAppend(store, streamSegmentName, updateEventNumber(clientId, data.length), Futures.failedFuture(new UnsupportedOperationException()));
processor.setupAppend(new SetupAppend(1, clientId, streamSegmentName, ""));
processor.append(new Append(streamSegmentName, clientId, data.length, 1, Unpooled.wrappedBuffer(data), null, requestId));
verify(store).getAttributes(anyString(), eq(Collections.singleton(AttributeId.fromUUID(clientId))), eq(true), eq(AppendProcessor.TIMEOUT));
verifyStoreAppend(ac, data);
verify(connection).send(new AppendSetup(1, streamSegmentName, clientId, 0));
verify(tracker).updateOutstandingBytes(connection, data.length, data.length);
verify(connection).send(new OperationUnsupported(requestId, "appending data", ""));
verify(tracker).updateOutstandingBytes(connection, -data.length, 0);
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
}
Aggregations