use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class SegmentOutputStreamTest method testReconnectSendsSetupAppendOnTokenExpiration.
@Test(timeout = 10000)
public void testReconnectSendsSetupAppendOnTokenExpiration() throws ConnectionFailedException, SegmentSealedException {
UUID writerId = UUID.randomUUID();
PravegaNodeUri segmentStoreUri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl mockConnectionFactory = spy(new MockConnectionFactoryImpl());
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
// Ensure task submitted to executor is run inline.
implementAsDirectExecutor(executor);
mockConnectionFactory.setExecutor(executor);
MockController controller = new MockController(segmentStoreUri.getEndpoint(), segmentStoreUri.getPort(), mockConnectionFactory, true);
ClientConnection mockConnection = mock(ClientConnection.class);
mockConnectionFactory.provideConnection(segmentStoreUri, mockConnection);
@Cleanup SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, mockConnectionFactory, writerId, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken());
output.reconnect();
verify(mockConnection).send(new SetupAppend(output.getRequestId(), writerId, SEGMENT, ""));
reset(mockConnection);
// Simulate token expiry
WireCommands.AuthTokenCheckFailed authTokenCheckFailed = new WireCommands.AuthTokenCheckFailed(1, "server-stacktrace", WireCommands.AuthTokenCheckFailed.ErrorCode.TOKEN_EXPIRED);
mockConnectionFactory.getProcessor(segmentStoreUri).authTokenCheckFailed(authTokenCheckFailed);
// Upon token expiry we expect that the SetupAppend will occur again.
verify(mockConnection).send(new SetupAppend(output.getRequestId(), writerId, SEGMENT, ""));
}
use of io.pravega.client.connection.impl.ClientConnection in project pravega by pravega.
the class SegmentOutputStreamTest method testReconnectWorksWithTokenTaskInInternalExecutor.
@Test(timeout = 10000)
public void testReconnectWorksWithTokenTaskInInternalExecutor() throws SegmentSealedException {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
@Cleanup("shutdownNow") val executor = ExecutorServiceHelpers.newScheduledThreadPool(1, "test");
@Cleanup MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
// create one thread on connection factory
cf.setExecutor(executor);
CompletableFuture<Void> signal = new CompletableFuture<>();
MockControllerWithTokenTask controller = spy(new MockControllerWithTokenTask(uri.getEndpoint(), uri.getPort(), cf, true, signal));
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
@Cleanup SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.create(controller, "scope", "stream", AccessOperation.ANY));
output.reconnect();
signal.join();
verify(controller, times(1)).getOrRefreshDelegationTokenFor("scope", "stream", AccessOperation.ANY);
}
use of io.pravega.client.connection.impl.ClientConnection 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.client.connection.impl.ClientConnection 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.client.connection.impl.ClientConnection 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);
}
Aggregations