use of io.pravega.common.util.Retry.RetryWithBackoff in project pravega by pravega.
the class SegmentOutputStreamTest method testConnectWithMultipleFailures.
@Test(timeout = 10000)
public void testConnectWithMultipleFailures() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
RetryWithBackoff retryConfig = Retry.withExpBackoff(1, 1, 4);
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, true);
ClientConnection connection = mock(ClientConnection.class);
InOrder verify = inOrder(connection);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, retryConfig, DelegationTokenProviderFactory.createWithEmptyToken());
try {
output.reconnect();
verify.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
// simulate a processing Failure and ensure SetupAppend is executed.
ReplyProcessor processor = cf.getProcessor(uri);
processor.processingFailure(new IOException());
verify.verify(connection).close();
verify.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
verifyNoMoreInteractions(connection);
processor.connectionDropped();
verify.verify(connection).close();
verify.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
processor.wrongHost(new WireCommands.WrongHost(output.getRequestId(), SEGMENT, "newHost", "SomeException"));
verify.verify(connection).close();
verify.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
verifyNoMoreInteractions(connection);
processor.processingFailure(new IOException());
assertTrue("Connection is exceptionally closed with RetriesExhaustedException", output.getConnection().isCompletedExceptionally());
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> Futures.getThrowingException(output.getConnection()));
verify.verify(connection).close();
verifyNoMoreInteractions(connection);
} finally {
// Verify that a close on the SegmentOutputStream does throw a RetriesExhaustedException.
AssertExtensions.assertThrows(RetriesExhaustedException.class, output::close);
}
}
use of io.pravega.common.util.Retry.RetryWithBackoff in project pravega by pravega.
the class SegmentOutputStreamTest method testFlushWithMultipleConnectFailures.
@Test(timeout = 10000)
public void testFlushWithMultipleConnectFailures() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
RetryWithBackoff retryConfig = Retry.withExpBackoff(1, 1, 1);
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, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, retryConfig, DelegationTokenProviderFactory.createWithEmptyToken());
try {
output.reconnect();
verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
// Simulate a successful connection setup.
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
// try sending an event.
byte[] eventData = "test data".getBytes();
CompletableFuture<Void> acked = new CompletableFuture<>();
// this is an inflight event and the client will track it until there is a response from SSS.
output.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(eventData), acked));
verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(eventData), null, output.getRequestId()));
reset(connection);
// simulate a connection drop and verify if the writer tries to establish a new connection.
cf.getProcessor(uri).connectionDropped();
verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
reset(connection);
// Verify flush blocks until there is a response from SSS. Incase of connection error the client retries. If the
// retry count more than the configuration ensure flush returns exceptionally.
AssertExtensions.assertBlocks(() -> AssertExtensions.assertThrows(RetriesExhaustedException.class, output::flush), () -> cf.getProcessor(uri).connectionDropped());
assertTrue("Connection is exceptionally closed with RetriesExhaustedException", output.getConnection().isCompletedExceptionally());
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> Futures.getThrowingException(output.getConnection()));
// Verify that the inflight event future is completed exceptionally.
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> Futures.getThrowingException(acked));
} finally {
// Verify that a close on the SegmentOutputStream does throw a RetriesExhaustedException.
AssertExtensions.assertThrows(RetriesExhaustedException.class, output::close);
}
}
use of io.pravega.common.util.Retry.RetryWithBackoff in project pravega by pravega.
the class SegmentOutputStreamTest method testInflightWithMultipleConnectFailures.
@Test(timeout = 10000)
public void testInflightWithMultipleConnectFailures() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
RetryWithBackoff retryConfig = Retry.withExpBackoff(1, 1, 1);
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, true);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, retryConfig, DelegationTokenProviderFactory.createWithEmptyToken());
try {
output.reconnect();
verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
// Simulate a successful connection setup.
cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), SEGMENT, cid, 0));
// try sending an event.
byte[] eventData = "test data".getBytes();
CompletableFuture<Void> ack1 = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(eventData), ack1));
verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(eventData), null, output.getRequestId()));
reset(connection);
// simulate a connection drop and verify if the writer tries to establish a new connection.
cf.getProcessor(uri).connectionDropped();
verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
reset(connection);
// Simulate a connection drop again.
cf.getProcessor(uri).connectionDropped();
// Since we have exceeded the retry attempts verify we do not try to establish a connection.
verify(connection, never()).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
assertTrue("Connection is exceptionally closed with RetriesExhaustedException", output.getConnection().isCompletedExceptionally());
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> Futures.getThrowingException(output.getConnection()));
// Verify that the inflight event future is completed exceptionally.
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> Futures.getThrowingException(ack1));
// Write an additional event to a writer that has failed with RetriesExhaustedException.
CompletableFuture<Void> ack2 = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, ByteBuffer.wrap(eventData), ack2));
verify(connection, never()).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
AssertExtensions.assertThrows(RetriesExhaustedException.class, () -> Futures.getThrowingException(ack2));
// Verify that a flush on the SegmentOutputStream does throw a RetriesExhaustedException.
AssertExtensions.assertThrows(RetriesExhaustedException.class, output::flush);
} finally {
// Verify that a close on the SegmentOutputStream does throw a RetriesExhaustedException.
AssertExtensions.assertThrows(RetriesExhaustedException.class, output::close);
}
}
Aggregations