Search in sources :

Example 61 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class RpcRegistryTest method setup.

@Before
public void setup() {
    invoker1 = new TestKit(node1);
    registrar1 = new TestKit(node1);
    registry1 = node1.actorOf(RpcRegistry.props(config(node1), invoker1.getRef(), registrar1.getRef()));
    invoker2 = new TestKit(node2);
    registrar2 = new TestKit(node2);
    registry2 = node2.actorOf(RpcRegistry.props(config(node2), invoker2.getRef(), registrar2.getRef()));
    invoker3 = new TestKit(node3);
    registrar3 = new TestKit(node3);
    registry3 = node3.actorOf(RpcRegistry.props(config(node3), invoker3.getRef(), registrar3.getRef()));
}
Also used : TestKit(akka.testkit.javadsl.TestKit) Before(org.junit.Before)

Example 62 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class RpcRegistryTest method testRpcAddRemoveInCluster.

/**
 * Three node cluster. 1. Register rpc on 1 node, ensure 2nd node gets updated 2. Remove rpc on
 * 1 node, ensure 2nd node gets updated
 */
@Test
public void testRpcAddRemoveInCluster() throws Exception {
    LOG.info("testRpcAddRemoveInCluster starting");
    List<DOMRpcIdentifier> addedRouteIds = createRouteIds();
    Address node1Address = node1.provider().getDefaultAddress();
    // Add rpc on node 1
    registry1.tell(new AddOrUpdateRoutes(addedRouteIds), ActorRef.noSender());
    // Bucket store on node2 should get a message to update its local copy of remote buckets
    final TestKit testKit = new TestKit(node2);
    Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry2, testKit, node1Address);
    verifyBucket(buckets.get(node1Address), addedRouteIds);
    // Now remove
    registry1.tell(new RemoveRoutes(addedRouteIds), ActorRef.noSender());
    // Bucket store on node2 should get a message to update its local copy of remote buckets.
    // Wait for the bucket for node1 to be empty.
    verifyEmptyBucket(testKit, registry2, node1Address);
    LOG.info("testRpcAddRemoveInCluster ending");
}
Also used : UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) AddOrUpdateRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) RemoveRoutes(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.RemoveRoutes) Test(org.junit.Test)

Example 63 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class RemoteRpcRegistryMXBeanImplTest method setUp.

@Before
public void setUp() throws Exception {
    system = ActorSystem.create("test");
    final DOMRpcIdentifier emptyRpcIdentifier = DOMRpcIdentifier.create(EMPTY_SCHEMA_PATH, YangInstanceIdentifier.EMPTY);
    final DOMRpcIdentifier localRpcIdentifier = DOMRpcIdentifier.create(LOCAL_SCHEMA_PATH, YangInstanceIdentifier.of(LOCAL_QNAME));
    buckets = Lists.newArrayList(emptyRpcIdentifier, localRpcIdentifier);
    final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build();
    final TestKit invoker = new TestKit(system);
    final TestKit registrar = new TestKit(system);
    final TestKit supervisor = new TestKit(system);
    final Props props = RpcRegistry.props(config, invoker.getRef(), registrar.getRef()).withDispatcher(Dispatchers.DefaultDispatcherId());
    testActor = new TestActorRef<>(system, props, supervisor.getRef(), "testActor");
    final Timeout timeout = Timeout.apply(10, TimeUnit.SECONDS);
    mxBean = new RemoteRpcRegistryMXBeanImpl(new BucketStoreAccess(testActor, system.dispatcher(), timeout), timeout);
}
Also used : Timeout(akka.util.Timeout) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) RemoteRpcProviderConfig(org.opendaylight.controller.remote.rpc.RemoteRpcProviderConfig) Props(akka.actor.Props) BucketStoreAccess(org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess) Before(org.junit.Before)

Example 64 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class RaftActorTest method testRaftActorRecoveryWithPersistenceEnabled.

