当前位置: 首页>>代码示例>>Java>>正文


Java JavaTestKit.expectNoMsg方法代码示例

本文整理汇总了Java中akka.testkit.JavaTestKit.expectNoMsg方法的典型用法代码示例。如果您正苦于以下问题:Java JavaTestKit.expectNoMsg方法的具体用法?Java JavaTestKit.expectNoMsg怎么用?Java JavaTestKit.expectNoMsg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在akka.testkit.JavaTestKit的用法示例。


在下文中一共展示了JavaTestKit.expectNoMsg方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testOnDataTreeChanged

import akka.testkit.JavaTestKit; //导入方法依赖的package包/类
@Test
public void testOnDataTreeChanged() throws Exception {
    JavaTestKit kit = new JavaTestKit(getSystem());

    new CandidateListChangeListener(kit.getRef(), "test").init(shardDataTree);

    String memberName1 = "member-1";
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName1));

    CandidateAdded candidateAdded = kit.expectMsgClass(CandidateAdded.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateAdded.getEntityPath());
    assertEquals("getNewCandidate", memberName1, candidateAdded.getNewCandidate());
    assertEquals("getAllCandidates", ImmutableSet.of(memberName1),
            ImmutableSet.copyOf(candidateAdded.getAllCandidates()));

    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName1));
    kit.expectNoMsg(FiniteDuration.create(500, TimeUnit.MILLISECONDS));

    String memberName2 = "member-2";
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName2));

    candidateAdded = kit.expectMsgClass(CandidateAdded.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateAdded.getEntityPath());
    assertEquals("getNewCandidate", memberName2, candidateAdded.getNewCandidate());
    assertEquals("getAllCandidates", ImmutableSet.of(memberName1, memberName2),
            ImmutableSet.copyOf(candidateAdded.getAllCandidates()));

    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID2, memberName1));

    candidateAdded = kit.expectMsgClass(CandidateAdded.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID2), candidateAdded.getEntityPath());
    assertEquals("getNewCandidate", memberName1, candidateAdded.getNewCandidate());
    assertEquals("getAllCandidates", ImmutableSet.of(memberName1),
            ImmutableSet.copyOf(candidateAdded.getAllCandidates()));

    deleteNode(candidatePath(ENTITY_TYPE, ENTITY_ID1, memberName1));

    CandidateRemoved candidateRemoved = kit.expectMsgClass(CandidateRemoved.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateRemoved.getEntityPath());
    assertEquals("getRemovedCandidate", memberName1, candidateRemoved.getRemovedCandidate());
    assertEquals("getRemainingCandidates", ImmutableSet.of(memberName2),
            ImmutableSet.copyOf(candidateRemoved.getRemainingCandidates()));

    deleteNode(candidatePath(ENTITY_TYPE, ENTITY_ID1, memberName2));

    candidateRemoved = kit.expectMsgClass(CandidateRemoved.class);
    assertEquals("getEntityId", entityPath(ENTITY_TYPE, ENTITY_ID1), candidateRemoved.getEntityPath());
    assertEquals("getRemovedCandidate", memberName2, candidateRemoved.getRemovedCandidate());
    assertEquals("getRemainingCandidates", ImmutableSet.of(),
            ImmutableSet.copyOf(candidateRemoved.getRemainingCandidates()));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:52,代码来源:CandidateListChangeListenerTest.java

示例2: testSuccess

import akka.testkit.JavaTestKit; //导入方法依赖的package包/类
@Test
public void testSuccess() {
    JavaTestKit kit = new JavaTestKit(getSystem());

    List<String> shardList = Arrays.asList("shard1", "shard2", "shard3");
    ShardManagerSnapshot shardManagerSnapshot = new ShardManagerSnapshot(shardList, Collections.emptyMap());
    ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(
            shardList, "config", shardManagerSnapshot, kit.getRef(),
            "shard-manager", Duration.create(100, TimeUnit.SECONDS)), "testSuccess");

    kit.watch(replyActor);

    ByteState shard1SnapshotState = ByteState.of(new byte[]{1,2,3});
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(),
            Snapshot.create(shard1SnapshotState, Collections.<ReplicatedLogEntry>emptyList(),
                    2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());

    ByteState shard2SnapshotState = ByteState.of(new byte[]{4,5,6});
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard2", MEMBER_1, "config").toString(),
            Snapshot.create(shard2SnapshotState, Collections.<ReplicatedLogEntry>emptyList(),
                    2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());

    kit.expectNoMsg(FiniteDuration.create(500, TimeUnit.MILLISECONDS));

    ByteState shard3SnapshotState = ByteState.of(new byte[]{7,8,9});
    replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard3", MEMBER_1, "config").toString(),
            Snapshot.create(shard3SnapshotState, Collections.<ReplicatedLogEntry>emptyList(),
                    2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());

    DatastoreSnapshot datastoreSnapshot = kit.expectMsgClass(DatastoreSnapshot.class);

    assertEquals("getType", "config", datastoreSnapshot.getType());
    assertEquals("getShardManagerSnapshot", shardManagerSnapshot.getShardList(),
            datastoreSnapshot.getShardManagerSnapshot().getShardList());
    List<ShardSnapshot> shardSnapshots = datastoreSnapshot.getShardSnapshots();
    assertEquals("ShardSnapshot size", 3, shardSnapshots.size());
    assertEquals("ShardSnapshot 1 getName", "shard1", shardSnapshots.get(0).getName());
    assertEquals("ShardSnapshot 1 getSnapshot", shard1SnapshotState,
            shardSnapshots.get(0).getSnapshot().getState());
    assertEquals("ShardSnapshot 2 getName", "shard2", shardSnapshots.get(1).getName());
    assertEquals("ShardSnapshot 2 getSnapshot", shard2SnapshotState,
            shardSnapshots.get(1).getSnapshot().getState());
    assertEquals("ShardSnapshot 3 getName", "shard3", shardSnapshots.get(2).getName());
    assertEquals("ShardSnapshot 3 getSnapshot", shard3SnapshotState,
            shardSnapshots.get(2).getSnapshot().getState());

    kit.expectMsgClass(Terminated.class);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:49,代码来源:ShardManagerGetSnapshotReplyActorTest.java


注:本文中的akka.testkit.JavaTestKit.expectNoMsg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。