本文整理汇总了Java中akka.testkit.TestActorRef.create方法的典型用法代码示例。如果您正苦于以下问题:Java TestActorRef.create方法的具体用法?Java TestActorRef.create怎么用?Java TestActorRef.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类akka.testkit.TestActorRef
的用法示例。
在下文中一共展示了TestActorRef.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTestActor
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
/**
* Create a test actor with the passed in name.
*
* @param props the actor Props
* @param actorId name of actor
* @param <T> the actor type
* @return the ActorRef
*/
@SuppressWarnings("unchecked")
public <T extends Actor> TestActorRef<T> createTestActor(Props props, String actorId) {
InvalidActorNameException lastError = null;
for (int i = 0; i < 10; i++) {
try {
TestActorRef<T> actorRef = TestActorRef.create(system, props, actorId);
return (TestActorRef<T>) addActor(actorRef, true);
} catch (InvalidActorNameException e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
示例2: testHandleRegisterRoleChangeListener
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test
public void testHandleRegisterRoleChangeListener() throws Exception {
new JavaTestKit(getSystem()) {
{
String memberId = "testHandleRegisterRoleChangeListener";
ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(),
RoleChangeNotifier.getProps(memberId), memberId);
notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor,
RegisterRoleChangeListenerReply.class);
assertNotNull(reply);
RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor,
RoleChangeNotification.class);
assertNull(notification);
}
};
}
示例3: testNegativeReadWithReadWriteTransactionClosed
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadWriteTransactionClosed() throws Exception {
final ActorRef shard = createShard();
final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard,
datastoreContext, shardStats);
final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props,
"testNegativeReadWithReadWriteTransactionClosed");
Future<Object> future = akka.pattern.Patterns.ask(subject,
new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY,
DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
示例4: testNegativeExistsWithReadWriteTransactionClosed
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test(expected = ReadFailedException.class)
public void testNegativeExistsWithReadWriteTransactionClosed() throws Exception {
final ActorRef shard = createShard();
final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard,
datastoreContext, shardStats);
final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props,
"testNegativeExistsWithReadWriteTransactionClosed");
Future<Object> future = akka.pattern.Patterns.ask(subject,
new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
future = akka.pattern.Patterns.ask(subject,
new DataExists(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
示例5: SinglePlayerActorsContainer
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
public SinglePlayerActorsContainer(ActorSystem system) {
Props p1 = Props.create(CPUActor.class);
cpuActorRef = TestActorRef.create(system, p1);
cpuActor = cpuActorRef.underlyingActor();
Props p2 = Props.create(GameViewActor.class);
gameViewActorRef = TestActorRef.create(system, p2);
gameViewActor = gameViewActorRef.underlyingActor();
}
示例6: testHandleRaftRoleChanged
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test
public void testHandleRaftRoleChanged() throws Exception {
new JavaTestKit(getSystem()) {
{
String memberId = "testHandleRegisterRoleChangeListenerWithNotificationSet";
ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
ActorRef shardActor = getTestActor();
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(),
RoleChangeNotifier.getProps(memberId), memberId);
notifierTestActorRef.tell(
new RoleChanged(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), shardActor);
// no notification should be sent as listener has not yet
// registered
assertNull(MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class));
// listener registers after role has been changed, ensure we
// sent the latest role change after a reply
notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor,
RegisterRoleChangeListenerReply.class);
assertNotNull(reply);
RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor,
RoleChangeNotification.class);
assertNotNull(notification);
assertEquals(RaftState.Candidate.name(), notification.getOldRole());
assertEquals(RaftState.Leader.name(), notification.getNewRole());
}
};
}
示例7: testHandleLeaderStateChanged
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test
public void testHandleLeaderStateChanged() throws Exception {
new JavaTestKit(getSystem()) {
{
String actorId = "testHandleLeaderStateChanged";
TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(),
RoleChangeNotifier.getProps(actorId), actorId);
notifierTestActorRef.tell(new LeaderStateChanged("member1", "leader1", (short) 5), ActorRef.noSender());
// listener registers after the sate has been changed, ensure we
// sent the latest state change after a reply
notifierTestActorRef.tell(new RegisterRoleChangeListener(), getRef());
expectMsgClass(RegisterRoleChangeListenerReply.class);
LeaderStateChanged leaderStateChanged = expectMsgClass(LeaderStateChanged.class);
assertEquals("getMemberId", "member1", leaderStateChanged.getMemberId());
assertEquals("getLeaderId", "leader1", leaderStateChanged.getLeaderId());
assertEquals("getLeaderPayloadVersion", 5, leaderStateChanged.getLeaderPayloadVersion());
notifierTestActorRef.tell(new LeaderStateChanged("member1", "leader2", (short) 6), ActorRef.noSender());
leaderStateChanged = expectMsgClass(LeaderStateChanged.class);
assertEquals("getMemberId", "member1", leaderStateChanged.getMemberId());
assertEquals("getLeaderId", "leader2", leaderStateChanged.getLeaderId());
assertEquals("getLeaderPayloadVersion", 6, leaderStateChanged.getLeaderPayloadVersion());
}
};
}
示例8: testBroadcast
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test
public void testBroadcast() {
new JavaTestKit(getSystem()) {
{
ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props());
ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props());
TestActorRef<MockShardManager> shardManagerActorRef = TestActorRef.create(getSystem(),
MockShardManager.props());
MockShardManager shardManagerActor = shardManagerActorRef.underlyingActor();
shardManagerActor.addFindPrimaryResp("shard1", new RemotePrimaryShardFound(
shardActorRef1.path().toString(), DataStoreVersions.CURRENT_VERSION));
shardManagerActor.addFindPrimaryResp("shard2", new RemotePrimaryShardFound(
shardActorRef2.path().toString(), DataStoreVersions.CURRENT_VERSION));
shardManagerActor.addFindPrimaryResp("shard3", new NoShardLeaderException("not found"));
Configuration mockConfig = mock(Configuration.class);
doReturn(Sets.newLinkedHashSet(Arrays.asList("shard1", "shard2", "shard3"))).when(mockConfig)
.getAllShardNames();
ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef,
mock(ClusterWrapper.class), mockConfig,
DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(),
new PrimaryShardInfoFutureCache());
actorContext.broadcast(v -> new TestMessage(), TestMessage.class);
MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);
}
};
}
示例9: testServerChangeWhenAlreadyInProgress
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
public void testServerChangeWhenAlreadyInProgress(final String shardName, final Object firstServerChange,
final Class<?> firstForwardedServerChangeClass,
final Object secondServerChange) throws Exception {
new JavaTestKit(getSystem()) {
{
JavaTestKit mockShardLeaderKit = new JavaTestKit(getSystem());
final JavaTestKit secondRequestKit = new JavaTestKit(getSystem());
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder()
.put(shardName, Arrays.asList("member-2")).build());
final TestActorRef<TestShardManager> shardManager = TestActorRef.create(getSystem(),
newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockShardActor)
.cluster(new MockClusterWrapper()).props()
.withDispatcher(Dispatchers.DefaultDispatcherId()),
shardMgrID);
shardManager.underlyingActor()
.setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(firstServerChange, getRef());
mockShardLeaderKit.expectMsgClass(firstForwardedServerChangeClass);
shardManager.tell(secondServerChange, secondRequestKit.getRef());
secondRequestKit.expectMsgClass(duration("5 seconds"), Failure.class);
}
};
}
示例10: testConfigCustomizations
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@Test
public void testConfigCustomizations() {
AkkaConfigurationReader reader = new TestConfigReader();
final int expectedCapacity = 100;
String timeOutVal = "10ms";
FiniteDuration expectedTimeout = FiniteDuration.create(10, TimeUnit.MILLISECONDS);
RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("unit-test")
.metricCaptureEnabled(true)//enable metric capture
.mailboxCapacity(expectedCapacity)
.mailboxPushTimeout(timeOutVal)
.withConfigReader(reader)
.build();
Assert.assertTrue(config.isMetricCaptureEnabled());
Assert.assertEquals(expectedCapacity, config.getMailBoxCapacity().intValue());
Assert.assertEquals(expectedTimeout.toMillis(), config.getMailBoxPushTimeout().toMillis());
//Now check this config inside an actor
ActorSystem system = ActorSystem.create("unit-test", config.get());
TestActorRef<ConfigTestActor> configTestActorTestActorRef =
TestActorRef.create(system, Props.create(ConfigTestActor.class));
ConfigTestActor actor = configTestActorTestActorRef.underlyingActor();
Config actorConfig = actor.getConfig();
config = new RemoteRpcProviderConfig(actorConfig);
Assert.assertTrue(config.isMetricCaptureEnabled());
Assert.assertEquals(expectedCapacity, config.getMailBoxCapacity().intValue());
Assert.assertEquals(expectedTimeout.toMillis(), config.getMailBoxPushTimeout().toMillis());
}
示例11: createGossiper
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
/**
* Create Gossiper actor and return the underlying instance of Gossiper class.
*
* @return instance of Gossiper class
*/
private static Gossiper createGossiper() {
final RemoteRpcProviderConfig config =
new RemoteRpcProviderConfig.Builder("unit-test")
.withConfigReader(ConfigFactory::load).build();
final Props props = Gossiper.testProps(config);
final TestActorRef<Gossiper> testRef = TestActorRef.create(system, props, "testGossiper");
return testRef.underlyingActor();
}
示例12: setUp
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
ref = TestActorRef.create(system, props, "testActor");
insertBatchDataToES();
insertOrgDataToES();
insertUserCoursesDataToES();
insertUserDataToES();
}
示例13: setUp
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
ref = TestActorRef.create(system, prop, "testActor");
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
insertUserDataToES();
}
示例14: setUp
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
ref = TestActorRef.create(system, props, "testActor");
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
insertUserDataToES();
}
示例15: setUp
import akka.testkit.TestActorRef; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() {
system = ActorSystem.create("system");
Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
ref = TestActorRef.create(system, props, "testActor");
insertCourse();
insertContent();
}