Search in sources :

Example 6 with TestingRpcService

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

the class RetryingRegistrationTest method testSimpleSuccessfulRegistration.

@Test
public void testSimpleSuccessfulRegistration() throws Exception {
    final String testId = "laissez les bon temps roulez";
    final String testEndpointAddress = "<test-address>";
    final UUID leaderId = UUID.randomUUID();
    // an endpoint that immediately returns success
    TestRegistrationGateway testGateway = new TestRegistrationGateway(new TestRegistrationSuccess(testId));
    TestingRpcService rpc = new TestingRpcService();
    try {
        rpc.registerGateway(testEndpointAddress, testGateway);
        TestRetryingRegistration registration = new TestRetryingRegistration(rpc, testEndpointAddress, leaderId);
        registration.startRegistration();
        Future<Tuple2<TestRegistrationGateway, TestRegistrationSuccess>> future = registration.getFuture();
        assertNotNull(future);
        // multiple accesses return the same future
        assertEquals(future, registration.getFuture());
        Tuple2<TestRegistrationGateway, TestRegistrationSuccess> success = future.get(10L, TimeUnit.SECONDS);
        // validate correct invocation and result
        assertEquals(testId, success.f1.getCorrelationId());
        assertEquals(leaderId, testGateway.getInvocations().take().leaderId());
    } finally {
        testGateway.stop();
        rpc.stopService();
    }
}
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 7 with TestingRpcService

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

the class RetryingRegistrationTest method testRetryOnError.

@Test
@SuppressWarnings("unchecked")
public void testRetryOnError() throws Exception {
    final String testId = "Petit a petit, l'oiseau fait son nid";
    final String testEndpointAddress = "<test-address>";
    final UUID leaderId = UUID.randomUUID();
    TestingRpcService rpc = new TestingRpcService();
    try {
        // gateway that upon calls first responds with a failure, then with a success
        TestRegistrationGateway testGateway = mock(TestRegistrationGateway.class);
        when(testGateway.registrationCall(any(UUID.class), anyLong())).thenReturn(FlinkCompletableFuture.<RegistrationResponse>completedExceptionally(new Exception("test exception")), FlinkCompletableFuture.<RegistrationResponse>completed(new TestRegistrationSuccess(testId)));
        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(10, TimeUnit.SECONDS);
        long finished = System.nanoTime();
        long elapsedMillis = (finished - started) / 1000000;
        assertEquals(testId, success.f1.getCorrelationId());
        // validate that some retry-delay / back-off behavior happened
        assertTrue("retries did not properly back off", elapsedMillis >= TestRetryingRegistration.DELAY_ON_ERROR);
    } finally {
        rpc.stopService();
    }
}
Also used : Tuple2(org.apache.flink.api.java.tuple.Tuple2) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) UUID(java.util.UUID) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 8 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)

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