use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class SegmentMetadataClientTest method testTokenCheckFailure.
@Test(timeout = 10000)
public void testTokenCheckFailure() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf, true);
@Cleanup ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(endpoint, connection);
@Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
client.getConnection();
ReplyProcessor processor = cf.getProcessor(endpoint);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.GetStreamSegmentInfo getStreamInfo = invocation.getArgument(0);
processor.process(new WireCommands.AuthTokenCheckFailed(getStreamInfo.getRequestId(), "server-stacktrace", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED));
return null;
}
}).when(connection).send(any(WireCommands.GetStreamSegmentInfo.class));
AssertExtensions.assertThrows("TokenException was not thrown or server stacktrace contained unexpected content.", () -> client.fetchCurrentSegmentLength().join(), e -> e instanceof InvalidTokenException && e.getMessage().contains("serverStackTrace=server-stacktrace"));
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class SegmentMetadataClientTest method testTruncateNoSuchSegmentError.
@Test(timeout = 10000)
public void testTruncateNoSuchSegmentError() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testTruncate", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf, true);
@Cleanup ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(endpoint, connection);
@Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
client.getConnection();
ReplyProcessor processor = cf.getProcessor(endpoint);
AtomicLong requestId = new AtomicLong();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.TruncateSegment truncateSegment = invocation.getArgument(0);
processor.process(new WireCommands.NoSuchSegment(truncateSegment.getRequestId(), segment.getScopedName(), "", 123L));
requestId.set(truncateSegment.getRequestId());
return null;
}
}).when(connection).send(any(WireCommands.TruncateSegment.class));
AssertExtensions.assertThrows(NoSuchSegmentException.class, () -> client.truncateSegment(123L).join());
Mockito.verify(connection).send(Mockito.eq(new WireCommands.TruncateSegment(requestId.get(), segment.getScopedName(), 123L, "")));
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class SegmentMetadataClientTest method testSeal.
@Test(timeout = 10000)
public void testSeal() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testSeal", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf, true);
@Cleanup ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(endpoint, connection);
@Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
client.getConnection();
ReplyProcessor processor = cf.getProcessor(endpoint);
AtomicLong requestId = new AtomicLong();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.SealSegment sealSegment = invocation.getArgument(0);
processor.process(new WireCommands.SegmentSealed(sealSegment.getRequestId(), segment.getScopedName()));
requestId.set(sealSegment.getRequestId());
return null;
}
}).when(connection).send(any(WireCommands.SealSegment.class));
client.sealSegment().join();
Mockito.verify(connection).send(Mockito.eq(new WireCommands.SealSegment(requestId.get(), segment.getScopedName(), "")));
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class SegmentMetadataClientTest method testCurrentStreamLength.
@Test(timeout = 10000)
public void testCurrentStreamLength() throws ConnectionFailedException {
Segment segment = new Segment("scope", "testRetry", 4);
PravegaNodeUri endpoint = new PravegaNodeUri("localhost", 0);
@Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController(endpoint.getEndpoint(), endpoint.getPort(), cf, true);
@Cleanup ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(endpoint, connection);
@Cleanup SegmentMetadataClientImpl client = new SegmentMetadataClientImpl(segment, controller, cf, "");
client.getConnection();
ReplyProcessor processor = cf.getProcessor(endpoint);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
WireCommands.GetStreamSegmentInfo getStreamInfo = invocation.getArgument(0);
processor.process(new StreamSegmentInfo(getStreamInfo.getRequestId(), segment.getScopedName(), true, false, false, 0, 123, 121));
return null;
}
}).when(connection).send(any(WireCommands.GetStreamSegmentInfo.class));
long head = client.fetchCurrentSegmentHeadOffset().join();
long length = client.fetchCurrentSegmentLength().join();
assertEquals(121, head);
assertEquals(123, length);
}
use of io.pravega.client.connection.impl.ClientConnection 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);
}
}
Aggregations