use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class SegmentOutputStreamTest method testClose.
@Test(timeout = 10000)
public void testClose() 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));
ByteBuffer data = getBuffer("test");
CompletableFuture<Void> acked = new CompletableFuture<>();
output.write(PendingEvent.withoutHeader(null, data, acked));
verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId()));
assertEquals(false, acked.isDone());
AssertExtensions.assertBlocks(() -> output.close(), () -> cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(output.getRequestId(), cid, 1, 0, -1)));
assertEquals(false, acked.isCompletedExceptionally());
assertEquals(true, acked.isDone());
verify(connection, Mockito.atMost(1)).send(new WireCommands.KeepAlive());
verify(connection).close();
verifyNoMoreInteractions(connection);
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class RevisionedStreamClientTest method testMark.
@Test
public void testMark() {
String scope = "scope";
String stream = "stream";
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, false);
createScopeAndStream(scope, stream, controller);
MockSegmentStreamFactory streamFactory = new MockSegmentStreamFactory();
@Cleanup SynchronizerClientFactory clientFactory = new ClientFactoryImpl(scope, controller, connectionFactory, streamFactory, streamFactory, streamFactory, streamFactory);
SynchronizerConfig config = SynchronizerConfig.builder().build();
@Cleanup RevisionedStreamClient<String> client = clientFactory.createRevisionedStreamClient(stream, new JavaSerializer<>(), config);
client.writeUnconditionally("a");
Revision ra = client.fetchLatestRevision();
client.writeUnconditionally("b");
Revision rb = client.fetchLatestRevision();
client.writeUnconditionally("c");
Revision rc = client.fetchLatestRevision();
assertTrue(client.compareAndSetMark(null, ra));
assertEquals(ra, client.getMark());
assertTrue(client.compareAndSetMark(ra, rb));
assertEquals(rb, client.getMark());
assertFalse(client.compareAndSetMark(ra, rc));
assertEquals(rb, client.getMark());
assertTrue(client.compareAndSetMark(rb, rc));
assertEquals(rc, client.getMark());
assertTrue(client.compareAndSetMark(rc, ra));
assertEquals(ra, client.getMark());
assertTrue(client.compareAndSetMark(ra, null));
assertEquals(null, client.getMark());
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testAuthenticationFailure.
@SneakyThrows
@Test(timeout = 10000)
public void testAuthenticationFailure() {
Segment segment = new Segment("scope", "testRead", 1);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
// Non-token expiry auth token check failure response from Segment store.
WireCommands.AuthTokenCheckFailed authTokenCheckFailed = new WireCommands.AuthTokenCheckFailed(in.getRequestId(), "SomeException", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED);
// Trigger read.
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
assertEquals(0, dataAvailable.availablePermits());
// verify that a response from Segment store completes the readFuture and the future completes with the specified exception.
AssertExtensions.assertBlocks(() -> assertThrows(AuthenticationException.class, () -> readFuture.get()), () -> {
ReplyProcessor processor = connectionFactory.getProcessor(endpoint);
processor.process(authTokenCheckFailed);
});
verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
// verify read future completedExceptionally
assertTrue(!Futures.isSuccessful(readFuture));
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testRetryWithConnectionFailures.
@Test(timeout = 10000)
public void testRetryWithConnectionFailures() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
ClientConnection c = mock(ClientConnection.class);
connectionFactory.provideConnection(endpoint, c);
MockConnectionFactoryImpl mockedCF = spy(connectionFactory);
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, mockedCF, segment, DelegationTokenProviderFactory.createWithEmptyToken(), dataAvailable);
InOrder inOrder = Mockito.inOrder(c);
// Failed Connection
CompletableFuture<ClientConnection> failedConnection = new CompletableFuture<>();
failedConnection.completeExceptionally(new ConnectionFailedException("Netty error while establishing connection"));
// Successful Connection
CompletableFuture<ClientConnection> successfulConnection = new CompletableFuture<>();
successfulConnection.complete(c);
WireCommands.SegmentRead segmentRead = new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, Unpooled.EMPTY_BUFFER, in.getRequestId());
// simulate a establishConnection failure to segment store.
Mockito.doReturn(failedConnection).doCallRealMethod().when(mockedCF).establishConnection(eq(endpoint), any(ReplyProcessor.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
// Simulate a connection failure post establishing connection to SegmentStore.
throw Exceptions.sneakyThrow(new ConnectionFailedException("SendAsync exception since netty channel is null"));
}
}).doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
mockedCF.getProcessor(endpoint).process(segmentRead);
return null;
}
}).when(c).send(any(ReadSegment.class));
assertEquals(0, dataAvailable.availablePermits());
// Read invocation.
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
// Verification.
assertEquals(segmentRead, readFuture.join());
// read completes after 3 retries.
assertTrue(Futures.isSuccessful(readFuture));
assertEquals(1, dataAvailable.availablePermits());
// Verify that the reader attempts to establish connection 3 times ( 2 failures followed by a successful attempt).
verify(mockedCF, times(3)).establishConnection(eq(endpoint), any(ReplyProcessor.class));
// The second time sendAsync is invoked but it fail due to the exception.
inOrder.verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
// Validate that the connection is closed in case of an error.
inOrder.verify(c).close();
// Validate that the read command is send again over the new connection.
inOrder.verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
// No more interactions since the SSS responds and the ReplyProcessor.segmentRead is invoked by netty.
verifyNoMoreInteractions(c);
}
use of io.pravega.shared.protocol.netty.PravegaNodeUri in project pravega by pravega.
the class AsyncSegmentInputStreamTest method testProcessingFailure.
@Test
public void testProcessingFailure() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", SERVICE_PORT);
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), connectionFactory, true);
DelegationTokenProvider tokenProvider = mock(DelegationTokenProvider.class);
// return empty token
when(tokenProvider.retrieveToken()).thenReturn(CompletableFuture.completedFuture(""));
Semaphore dataAvailable = new Semaphore(0);
@Cleanup AsyncSegmentInputStreamImpl in = new AsyncSegmentInputStreamImpl(controller, connectionFactory, segment, tokenProvider, dataAvailable);
ClientConnection c = mock(ClientConnection.class);
InOrder inOrder = Mockito.inOrder(c);
connectionFactory.provideConnection(endpoint, c);
WireCommands.SegmentRead segmentRead = new WireCommands.SegmentRead(segment.getScopedName(), 1234, false, false, Unpooled.EMPTY_BUFFER, in.getRequestId());
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
connectionFactory.getProcessor(endpoint).processingFailure(new ConnectionFailedException("Custom error"));
return null;
}
}).doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
connectionFactory.getProcessor(endpoint).process(segmentRead);
return null;
}
}).when(c).send(any(ReadSegment.class));
assertEquals(0, dataAvailable.availablePermits());
CompletableFuture<SegmentRead> readFuture = in.read(1234, 5678);
assertEquals(segmentRead, readFuture.join());
assertTrue(Futures.isSuccessful(readFuture));
assertEquals(1, dataAvailable.availablePermits());
inOrder.verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
inOrder.verify(c).close();
inOrder.verify(c).send(eq(new WireCommands.ReadSegment(segment.getScopedName(), 1234, 5678, "", in.getRequestId())));
verifyNoMoreInteractions(c);
// ensure retrieve Token is invoked for every retry.
verify(tokenProvider, times(2)).retrieveToken();
}
Aggregations