use of org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection in project flink by apache.
the class RegisteredRpcConnectionTest method testSuccessfulRpcConnection.
@Test
public void testSuccessfulRpcConnection() throws Exception {
final String testRpcConnectionEndpointAddress = "<TestRpcConnectionEndpointAddress>";
final UUID leaderId = UUID.randomUUID();
final String connectionID = "Test RPC Connection ID";
// an endpoint that immediately returns success
ManualResponseTestRegistrationGateway testGateway = new ManualResponseTestRegistrationGateway(new RetryingRegistrationTest.TestRegistrationSuccess(connectionID));
try {
rpcService.registerGateway(testRpcConnectionEndpointAddress, testGateway);
TestRpcConnection connection = new TestRpcConnection(testRpcConnectionEndpointAddress, leaderId, rpcService.getScheduledExecutor(), rpcService);
connection.start();
// wait for connection established
final Either<TestRegistrationSuccess, TestRegistrationRejection> connectionResult = connection.getConnectionFuture().get();
assertTrue(connectionResult.isLeft());
final String actualConnectionId = connectionResult.left().getCorrelationId();
// validate correct invocation and result
assertTrue(connection.isConnected());
assertEquals(testRpcConnectionEndpointAddress, connection.getTargetAddress());
assertEquals(leaderId, connection.getTargetLeaderId());
assertEquals(testGateway, connection.getTargetGateway());
assertEquals(connectionID, actualConnectionId);
} finally {
testGateway.stop();
}
}
use of org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection in project flink by apache.
the class RegisteredRpcConnectionTest method testReconnect.
@Test
public void testReconnect() throws Exception {
final String connectionId1 = "Test RPC Connection ID 1";
final String connectionId2 = "Test RPC Connection ID 2";
final String testRpcConnectionEndpointAddress = "<TestRpcConnectionEndpointAddress>";
final UUID leaderId = UUID.randomUUID();
final TestRegistrationGateway testGateway = new ManualResponseTestRegistrationGateway(new RetryingRegistrationTest.TestRegistrationSuccess(connectionId1), new RetryingRegistrationTest.TestRegistrationSuccess(connectionId2));
rpcService.registerGateway(testRpcConnectionEndpointAddress, testGateway);
TestRpcConnection connection = new TestRpcConnection(testRpcConnectionEndpointAddress, leaderId, rpcService.getScheduledExecutor(), rpcService);
connection.start();
final Either<TestRegistrationSuccess, TestRegistrationRejection> firstConnectionResult = connection.getConnectionFuture().get();
assertTrue(firstConnectionResult.isLeft());
final String actualConnectionId1 = firstConnectionResult.left().getCorrelationId();
assertEquals(actualConnectionId1, connectionId1);
assertTrue(connection.tryReconnect());
final Either<TestRegistrationSuccess, TestRegistrationRejection> secondConnectionResult = connection.getConnectionFuture().get();
assertTrue(secondConnectionResult.isLeft());
final String actualConnectionId2 = secondConnectionResult.left().getCorrelationId();
assertEquals(actualConnectionId2, connectionId2);
}
use of org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection in project flink by apache.
the class RegisteredRpcConnectionTest method testRpcConnectionRejectionCallsOnRegistrationRejection.
@Test
public void testRpcConnectionRejectionCallsOnRegistrationRejection() {
TestRegistrationGateway testRegistrationGateway = DefaultTestRegistrationGateway.newBuilder().setRegistrationFunction((uuid, aLong) -> CompletableFuture.completedFuture(new TestRegistrationRejection(TestRegistrationRejection.RejectionReason.REJECTED))).build();
rpcService.registerGateway(testRegistrationGateway.getAddress(), testRegistrationGateway);
TestRpcConnection connection = new TestRpcConnection(testRegistrationGateway.getAddress(), UUID.randomUUID(), rpcService.getScheduledExecutor(), rpcService);
connection.start();
final Either<TestRegistrationSuccess, TestRegistrationRejection> connectionResult = connection.getConnectionFuture().join();
assertTrue(connectionResult.isRight());
final TestRegistrationRejection registrationRejection = connectionResult.right();
assertThat(registrationRejection.getRejectionReason(), is(TestRegistrationRejection.RejectionReason.REJECTED));
}
Aggregations