use of org.apache.flink.runtime.messages.RegistrationMessages.AcknowledgeRegistration in project flink by apache.
the class TaskManagerRegistrationTest method testTaskManagerResumesConnectAfterJobManagerFailure.
/**
* Validate that the TaskManager attempts to re-connect after it lost the connection
* to the JobManager.
*/
@Test
public void testTaskManagerResumesConnectAfterJobManagerFailure() {
new JavaTestKit(actorSystem) {
{
ActorGateway fakeJobManager1Gateway = null;
ActorGateway fakeJobManager2Gateway = null;
ActorGateway taskManagerGateway = null;
final String JOB_MANAGER_NAME = "ForwardingJobManager";
try {
fakeJobManager1Gateway = TestingUtils.createForwardingActor(actorSystem, getTestActor(), Option.apply(JOB_MANAGER_NAME));
final ActorGateway fakeJM1Gateway = fakeJobManager1Gateway;
// we make the test actor (the test kit) the JobManager to intercept
// the messages
taskManagerGateway = createTaskManager(actorSystem, fakeJobManager1Gateway, config, true, false);
final ActorGateway tm = taskManagerGateway;
// validate initial registration
new Within(timeout) {
@Override
protected void run() {
// the TaskManager should try to register
expectMsgClass(RegisterTaskManager.class);
// we accept the registration
tm.tell(new AcknowledgeRegistration(new InstanceID(), 45234), fakeJM1Gateway);
}
};
// kill the first forwarding JobManager
watch(fakeJobManager1Gateway.actor());
stopActor(fakeJobManager1Gateway.actor());
final ActorGateway gateway = fakeJobManager1Gateway;
new Within(timeout) {
@Override
protected void run() {
Object message = null;
// are queued up in the testing actor's mailbox
while (message == null || !(message instanceof Terminated)) {
message = receiveOne(timeout);
}
Terminated terminatedMessage = (Terminated) message;
assertEquals(gateway.actor(), terminatedMessage.actor());
}
};
fakeJobManager1Gateway = null;
// now start the second fake JobManager and expect that
// the TaskManager registers again
// the second fake JM needs to have the same actor URL
// since we cannot reliably wait until the actor is unregistered (name is
// available again) we loop with multiple tries for 20 seconds
long deadline = 20000000000L + System.nanoTime();
do {
try {
fakeJobManager2Gateway = TestingUtils.createForwardingActor(actorSystem, getTestActor(), Option.apply(JOB_MANAGER_NAME));
} catch (InvalidActorNameException e) {
// wait and retry
Thread.sleep(100);
}
} while (fakeJobManager2Gateway == null && System.nanoTime() < deadline);
final ActorGateway fakeJM2GatewayClosure = fakeJobManager2Gateway;
// expect the next registration
new Within(timeout) {
@Override
protected void run() {
expectMsgClass(RegisterTaskManager.class);
// we accept the registration
tm.tell(new AcknowledgeRegistration(new InstanceID(), 45234), fakeJM2GatewayClosure);
}
};
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
stopActor(taskManagerGateway);
stopActor(fakeJobManager1Gateway);
stopActor(fakeJobManager2Gateway);
}
}
};
}
use of org.apache.flink.runtime.messages.RegistrationMessages.AcknowledgeRegistration in project flink by apache.
the class TaskManagerRegistrationTest method testCheckForValidRegistrationSessionIDs.
@Test
public void testCheckForValidRegistrationSessionIDs() {
new JavaTestKit(actorSystem) {
{
ActorGateway taskManagerGateway = null;
try {
// we make the test actor (the test kit) the JobManager to intercept
// the messages
taskManagerGateway = createTaskManager(actorSystem, getTestActor(), config, true, false);
final ActorRef taskManager = taskManagerGateway.actor();
final UUID falseLeaderSessionID = UUID.randomUUID();
final UUID trueLeaderSessionID = null;
new Within(timeout) {
@Override
protected void run() {
taskManager.tell(TaskManagerMessages.getNotifyWhenRegisteredAtJobManagerMessage(), getTestActor());
// the TaskManager should try to register
LeaderSessionMessage lsm = expectMsgClass(LeaderSessionMessage.class);
assertTrue(lsm.leaderSessionID() == trueLeaderSessionID);
assertTrue(lsm.message() instanceof RegisterTaskManager);
final ActorRef tm = getLastSender();
// This AcknowledgeRegistration message should be discarded because the
// registration session ID is wrong
tm.tell(new LeaderSessionMessage(falseLeaderSessionID, new AcknowledgeRegistration(new InstanceID(), 1)), getTestActor());
// Valid AcknowledgeRegistration message
tm.tell(new LeaderSessionMessage(trueLeaderSessionID, new AcknowledgeRegistration(new InstanceID(), 1)), getTestActor());
Object message = null;
Object confirmMessageClass = TaskManagerMessages.getRegisteredAtJobManagerMessage().getClass();
while (message == null || !(message.getClass().equals(confirmMessageClass))) {
message = receiveOne(TestingUtils.TESTING_DURATION());
}
tm.tell(JobManagerMessages.getRequestLeaderSessionID(), getTestActor());
expectMsgEquals(new JobManagerMessages.ResponseLeaderSessionID(trueLeaderSessionID));
}
};
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
stopActor(taskManagerGateway);
}
}
};
}
Aggregations