Search in sources :

Example 1 with TestingRpcService

use of org.apache.flink.runtime.rpc.TestingRpcService 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
    TestRegistrationGateway testGateway = new TestRegistrationGateway(new RetryingRegistrationTest.TestRegistrationSuccess(connectionID));
    TestingRpcService rpcService = new TestingRpcService();
    try {
        rpcService.registerGateway(testRpcConnectionEndpointAddress, testGateway);
        TestRpcConnection connection = new TestRpcConnection(testRpcConnectionEndpointAddress, leaderId, rpcService.getExecutor(), rpcService);
        connection.start();
        //wait for connection established
        Thread.sleep(RetryingRegistrationTest.TestRetryingRegistration.MAX_TIMEOUT);
        // validate correct invocation and result
        assertTrue(connection.isConnected());
        assertEquals(testRpcConnectionEndpointAddress, connection.getTargetAddress());
        assertEquals(leaderId, connection.getTargetLeaderId());
        assertEquals(testGateway, connection.getTargetGateway());
        assertEquals(connectionID, connection.getConnectionId());
    } finally {
        testGateway.stop();
        rpcService.stopService();
    }
}
Also used : TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with TestingRpcService

use of org.apache.flink.runtime.rpc.TestingRpcService in project flink by apache.

the class RegisteredRpcConnectionTest method testRpcConnectionClose.

@Test
public void testRpcConnectionClose() throws Exception {
    final String testRpcConnectionEndpointAddress = "<TestRpcConnectionEndpointAddress>";
    final UUID leaderId = UUID.randomUUID();
    final String connectionID = "Test RPC Connection ID";
    TestRegistrationGateway testGateway = new TestRegistrationGateway(new RetryingRegistrationTest.TestRegistrationSuccess(connectionID));
    TestingRpcService rpcService = new TestingRpcService();
    try {
        rpcService.registerGateway(testRpcConnectionEndpointAddress, testGateway);
        TestRpcConnection connection = new TestRpcConnection(testRpcConnectionEndpointAddress, leaderId, rpcService.getExecutor(), rpcService);
        connection.start();
        //close the connection
        connection.close();
        // validate connection is closed
        assertEquals(testRpcConnectionEndpointAddress, connection.getTargetAddress());
        assertEquals(leaderId, connection.getTargetLeaderId());
        assertTrue(connection.isClosed());
    } finally {
        testGateway.stop();
        rpcService.stopService();
    }
}
Also used : TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) TestRegistrationSuccess(org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with TestingRpcService

use of org.apache.flink.runtime.rpc.TestingRpcService in project flink by apache.

the class RetryingRegistrationTest method testCancellation.

@Test
public void testCancellation() throws Exception {
    final String testEndpointAddress = "my-test-address";
    final UUID leaderId = UUID.randomUUID();
    TestingRpcService rpc = new TestingRpcService();
    try {
        FlinkCompletableFuture<RegistrationResponse> result = new FlinkCompletableFuture<>();
        TestRegistrationGateway testGateway = mock(TestRegistrationGateway.class);
        when(testGateway.registrationCall(any(UUID.class), anyLong())).thenReturn(result);
        rpc.registerGateway(testEndpointAddress, testGateway);
        TestRetryingRegistration registration = new TestRetryingRegistration(rpc, testEndpointAddress, leaderId);
        registration.startRegistration();
        // cancel and fail the current registration attempt
        registration.cancel();
        result.completeExceptionally(new TimeoutException());
        // there should not be a second registration attempt
        verify(testGateway, atMost(1)).registrationCall(any(UUID.class), anyLong());
    } finally {
        rpc.stopService();
    }
}
Also used : TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) UUID(java.util.UUID) FlinkCompletableFuture(org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 4 with TestingRpcService

use of org.apache.flink.runtime.rpc.TestingRpcService in project flink by apache.

the class RetryingRegistrationTest method testRetriesOnTimeouts.

@Test
public void testRetriesOnTimeouts() throws Exception {
    final String testId = "rien ne va plus";
    final String testEndpointAddress = "<test-address>";
    final UUID leaderId = UUID.randomUUID();
    // an endpoint that immediately returns futures with timeouts before returning a successful future
    TestRegistrationGateway testGateway = new TestRegistrationGateway(// timeout
    null, // timeout
    null, // success
    new TestRegistrationSuccess(testId));
    TestingRpcService rpc = new TestingRpcService();
    try {
        rpc.registerGateway(testEndpointAddress, testGateway);
        TestRetryingRegistration registration = new TestRetryingRegistration(rpc, testEndpointAddress, leaderId);
        long started = System.nanoTime();
        registration.startRegistration();
        Future<Tuple2<TestRegistrationGateway, TestRegistrationSuccess>> future = registration.getFuture();
        Tuple2<TestRegistrationGateway, TestRegistrationSuccess> success = future.get(10L, TimeUnit.SECONDS);
        long finished = System.nanoTime();
        long elapsedMillis = (finished - started) / 1000000;
        // validate correct invocation and result
        assertEquals(testId, success.f1.getCorrelationId());
        assertEquals(leaderId, testGateway.getInvocations().take().leaderId());
        // validate that some retry-delay / back-off behavior happened
        assertTrue("retries did not properly back off", elapsedMillis >= 3 * TestRetryingRegistration.INITIAL_TIMEOUT);
    } finally {
        rpc.stopService();
        testGateway.stop();
    }
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with TestingRpcService

use of org.apache.flink.runtime.rpc.TestingRpcService in project flink by apache.

the class RegisteredRpcConnectionTest method testRpcConnectionFailures.

@Test
public void testRpcConnectionFailures() throws Exception {
    final String connectionFailureMessage = "Test RPC Connection failure";
    final String testRpcConnectionEndpointAddress = "<TestRpcConnectionEndpointAddress>";
    final UUID leaderId = UUID.randomUUID();
    TestingRpcService rpcService = new TestingRpcService();
    try {
        // gateway that upon calls Throw an exception
        TestRegistrationGateway testGateway = mock(TestRegistrationGateway.class);
        when(testGateway.registrationCall(any(UUID.class), anyLong())).thenThrow(new RuntimeException(connectionFailureMessage));
        rpcService.registerGateway(testRpcConnectionEndpointAddress, testGateway);
        TestRpcConnection connection = new TestRpcConnection(testRpcConnectionEndpointAddress, leaderId, rpcService.getExecutor(), rpcService);
        connection.start();
        //wait for connection failure
        Thread.sleep(RetryingRegistrationTest.TestRetryingRegistration.MAX_TIMEOUT);
        // validate correct invocation and result
        assertFalse(connection.isConnected());
        assertEquals(testRpcConnectionEndpointAddress, connection.getTargetAddress());
        assertEquals(leaderId, connection.getTargetLeaderId());
        assertNull(connection.getTargetGateway());
        assertEquals(connectionFailureMessage, connection.getFailareMessage());
    } finally {
        rpcService.stopService();
    }
}
Also used : TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)8 TestingRpcService (org.apache.flink.runtime.rpc.TestingRpcService)8 Test (org.junit.Test)8 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)4 TimeoutException (java.util.concurrent.TimeoutException)2 TestRegistrationSuccess (org.apache.flink.runtime.registration.RetryingRegistrationTest.TestRegistrationSuccess)2 ExecutionException (java.util.concurrent.ExecutionException)1 FlinkCompletableFuture (org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture)1