use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class LargeEventWriterTest method testEventStreamWriter.
@Test(timeout = 5000)
public void testEventStreamWriter() throws ConnectionFailedException, SegmentSealedException {
String scope = "scope";
String streamName = "stream";
StreamImpl stream = new StreamImpl(scope, streamName);
Segment segment = new Segment(scope, streamName, 0);
@Cleanup InlineExecutor executor = new InlineExecutor();
EventWriterConfig config = EventWriterConfig.builder().enableLargeEvents(true).build();
SegmentOutputStreamFactory streamFactory = Mockito.mock(SegmentOutputStreamFactory.class);
MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
MockController controller = new MockController("localhost", 0, connectionFactory, false);
controller.createScope(scope).join();
controller.createStream(scope, streamName, StreamConfiguration.builder().build());
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
ClientConnection connection = Mockito.mock(ClientConnection.class);
connectionFactory.provideConnection(location, connection);
SegmentOutputStream outputStream = Mockito.mock(SegmentOutputStream.class);
Mockito.when(streamFactory.createOutputStreamForSegment(eq(segment), any(), any(), any())).thenReturn(outputStream);
answerRequest(connectionFactory, connection, location, CreateTransientSegment.class, r -> new SegmentCreated(r.getRequestId(), "transient-segment"));
answerRequest(connectionFactory, connection, location, SetupAppend.class, r -> new AppendSetup(r.getRequestId(), segment.getScopedName(), r.getWriterId(), WireCommands.NULL_ATTRIBUTE_VALUE));
answerRequest(connectionFactory, connection, location, ConditionalBlockEnd.class, r -> {
ByteBuf data = r.getData();
return new DataAppended(r.getRequestId(), r.getWriterId(), r.getEventNumber(), r.getEventNumber() - 1, r.getExpectedOffset() + data.readableBytes());
});
answerRequest(connectionFactory, connection, location, MergeSegments.class, r -> {
return new SegmentsMerged(r.getRequestId(), r.getSource(), r.getTarget(), -1);
});
@Cleanup EventStreamWriter<byte[]> writer = new EventStreamWriterImpl<>(stream, "id", controller, streamFactory, new ByteArraySerializer(), config, executor, executor, connectionFactory);
writer.writeEvent(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 });
writer.writeEvent(new byte[Serializer.MAX_EVENT_SIZE * 2]);
InOrder order = Mockito.inOrder(connection, outputStream);
order.verify(outputStream).write(any(PendingEvent.class));
order.verify(outputStream).flush();
order.verify(connection).send(any(CreateTransientSegment.class));
order.verify(connection).send(any(SetupAppend.class));
order.verify(connection, times(3)).send(any(ConditionalBlockEnd.class));
order.verify(connection).send(any(MergeSegments.class));
order.verify(connection).close();
order.verifyNoMoreInteractions();
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class AppendTest method sendLargeAppend.
@Test(timeout = 10000)
public void sendLargeAppend() throws Exception {
String segment = "sendLargeAppend";
ByteBuf data = Unpooled.wrappedBuffer(new byte[Serializer.MAX_EVENT_SIZE]);
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, "", 1024L));
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());
DataAppended ack = (DataAppended) sendRequest(channel, new Append(segment, uuid, data.readableBytes(), new Event(data), 1L));
assertEquals(uuid, ack.getWriterId());
assertEquals(data.readableBytes(), ack.getEventNumber());
assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class AppendTest method testMultipleAppends.
@Test(timeout = 10000)
public void testMultipleAppends() throws Exception {
String segment = "testMultipleAppends";
ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
StreamSegmentStore store = SERVICE_BUILDER.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, "", 1024L));
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, new Event(data), 1L));
assertEquals(uuid, ack.getWriterId());
assertEquals(1, ack.getEventNumber());
assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, new Event(data), 1L));
assertEquals(uuid, ack2.getWriterId());
assertEquals(2, ack2.getEventNumber());
assertEquals(1, ack2.getPreviousEventNumber());
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class AppendProcessorTest method testTransactionAppend.
@Test
public void testTransactionAppend() {
String streamSegmentName = "scope/stream/transactionSegment#transaction.01234567890123456789012345678901";
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);
val mockedRecorder = Mockito.mock(SegmentStatsRecorder.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).statsRecorder(mockedRecorder).build();
setupGetAttributes(streamSegmentName, clientId, store);
val ac = interceptAppend(store, streamSegmentName, updateEventNumber(clientId, data.length), CompletableFuture.completedFuture(21L));
processor.setupAppend(new SetupAppend(requestId, 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(requestId, streamSegmentName, clientId, 0));
verify(tracker).updateOutstandingBytes(connection, data.length, data.length);
verify(connection).send(new DataAppended(requestId, clientId, data.length, 0L, 21L));
verify(tracker).updateOutstandingBytes(connection, -data.length, 0);
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
verify(mockedRecorder).recordAppend(eq(streamSegmentName), eq(8L), eq(1), any());
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class AppendProcessorTest method testAppend.
@Test
public void testAppend() {
String streamSegmentName = "scope/stream/0.#epoch.0";
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);
val mockedRecorder = Mockito.mock(SegmentStatsRecorder.class);
@Cleanup AppendProcessor processor = AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(connection, tracker)).statsRecorder(mockedRecorder).build();
setupGetAttributes(streamSegmentName, clientId, store);
val ac = interceptAppend(store, streamSegmentName, updateEventNumber(clientId, data.length), CompletableFuture.completedFuture((long) data.length));
SetupAppend setupAppendCommand = new SetupAppend(1, clientId, streamSegmentName, "");
processor.setupAppend(setupAppendCommand);
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 DataAppended(requestId, clientId, data.length, 0L, data.length));
verify(tracker).updateOutstandingBytes(connection, -data.length, 0);
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
verify(mockedRecorder).recordAppend(eq(streamSegmentName), eq(8L), eq(1), any());
assertTrue(processor.isSetupAppendCompleted(setupAppendCommand.getSegment(), setupAppendCommand.getWriterId()));
}
Aggregations