use of akka.actor.InvalidActorNameException 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 akka.actor.InvalidActorNameException in project transporter by wang4ever.
the class ActorManager method actorCreate.
/**
* 创建一个actor
*
* @param actorName
* actor名称
* @return
*/
public ActorBean actorCreate(String actorName) {
// 1.0 Check info.
if (this._system == null)
throw new AkkaException("Create actor failed('" + actorName + "'), actor system is unnitialized.");
if (StringUtils.equalsIgnoreCase(actorName, ActorPath.DEFAULT_ACTOR_NAME) && this.defaultActorBean != null)
throw new AkkaException("Create actor failed, because the name '" + actorName + "' is the guardian.");
// 1.1 Create accpetActor.
try {
this._system.actorOf(Props.create(AccpetActor.class, actorName), actorName);
} catch (InvalidActorNameException e) {
if (logger.isInfoEnabled())
logger.info("Create an existing actor '{}'", actorName);
} catch (Throwable t) {
logger.error("Creating actor '" + actorName + "' failed.", t);
throw new AkkaException(t.getMessage(), t);
}
// 1.2 Selection actor info.
String path = new ActorPath(conf.getActorSystemName(), conf.getHostname(), conf.getRemote().getPort(), actorName).asString();
ActorSelection actorSel = this._system.actorSelection(path);
ActorBean ab = new ActorBean(actorSel.anchor(), path);
// Default actorBean.
if (StringUtils.equalsIgnoreCase(actorName, ActorPath.DEFAULT_ACTOR_NAME))
this.defaultActorBean = ab;
// 1.3 Save actor info.
this.repository.putActorBean(actorName, ab);
return ab;
}
use of akka.actor.InvalidActorNameException in project controller by opendaylight.
the class AbstractRaftActorIntegrationTest method newTestRaftActor.
protected TestActorRef<TestRaftActor> newTestRaftActor(final String id, final TestRaftActor.Builder builder) {
builder.collectorActor(factory.createActor(MessageCollectorActor.props(), factory.generateActorId(id + "-collector"))).id(id);
InvalidActorNameException lastEx = null;
for (int i = 0; i < 10; i++) {
try {
return factory.createTestActor(builder.props().withDispatcher(Dispatchers.DefaultDispatcherId()).withMailbox(Mailboxes.DefaultMailboxId()), id);
} catch (InvalidActorNameException e) {
lastEx = e;
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
}
assertNotNull(lastEx);
throw lastEx;
}
Aggregations