use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class SegmentOutputStreamTest method testFailOnClose.
/**
* Verifies that if a exception is encountered while flushing data inside of close, the
* connection is reestablished and the data is retransmitted before close returns.
*/
@Test
public void testFailOnClose() throws ConnectionFailedException {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
InOrder inOrder = Mockito.inOrder(connection);
inOrder.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
// Prep mock: the mockito doAnswers setup below are triggered during the close inside of the testBlocking() call.
CompletableFuture<Void> acked = new CompletableFuture<>();
Append append = new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
cf.getProcessor(uri).connectionDropped();
throw new ConnectionFailedException();
}
}).doNothing().when(connection).send(new WireCommands.KeepAlive());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
CompletedCallback callback = (CompletedCallback) invocation.getArgument(1);
callback.complete(null);
return null;
}
}).when(connection).sendAsync(Mockito.eq(Collections.singletonList(append)), Mockito.any());
// Queue up event.
output.write(PendingEvent.withoutHeader(null, data, acked));
inOrder.verify(connection).send(append);
// Verify behavior
AssertExtensions.assertBlocks(() -> {
output.close();
}, () -> {
// close is unblocked once the connection is setup and data is appended on Segment store.
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(output.getRequestId(), cid, 1, 0, -1));
});
// Verify the order of WireCommands sent.
inOrder.verify(connection).send(new WireCommands.KeepAlive());
// Two SetupAppend WireCommands are sent since the connection is dropped right after the first KeepAlive WireCommand is sent.
// The second SetupAppend WireCommand is sent while trying to re-establish connection.
inOrder.verify(connection, times(2)).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
// Ensure the pending append is sent over the connection. The exact verification of the append data is performed while setting up
// the when clause of setting up append.
inOrder.verify(connection).sendAsync(Mockito.anyList(), Mockito.any());
inOrder.verify(connection).close();
assertEquals(true, acked.isDone());
inOrder.verifyNoMoreInteractions();
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class SegmentOutputStreamTest method testSealedBeforeFlush.
@Test(timeout = 10000)
public void testSealedBeforeFlush() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
InOrder order = Mockito.inOrder(connection);
@SuppressWarnings("resource") SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
CompletableFuture<Void> ack = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, ack));
order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId()));
assertEquals(false, ack.isDone());
cf.getProcessor(uri).segmentIsSealed(new WireCommands.SegmentIsSealed(output.getRequestId(), SEGMENT, "SomeException", 1));
// this is invoked by the segmentSealedCallback.
output.getUnackedEventsOnSeal();
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush());
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class SegmentOutputStreamTest method testConnectAndSendWithoutConnectionPooling.
@Test(timeout = 10000)
public void testConnectAndSendWithoutConnectionPooling() throws ConnectionFailedException {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, false, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
sendAndVerifyEvent(cid, connection, output, getBuffer("test"), 1);
verifyNoMoreInteractions(connection);
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class SegmentOutputStreamTest method testConditionalSend.
@Test(timeout = 10000)
public void testConditionalSend() throws ConnectionFailedException {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
sendAndVerifyEvent(cid, connection, output, getBuffer("test"), 1);
verifyNoMoreInteractions(connection);
}
use of io.pravega.shared.protocol.netty.WireCommands.AppendSetup in project pravega by pravega.
the class SegmentOutputStreamTest method testFlushDuringTransactionAbort.
@Test(timeout = 10000)
public void testFlushDuringTransactionAbort() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
cf.setExecutor(executorService());
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
InOrder order = Mockito.inOrder(connection);
@SuppressWarnings("resource") SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(TXN_SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, TXN_SEGMENT, ""));
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), TXN_SEGMENT, cid, 0));
ByteBuffer data = getBuffer("test");
// Write an Event.
CompletableFuture<Void> ack = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, ack));
order.verify(connection).send(new Append(TXN_SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId()));
// writer is not complete until a response from Segment Store is received.
assertFalse(ack.isDone());
// Validate that flush() is blocking until there is a response from Segment Store.
AssertExtensions.assertBlocks(() -> {
// A flush() should throw a SegmentSealedException.
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush());
}, () -> {
// Simulate a NoSuchSegment response from SegmentStore due to a Transaction abort.
cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(output.getRequestId(), TXN_SEGMENT, "SomeException", -1L));
});
AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush());
}
Aggregations