Search in sources :

Example 1 with TestRegistrationRejection

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();
    }
}
Also used : TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) UUID(java.util.UUID) TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Test(org.junit.Test)

Example 2 with TestRegistrationRejection

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);
}
Also used : TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) UUID(java.util.UUID) TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Test(org.junit.Test)

Example 3 with TestRegistrationRejection

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));
}
Also used : TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Either(org.apache.flink.types.Either) Executor(java.util.concurrent.Executor) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) Assert.assertThat(org.junit.Assert.assertThat) RpcService(org.apache.flink.runtime.rpc.RpcService) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) TestRegistrationRejection(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection) TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)3 TestRegistrationRejection (org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationRejection)3 TestRegistrationSuccess (org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess)3 Test (org.junit.Test)3 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Executor (java.util.concurrent.Executor)1 RpcService (org.apache.flink.runtime.rpc.RpcService)1 TestingRpcService (org.apache.flink.runtime.rpc.TestingRpcService)1 Either (org.apache.flink.types.Either)1 TestLogger (org.apache.flink.util.TestLogger)1 Matchers.is (org.hamcrest.Matchers.is)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNull (org.junit.Assert.assertNull)1 Assert.assertThat (org.junit.Assert.assertThat)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1