本文整理汇总了Java中akka.testkit.JavaTestKit类的典型用法代码示例。如果您正苦于以下问题:Java JavaTestKit类的具体用法?Java JavaTestKit怎么用?Java JavaTestKit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaTestKit类属于akka.testkit包,在下文中一共展示了JavaTestKit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRemoveServerNonExistentServer
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void testRemoveServerNonExistentServer() {
LOG.info("testRemoveServerNonExistentServer starting");
RaftActorContext initialActorContext = new MockRaftActorContext();
TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(
MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, followerActor.path().toString()),
initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()),
actorFactory.generateActorId(LEADER_ID));
leaderActor.tell(new RemoveServer(NEW_SERVER_ID), testKit.getRef());
RemoveServerReply removeServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"),
RemoveServerReply.class);
assertEquals("getStatus", ServerChangeStatus.DOES_NOT_EXIST, removeServerReply.getStatus());
LOG.info("testRemoveServerNonExistentServer ending");
}
示例2: testOnReceiveFindLocalShardWaitForShardInitialized
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void testOnReceiveFindLocalShardWaitForShardInitialized() throws Exception {
LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
new JavaTestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
// We're passing waitUntilInitialized = true to FindLocalShard
// so the response should be
// delayed until we send ActorInitialized.
Future<Object> future = Patterns.ask(shardManager, new FindLocalShard(Shard.DEFAULT_NAME, true),
new Timeout(5, TimeUnit.SECONDS));
shardManager.tell(new ActorInitialized(), mockShardActor);
Object resp = Await.result(future, duration("5 seconds"));
assertTrue("Expected: LocalShardFound, Actual: " + resp, resp instanceof LocalShardFound);
}
};
LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
}
示例3: testDataChangedWhenNotificationsAreEnabled
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void testDataChangedWhenNotificationsAreEnabled() {
new JavaTestKit(getSystem()) {
{
final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH);
final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsEnabled");
// Let the DataChangeListener know that notifications should be
// enabled
subject.tell(new EnableNotification(true, "test"), getRef());
subject.tell(new DataTreeChanged(mockCandidates), getRef());
expectMsgClass(DataTreeChangedReply.class);
Mockito.verify(mockListener).onDataTreeChanged(mockCandidates);
}
};
}
示例4: testRemoveServerWithNoLeader
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void testRemoveServerWithNoLeader() {
LOG.info("testRemoveServerWithNoLeader starting");
DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
TestActorRef<MockRaftActor> leaderActor = actorFactory.createTestActor(
MockRaftActor.builder().id(LEADER_ID).peerAddresses(ImmutableMap.of(FOLLOWER_ID,
followerActor.path().toString())).config(configParams).persistent(Optional.of(false))
.props().withDispatcher(Dispatchers.DefaultDispatcherId()),
actorFactory.generateActorId(LEADER_ID));
leaderActor.underlyingActor().waitForInitializeBehaviorComplete();
leaderActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef());
RemoveServerReply removeServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"),
RemoveServerReply.class);
assertEquals("getStatus", ServerChangeStatus.NO_LEADER, removeServerReply.getStatus());
LOG.info("testRemoveServerWithNoLeader ending");
}
示例5: testWriteOnlyTxOnReceiveCloseTransaction
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void testWriteOnlyTxOnReceiveCloseTransaction() throws Exception {
new JavaTestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(),
"testWriteTxOnReceiveCloseTransaction");
watch(transaction);
transaction.tell(new CloseTransaction().toSerializable(), getRef());
expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
expectTerminated(duration("3 seconds"), transaction);
}
};
}
示例6: onReceiveOfMessageCoffeeHouseShouldLogMessage
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void onReceiveOfMessageCoffeeHouseShouldLogMessage() {
new JavaTestKit(system) {{
ActorRef coffeeHouse = system.actorOf(Props.create(CoffeeHouse.class));
coffeeHouse.tell("Brew Coffee", getRef());
new ExpectMsg<String>("Some [Cc]offee response") {
@Override
protected String match(Object msg) {
if (msg.toString().matches(".*[Cc]offee.*")) {
return "match";
} else {
throw noMatch();
}
}
}.get();
}};
}
示例7: sendingCoffeeFinishedShouldResultInServeCoffeeMessageToWaiter
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void sendingCoffeeFinishedShouldResultInServeCoffeeMessageToWaiter() {
new JavaTestKit(system) {{
ActorRef guest = createGuest(this, getRef());
guest.tell(Guest.CoffeeFinished.Instance, ActorRef.noSender());
expectMsgEquals(new Waiter.ServeCoffee(new Coffee.Akkaccino()));
}};
}
示例8: shouldCreateChildActorCalledWaiterWhenCreated
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void shouldCreateChildActorCalledWaiterWhenCreated() {
new JavaTestKit(system) {{
system.actorOf(CoffeeHouse.props(Integer.MAX_VALUE), "create-waiter");
expectActor(this, "/user/create-waiter/waiter");
}};
}
示例9: sendingApproveCoffeeShouldForwardPrepareCoffeeIfCaffeineLimitNotReached
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void sendingApproveCoffeeShouldForwardPrepareCoffeeIfCaffeineLimitNotReached() {
new JavaTestKit(system) {{
ActorRef coffeeHouse = createActor(CoffeeHouse.class, "prepare-coffee", () -> new CoffeeHouse(Integer.MAX_VALUE) {
@Override
protected ActorRef createBarista() {
return getRef();
}
});
coffeeHouse.tell(new CoffeeHouse.CreateGuest(new Coffee.Akkaccino(), Integer.MAX_VALUE), ActorRef.noSender());
ActorRef guest = expectActor(this, "/user/prepare-coffee/$*");
coffeeHouse.tell(new CoffeeHouse.ApproveCoffee(new Coffee.Akkaccino(), guest), getRef());
expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), guest));
}};
}
示例10: sendingServeCoffeeShouldResultInCoffeeServedResponse
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void sendingServeCoffeeShouldResultInCoffeeServedResponse() {
new JavaTestKit(system) {{
ActorRef waiter = system.actorOf(Waiter.props());
waiter.tell(new Waiter.ServeCoffee(new Coffee.Akkaccino()), getRef());
expectMsgEquals(new Waiter.CoffeeServed(new Coffee.Akkaccino()));
}};
}
示例11: sendingServeCoffeeShouldResultInApproveCoffeeToCoffeeHouse
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void sendingServeCoffeeShouldResultInApproveCoffeeToCoffeeHouse() {
new JavaTestKit(system) {{
ActorRef coffeeHouse = getRef();
TestProbe guest = new TestProbe(system);
ActorRef waiter = system.actorOf(Waiter.props(coffeeHouse, system.deadLetters(), Integer.MAX_VALUE));
waiter.tell(new Waiter.ServeCoffee(new Coffee.Akkaccino()), guest.ref());
expectMsgEquals(new CoffeeHouse.ApproveCoffee(new Coffee.Akkaccino(), guest.ref()));
}};
}
示例12: sendingComplaintShouldResultInPrepareCoffeeToBarista
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void sendingComplaintShouldResultInPrepareCoffeeToBarista() {
new JavaTestKit(system) {{
ActorRef barista = getRef();
TestProbe guest = new TestProbe(system);
ActorRef waiter = system.actorOf(Waiter.props(system.deadLetters(), barista, 1));
waiter.tell(new Waiter.Complaint(new Coffee.Akkaccino()), guest.ref());
expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), guest.ref()));
}};
}
示例13: sendingCoffeeServedShouldIncreaseCoffeeCount
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void sendingCoffeeServedShouldIncreaseCoffeeCount() {
new JavaTestKit(system) {{
ActorRef guest = system.actorOf(Guest.props(system.deadLetters(), new Coffee.Akkaccino(), duration("100 milliseconds")));
interceptInfoLogMessage(this, ".*[Ee]njoy.*1\\.*", 1, () -> {
guest.tell(new Waiter.CoffeeServed(new Coffee.Akkaccino()), ActorRef.noSender());
});
}};
}
示例14: onTerminationOfGuestCoffeeHouseShouldRemoveGuestFromBookkeeper
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void onTerminationOfGuestCoffeeHouseShouldRemoveGuestFromBookkeeper() {
new JavaTestKit(system) {{
ActorRef coffeeHouse = system.actorOf(CoffeeHouse.props(1), "guest-removed");
coffeeHouse.tell(new CoffeeHouse.CreateGuest(new Coffee.Akkaccino(), Integer.MAX_VALUE), ActorRef.noSender());
ActorRef guest = expectActor(this, "/user/guest-removed/$*");
interceptDebugLogMessage(this, ".*[Rr]emoved.*", 1, () -> {
coffeeHouse.tell(new CoffeeHouse.ApproveCoffee(new Coffee.Akkaccino(), guest), ActorRef.noSender());
});
}};
}
示例15: shouldCreateChildActorCalledBaristaWhenCreated
import akka.testkit.JavaTestKit; //导入依赖的package包/类
@Test
public void shouldCreateChildActorCalledBaristaWhenCreated() {
new JavaTestKit(system) {{
system.actorOf(CoffeeHouse.props(Integer.MAX_VALUE), "create-barista");
expectActor(this, "/user/create-barista/waiter");
}};
}