use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class SegmentOutputStreamTest method testConnectAndFailedSetupAppend.
@Test(timeout = 10000)
public void testConnectAndFailedSetupAppend() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
// Ensure task submitted to executor is run inline.
implementAsDirectExecutor(executor);
cf.setExecutor(executor);
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
ClientConnection connection = mock(ClientConnection.class);
doThrow(ConnectionFailedException.class).doNothing().when(connection).send(any(SetupAppend.class));
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
output.reconnect();
verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
verify(connection).send(new SetupAppend(2, cid, SEGMENT, ""));
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class AppendProcessorTest method testAppend.
@Test
public void testAppend() {
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 = CompletableFuture.completedFuture(null);
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 DataAppended(clientId, data.length, 0L));
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class AppendProcessorTest method testSwitchingStream.
@Test
public void testSwitchingStream() {
String segment1 = "segment1";
String segment2 = "segment2";
UUID clientId1 = UUID.randomUUID();
UUID clientId2 = 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(segment1, clientId1, store);
CompletableFuture<Void> result = CompletableFuture.completedFuture(null);
when(store.append(segment1, data, updateEventNumber(clientId1, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
setupGetStreamSegmentInfo(segment2, clientId2, store);
result = CompletableFuture.completedFuture(null);
when(store.append(segment2, data, updateEventNumber(clientId2, data.length), AppendProcessor.TIMEOUT)).thenReturn(result);
processor.setupAppend(new SetupAppend(1, clientId1, segment1, ""));
processor.append(new Append(segment1, clientId1, data.length, Unpooled.wrappedBuffer(data), null));
processor.setupAppend(new SetupAppend(2, clientId2, segment2, ""));
processor.append(new Append(segment2, clientId2, data.length, Unpooled.wrappedBuffer(data), null));
verify(store).getStreamSegmentInfo(eq(segment1), eq(true), eq(AppendProcessor.TIMEOUT));
verify(store).append(segment1, data, updateEventNumber(clientId1, data.length), AppendProcessor.TIMEOUT);
verify(store).getStreamSegmentInfo(eq(segment2), eq(true), eq(AppendProcessor.TIMEOUT));
verify(store).append(segment2, data, updateEventNumber(clientId2, data.length), AppendProcessor.TIMEOUT);
verify(connection, atLeast(0)).resumeReading();
verify(connection).send(new AppendSetup(1, segment1, clientId1, 0));
verify(connection).send(new DataAppended(clientId1, data.length, 0));
verify(connection).send(new AppendSetup(2, segment2, clientId2, 0));
verify(connection).send(new DataAppended(clientId2, data.length, 0));
verifyNoMoreInteractions(connection);
verifyNoMoreInteractions(store);
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class AppendTest method testMultipleAppends.
@Test(timeout = 10000)
public void testMultipleAppends() throws Exception {
String segment = "123";
ByteBuf data = Unpooled.wrappedBuffer("Hello world\n".getBytes());
StreamSegmentStore store = this.serviceBuilder.createStreamSegmentService();
@Cleanup EmbeddedChannel channel = createChannel(store);
SegmentCreated created = (SegmentCreated) sendRequest(channel, new CreateSegment(1, segment, CreateSegment.NO_SCALE, 0, ""));
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, data, null));
assertEquals(uuid, ack.getWriterId());
assertEquals(1, ack.getEventNumber());
assertEquals(Long.MIN_VALUE, ack.getPreviousEventNumber());
DataAppended ack2 = (DataAppended) sendRequest(channel, new Append(segment, uuid, 2, data, null));
assertEquals(uuid, ack2.getWriterId());
assertEquals(2, ack2.getEventNumber());
assertEquals(1, ack2.getPreviousEventNumber());
}
use of io.pravega.shared.protocol.netty.WireCommands.SetupAppend in project pravega by pravega.
the class AppendEncodeDecodeTest method setupAppend.
private ArrayList<Object> setupAppend(String testStream, UUID writerId, ByteBuf fakeNetwork) throws Exception {
SetupAppend setupAppend = new SetupAppend(1, writerId, testStream, "");
encoder.encode(null, setupAppend, fakeNetwork);
ArrayList<Object> received = new ArrayList<>();
WireCommand command = CommandDecoder.parseCommand(fakeNetwork);
assertTrue(appendDecoder.acceptInboundMessage(command));
assertEquals(setupAppend, appendDecoder.processCommand(command));
return received;
}
Aggregations