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


Java TestActorRef类代码示例

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


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

示例1: newTestRaftActor

import akka.testkit.TestActorRef; //导入依赖的package包/类
protected TestActorRef<TestRaftActor> newTestRaftActor(String id, 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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:AbstractRaftActorIntegrationTest.java

示例2: testFollowerInitialSyncStatus

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testFollowerInitialSyncStatus() throws Exception {
    final TestActorRef<Shard> shard = actorFactory.createTestActor(
            newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
            "testFollowerInitialSyncStatus");

    shard.underlyingActor().handleNonRaftCommand(new FollowerInitialSyncUpStatus(false,
            "member-1-shard-inventory-operational"));

    assertEquals(false, shard.underlyingActor().getShardMBean().getFollowerInitialSyncStatus());

    shard.underlyingActor().handleNonRaftCommand(new FollowerInitialSyncUpStatus(true,
            "member-1-shard-inventory-operational"));

    assertEquals(true, shard.underlyingActor().getShardMBean().getFollowerInitialSyncStatus());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:ShardTest.java

示例3: testNonVotingOnRecovery

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testNonVotingOnRecovery() throws Exception {
    TEST_LOG.info("testNonVotingOnRecovery starting");

    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setElectionTimeoutFactor(1);
    config.setHeartBeatInterval(FiniteDuration.create(1, TimeUnit.MILLISECONDS));

    String persistenceId = factory.generateActorId("test-actor-");
    InMemoryJournal.addEntry(persistenceId, 1,  new SimpleReplicatedLogEntry(0, 1,
            new ServerConfigurationPayload(Arrays.asList(new ServerInfo(persistenceId, false)))));

    TestActorRef<MockRaftActor> raftActorRef = factory.createTestActor(MockRaftActor.builder().id(persistenceId)
            .config(config).props().withDispatcher(Dispatchers.DefaultDispatcherId()), persistenceId);
    MockRaftActor mockRaftActor = raftActorRef.underlyingActor();

    mockRaftActor.waitForInitializeBehaviorComplete();

    // Sleep a bit and verify it didn't get an election timeout and schedule an election.

    Uninterruptibles.sleepUninterruptibly(400, TimeUnit.MILLISECONDS);
    assertEquals("getRaftState", RaftState.Follower, mockRaftActor.getRaftState());

    TEST_LOG.info("testNonVotingOnRecovery ending");
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:RaftActorTest.java

示例4: 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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:TestActorFactory.java

示例5: testRemoveServerWithNoLeader

import akka.testkit.TestActorRef; //导入依赖的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");
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:22,代码来源:RaftActorServerConfigurationSupportTest.java

示例6: testRemoveServerForwardToLeader

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testRemoveServerForwardToLeader() {
    LOG.info("testRemoveServerForwardToLeader starting");

    DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl();
    configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));

    ActorRef leaderActor = actorFactory.createTestActor(
            MessageCollectorActor.props(), actorFactory.generateActorId(LEADER_ID));

    TestActorRef<MockRaftActor> followerRaftActor = actorFactory.createTestActor(
            MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(ImmutableMap.of(LEADER_ID,
                    leaderActor.path().toString())).config(configParams).persistent(Optional.of(false))
                    .props().withDispatcher(Dispatchers.DefaultDispatcherId()),
            actorFactory.generateActorId(FOLLOWER_ID));
    followerRaftActor.underlyingActor().waitForInitializeBehaviorComplete();

    followerRaftActor.tell(new AppendEntries(1, LEADER_ID, 0, 1, Collections.<ReplicatedLogEntry>emptyList(),
            -1, -1, (short)0), leaderActor);

    followerRaftActor.tell(new RemoveServer(FOLLOWER_ID), testKit.getRef());
    expectFirstMatching(leaderActor, RemoveServer.class);

    LOG.info("testRemoveServerForwardToLeader ending");
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:RaftActorServerConfigurationSupportTest.java

示例7: testRemoveServerLeaderWithNoFollowers

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testRemoveServerLeaderWithNoFollowers() {
    LOG.info("testRemoveServerLeaderWithNoFollowers starting");

    TestActorRef<MockLeaderRaftActor> leaderActor = actorFactory.createTestActor(
            MockLeaderRaftActor.props(Collections.<String, String>emptyMap(),
                    new MockRaftActorContext()).withDispatcher(Dispatchers.DefaultDispatcherId()),
            actorFactory.generateActorId(LEADER_ID));

    leaderActor.tell(new RemoveServer(LEADER_ID), testKit.getRef());
    RemoveServerReply removeServerReply = testKit.expectMsgClass(JavaTestKit.duration("5 seconds"),
            RemoveServerReply.class);
    assertEquals("getStatus", ServerChangeStatus.NOT_SUPPORTED, removeServerReply.getStatus());

    LOG.info("testRemoveServerLeaderWithNoFollowers ending");
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:RaftActorServerConfigurationSupportTest.java

示例8: testOnDatastoreContext

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testOnDatastoreContext() {
    new ShardTestKit(getSystem()) {
        {
            dataStoreContextBuilder.persistent(true);

            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps(),
                    "testOnDatastoreContext");

            assertEquals("isRecoveryApplicable", true,
                    shard.underlyingActor().persistence().isRecoveryApplicable());

            waitUntilLeader(shard);

            shard.tell(dataStoreContextBuilder.persistent(false).build(), ActorRef.noSender());

            assertEquals("isRecoveryApplicable", false,
                    shard.underlyingActor().persistence().isRecoveryApplicable());

            shard.tell(dataStoreContextBuilder.persistent(true).build(), ActorRef.noSender());

            assertEquals("isRecoveryApplicable", true,
                    shard.underlyingActor().persistence().isRecoveryApplicable());
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:27,代码来源:ShardTest.java

示例9: testOnEntityOwnershipChanged

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testOnEntityOwnershipChanged() {
    DOMEntityOwnershipListener mockListener = mock(DOMEntityOwnershipListener.class);

    TestActorRef<EntityOwnershipListenerActor> listenerActor = actorFactory.createTestActor(
            EntityOwnershipListenerActor.props(mockListener), actorFactory.generateActorId("listener"));

    DOMEntity entity = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id1")));
    boolean wasOwner = false;
    boolean isOwner = true;
    boolean hasOwner = true;
    listenerActor.tell(new DOMEntityOwnershipChange(entity, EntityOwnershipChangeState.from(
            wasOwner, isOwner, hasOwner)), ActorRef.noSender());

    verify(mockListener, timeout(5000)).ownershipChanged(ownershipChange(entity, wasOwner, isOwner, hasOwner));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:EntityOwnershipListenerActorTest.java

示例10: testOnEntityOwnershipChangedWithListenerEx

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testOnEntityOwnershipChangedWithListenerEx() {
    DOMEntityOwnershipListener mockListener = mock(DOMEntityOwnershipListener.class);

    DOMEntity entity1 = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id1")));
    doThrow(new RuntimeException("mock")).when(mockListener).ownershipChanged(
            ownershipChange(entity1, false, true, true));
    DOMEntity entity2 = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id2")));
    doNothing().when(mockListener).ownershipChanged(ownershipChange(entity2, true, false, false));

    TestActorRef<EntityOwnershipListenerActor> listenerActor = actorFactory.createTestActor(
            EntityOwnershipListenerActor.props(mockListener), actorFactory.generateActorId("listener"));

    listenerActor.tell(new DOMEntityOwnershipChange(entity1, EntityOwnershipChangeState.from(
            false, true, true)), ActorRef.noSender());
    listenerActor.tell(new DOMEntityOwnershipChange(entity2, EntityOwnershipChangeState.from(
            true, false, false)), ActorRef.noSender());

    verify(mockListener, timeout(5000)).ownershipChanged(ownershipChange(entity2, true, false, false));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:EntityOwnershipListenerActorTest.java

示例11: verifyRaftState

import akka.testkit.TestActorRef; //导入依赖的package包/类
static void verifyRaftState(final TestActorRef<? extends EntityOwnershipShard> shard,
        Consumer<OnDemandRaftState> verifier)
        throws Exception {
    AssertionError lastError = null;
    Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        FiniteDuration operationDuration = Duration.create(5, TimeUnit.SECONDS);
        Future<Object> future = Patterns.ask(shard, GetOnDemandRaftState.INSTANCE, new Timeout(operationDuration));
        OnDemandRaftState raftState = (OnDemandRaftState)Await.result(future, operationDuration);
        try {
            verifier.accept(raftState);
            return;
        } catch (AssertionError e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        }
    }

    throw lastError;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:AbstractEntityOwnershipTest.java

示例12: testNegativeReadWithReadOnlyTransactionClosed

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadOnlyTransactionClosed() throws Exception {

    final ActorRef shard = createShard();
    final Props props = ShardTransaction.props(RO, STORE.newReadOnlyTransaction(nextTransactionId()), shard,
            datastoreContext, shardStats);

    final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props,
            "testNegativeReadWithReadOnlyTransactionClosed");

    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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:ShardTransactionFailureTest.java

示例13: 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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:ShardTransactionFailureTest.java

示例14: 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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:21,代码来源:ShardTransactionFailureTest.java

示例15: testChangeListenerWithNoInitialData

import akka.testkit.TestActorRef; //导入依赖的package包/类
@Test
public void testChangeListenerWithNoInitialData() throws Exception {

    new ShardTestKit(getSystem()) {
        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(
                    newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
                    "testChangeListenerWithNoInitialData");

            waitUntilLeader(actor);

            final Shard shard = actor.underlyingActor();
            final MockDataChangeListener listener = new MockDataChangeListener(0);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, TEST_PATH),
                    "testChangeListenerWithNoInitialData-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false),
                    true,true);

            listener.expectNoMoreChanges("Unexpected initial change event");
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:DataChangeListenerSupportTest.java


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