use of org.apache.flink.runtime.messages.RegistrationMessages.RegisterTaskManager in project flink by apache.
the class TaskManagerRegistrationTest method testTaskManagerNoExcessiveRegistrationMessages.
/**
* Tests that the TaskManager does not send an excessive amount of registration messages to
* the job manager if its registration was rejected.
*/
@Test
public void testTaskManagerNoExcessiveRegistrationMessages() throws Exception {
new JavaTestKit(actorSystem) {
{
ActorGateway jm = null;
ActorGateway taskManager = null;
try {
FiniteDuration timeout = new FiniteDuration(5, TimeUnit.SECONDS);
jm = TestingUtils.createForwardingActor(actorSystem, getTestActor(), Option.<String>empty());
final ActorGateway jmGateway = jm;
long refusedRegistrationPause = 500;
long initialRegistrationPause = 100;
long maxDelay = 30000;
Configuration tmConfig = new Configuration(config);
tmConfig.setString(ConfigConstants.TASK_MANAGER_REFUSED_REGISTRATION_PAUSE, refusedRegistrationPause + " ms");
tmConfig.setString(ConfigConstants.TASK_MANAGER_INITIAL_REGISTRATION_PAUSE, initialRegistrationPause + " ms");
// we make the test actor (the test kit) the JobManager to intercept
// the messages
taskManager = createTaskManager(actorSystem, jmGateway, tmConfig, true, false);
final ActorGateway taskManagerGateway = taskManager;
final Deadline deadline = timeout.fromNow();
try {
while (deadline.hasTimeLeft()) {
// the TaskManager should try to register
expectMsgClass(deadline.timeLeft(), RegisterTaskManager.class);
// we decline the registration
taskManagerGateway.tell(new RefuseRegistration(new Exception("test reason")), jmGateway);
}
} catch (AssertionError error) {
// ignore since it simply means that we have used up all our time
}
RegisterTaskManager[] registerTaskManagerMessages = new ReceiveWhile<RegisterTaskManager>(RegisterTaskManager.class, timeout) {
@Override
protected RegisterTaskManager match(Object msg) throws Exception {
if (msg instanceof RegisterTaskManager) {
return (RegisterTaskManager) msg;
} else {
throw noMatch();
}
}
}.get();
int maxExponent = (int) Math.floor(Math.log(((double) maxDelay / initialRegistrationPause + 1)) / Math.log(2));
int exponent = (int) Math.ceil(Math.log(((double) timeout.toMillis() / initialRegistrationPause + 1)) / Math.log(2));
int exp = Math.min(maxExponent, exponent);
long difference = timeout.toMillis() - (initialRegistrationPause * (1 << exp));
int numberRegisterTaskManagerMessages = exp;
if (difference > 0) {
numberRegisterTaskManagerMessages += Math.ceil((double) difference / maxDelay);
}
int maxExpectedNumberOfRegisterTaskManagerMessages = numberRegisterTaskManagerMessages * 2;
assertTrue("The number of RegisterTaskManager messages #" + registerTaskManagerMessages.length + " should be less than #" + maxExpectedNumberOfRegisterTaskManagerMessages, registerTaskManagerMessages.length <= maxExpectedNumberOfRegisterTaskManagerMessages);
} finally {
stopActor(taskManager);
stopActor(jm);
}
}
};
}
use of org.apache.flink.runtime.messages.RegistrationMessages.RegisterTaskManager 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