@Test
public void testRaftActorRecoveryWithPersistenceEnabled() throws Exception {
    TEST_LOG.info("testRaftActorRecoveryWithPersistenceEnabled starting");
    TestKit kit = new TestKit(getSystem());
    String persistenceId = factory.generateActorId("follower-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    // Set the heartbeat interval high to essentially disable election otherwise the test
    // may fail if the actor is switched to Leader and the commitIndex is set to the last
    // log entry.
    config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    ImmutableMap<String, String> peerAddresses = ImmutableMap.<String, String>builder().put("member1", "address").build();
    ActorRef followerActor = factory.createActor(MockRaftActor.props(persistenceId, peerAddresses, config), persistenceId);
    kit.watch(followerActor);
    List<ReplicatedLogEntry> snapshotUnappliedEntries = new ArrayList<>();
    ReplicatedLogEntry entry1 = new SimpleReplicatedLogEntry(4, 1, new MockRaftActorContext.MockPayload("E"));
    snapshotUnappliedEntries.add(entry1);
    int lastAppliedDuringSnapshotCapture = 3;
    int lastIndexDuringSnapshotCapture = 4;
    // 4 messages as part of snapshot, which are applied to state
    MockSnapshotState snapshotState = new MockSnapshotState(Arrays.asList(new MockRaftActorContext.MockPayload("A"), new MockRaftActorContext.MockPayload("B"), new MockRaftActorContext.MockPayload("C"), new MockRaftActorContext.MockPayload("D")));
    Snapshot snapshot = Snapshot.create(snapshotState, snapshotUnappliedEntries, lastIndexDuringSnapshotCapture, 1, lastAppliedDuringSnapshotCapture, 1, -1, null, null);
    InMemorySnapshotStore.addSnapshot(persistenceId, snapshot);
    // add more entries after snapshot is taken
    List<ReplicatedLogEntry> entries = new ArrayList<>();
    ReplicatedLogEntry entry2 = new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("F", 2));
    ReplicatedLogEntry entry3 = new SimpleReplicatedLogEntry(6, 1, new MockRaftActorContext.MockPayload("G", 3));
    ReplicatedLogEntry entry4 = new SimpleReplicatedLogEntry(7, 1, new MockRaftActorContext.MockPayload("H", 4));
    entries.add(entry2);
    entries.add(entry3);
    entries.add(entry4);
    final int lastAppliedToState = 5;
    final int lastIndex = 7;
    InMemoryJournal.addEntry(persistenceId, 5, entry2);
    // 2 entries are applied to state besides the 4 entries in snapshot
    InMemoryJournal.addEntry(persistenceId, 6, new ApplyJournalEntries(lastAppliedToState));
    InMemoryJournal.addEntry(persistenceId, 7, entry3);
    InMemoryJournal.addEntry(persistenceId, 8, entry4);
    // kill the actor
    followerActor.tell(PoisonPill.getInstance(), null);
    kit.expectMsgClass(kit.duration("5 seconds"), Terminated.class);
    kit.unwatch(followerActor);
    // reinstate the actor
    TestActorRef<MockRaftActor> ref = factory.createTestActor(MockRaftActor.props(persistenceId, peerAddresses, config));
    MockRaftActor mockRaftActor = ref.underlyingActor();
    mockRaftActor.waitForRecoveryComplete();
    RaftActorContext context = mockRaftActor.getRaftActorContext();
    assertEquals("Journal log size", snapshotUnappliedEntries.size() + entries.size(), context.getReplicatedLog().size());
    assertEquals("Journal data size", 10, context.getReplicatedLog().dataSize());
    assertEquals("Last index", lastIndex, context.getReplicatedLog().lastIndex());
    assertEquals("Last applied", lastAppliedToState, context.getLastApplied());
    assertEquals("Commit index", lastAppliedToState, context.getCommitIndex());
    assertEquals("Recovered state size", 6, mockRaftActor.getState().size());
    mockRaftActor.waitForInitializeBehaviorComplete();
    assertEquals("getRaftState", RaftState.Follower, mockRaftActor.getRaftState());
    TEST_LOG.info("testRaftActorRecoveryWithPersistenceEnabled ending");
}
Also used : MockSnapshotState(org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ArrayList(java.util.ArrayList) FiniteDuration(scala.concurrent.duration.FiniteDuration) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) TestKit(akka.testkit.javadsl.TestKit) ByteString(com.google.protobuf.ByteString) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) Test(org.junit.Test)

Example 65 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class RoleChangeListenerActorTest method testRegisterRoleChangeListenerOnStart.

@Test
public void testRegisterRoleChangeListenerOnStart() {
    new TestKit(getSystem()) {

        {
            final LeaderLocationListener listener = mock(LeaderLocationListener.class);
            final Props props = RoleChangeListenerActor.props(getRef(), listener);
            getSystem().actorOf(props, "testRegisterRoleChangeListenerOnStart");
            expectMsgClass(RegisterRoleChangeListener.class);
        }
    };
}
Also used : TestKit(akka.testkit.javadsl.TestKit) LeaderLocationListener(org.opendaylight.controller.cluster.dom.api.LeaderLocationListener) Props(akka.actor.Props) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Aggregations

TestKit (akka.testkit.javadsl.TestKit)124 Test (org.junit.Test)115 ActorRef (akka.actor.ActorRef)84 TestActorRef (akka.testkit.TestActorRef)63 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)44 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AddressFromURIString (akka.actor.AddressFromURIString)28 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)22 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)22 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)17 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)17 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)16 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)16 Props (akka.actor.Props)15 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 Failure (akka.actor.Status.Failure)14 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)14 FiniteDuration (scala.concurrent.duration.FiniteDuration)14 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)13