use of io.pravega.client.connection.impl.ClientConnection 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, true);
ClientConnection connection = mock(ClientConnection.class);
doThrow(ConnectionFailedException.class).doNothing().when(connection).send(any(SetupAppend.class));
cf.provideConnection(uri, connection);
@Cleanup SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
verify(connection, times(2)).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, ""));
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class ConditionalOutputStreamTest method testRetriesOnTokenExpiry.
@SneakyThrows
@Test(timeout = 10000)
public void testRetriesOnTokenExpiry() {
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController("localhost", 0, connectionFactory, true);
ConditionalOutputStreamFactory factory = new ConditionalOutputStreamFactoryImpl(controller, connectionFactory);
Segment segment = new Segment("scope", "testWrite", 1);
@Cleanup ConditionalOutputStream objectUnderTest = factory.createConditionalOutputStream(segment, DelegationTokenProviderFactory.create("token", controller, segment, AccessOperation.ANY), EventWriterConfig.builder().build());
ByteBuffer data = ByteBuffer.allocate(10);
ClientConnection clientConnection = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
connectionFactory.provideConnection(location, clientConnection);
setupAppend(connectionFactory, segment, clientConnection, location);
final AtomicLong retryCounter = new AtomicLong(0);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
ConditionalAppend argument = (ConditionalAppend) invocation.getArgument(0);
ReplyProcessor processor = connectionFactory.getProcessor(location);
if (retryCounter.getAndIncrement() < 2) {
processor.process(new WireCommands.AuthTokenCheckFailed(argument.getRequestId(), "SomeException", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_EXPIRED));
} else {
processor.process(new WireCommands.DataAppended(argument.getRequestId(), argument.getWriterId(), argument.getEventNumber(), 0, -1));
}
return null;
}
}).when(clientConnection).send(any(ConditionalAppend.class));
assertTrue(objectUnderTest.write(data, 0));
assertEquals(3, retryCounter.get());
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class ConditionalOutputStreamTest method testWrite.
@Test(timeout = 10000)
public void testWrite() throws ConnectionFailedException, SegmentSealedException {
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController("localhost", 0, connectionFactory, true);
ConditionalOutputStreamFactory factory = new ConditionalOutputStreamFactoryImpl(controller, connectionFactory);
Segment segment = new Segment("scope", "testWrite", 1);
@Cleanup ConditionalOutputStream cOut = factory.createConditionalOutputStream(segment, DelegationTokenProviderFactory.create("token", controller, segment, AccessOperation.ANY), EventWriterConfig.builder().build());
ByteBuffer data = ByteBuffer.allocate(10);
ClientConnection mock = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
connectionFactory.provideConnection(location, mock);
setupAppend(connectionFactory, segment, mock, location);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
ConditionalAppend argument = (ConditionalAppend) invocation.getArgument(0);
ReplyProcessor processor = connectionFactory.getProcessor(location);
if (argument.getExpectedOffset() == 0 || argument.getExpectedOffset() == 2) {
processor.process(new WireCommands.DataAppended(argument.getRequestId(), argument.getWriterId(), argument.getEventNumber(), 0, -1));
} else {
processor.process(new WireCommands.ConditionalCheckFailed(argument.getWriterId(), argument.getEventNumber(), argument.getRequestId()));
}
return null;
}
}).when(mock).send(any(ConditionalAppend.class));
assertTrue(cOut.write(data, 0));
assertFalse(cOut.write(data, 1));
assertTrue(cOut.write(data, 2));
assertFalse(cOut.write(data, 3));
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class ConditionalOutputStreamTest method testNonExpiryTokenCheckFailure.
@Test(timeout = 10000)
public void testNonExpiryTokenCheckFailure() throws ConnectionFailedException {
@Cleanup MockConnectionFactoryImpl connectionFactory = new MockConnectionFactoryImpl();
@Cleanup MockController controller = new MockController("localhost", 0, connectionFactory, true);
ConditionalOutputStreamFactory factory = new ConditionalOutputStreamFactoryImpl(controller, connectionFactory);
Segment segment = new Segment("scope", "testWrite", 1);
@Cleanup ConditionalOutputStream objectUnderTest = factory.createConditionalOutputStream(segment, DelegationTokenProviderFactory.create("token", controller, segment, AccessOperation.ANY), EventWriterConfig.builder().build());
ByteBuffer data = ByteBuffer.allocate(10);
ClientConnection clientConnection = Mockito.mock(ClientConnection.class);
PravegaNodeUri location = new PravegaNodeUri("localhost", 0);
connectionFactory.provideConnection(location, clientConnection);
setupAppend(connectionFactory, segment, clientConnection, location);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
ConditionalAppend argument = (ConditionalAppend) invocation.getArgument(0);
ReplyProcessor processor = connectionFactory.getProcessor(location);
processor.process(new WireCommands.AuthTokenCheckFailed(argument.getRequestId(), "SomeException", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_CHECK_FAILED));
return null;
}
}).when(clientConnection).send(any(ConditionalAppend.class));
AssertExtensions.assertThrows(AuthenticationException.class, () -> objectUnderTest.write(data, 0));
}
use of io.pravega.client.connection.impl.ClientConnection 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));
}
Aggregations