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();
}
}
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();
}
}
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();
}
}
Aggregations