Search in sources :

Example 56 with TestKit

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

the class ActorContextTest method testBroadcast.

@Test
public void testBroadcast() {
    new TestKit(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);
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) TestKit(akka.testkit.javadsl.TestKit) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 57 with TestKit

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

the class RpcBrokerTest method testExecuteRpcFailureWithException.

@Test
public void testExecuteRpcFailureWithException() {
    new TestKit(node1) {

        {
            when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("NOT FOUND")));
            final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
            rpcInvoker1.tell(executeMsg, getRef());
            final Failure rpcResponse = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            Assert.assertTrue(rpcResponse.cause() instanceof DOMRpcException);
        }
    };
}
Also used : DOMRpcImplementationNotAvailableException(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException) ExecuteRpc(org.opendaylight.controller.remote.rpc.messages.ExecuteRpc) TestKit(akka.testkit.javadsl.TestKit) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 58 with TestKit

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

the class RpcBrokerTest method testExecuteRpc.

@Test
public void testExecuteRpc() {
    new TestKit(node1) {

        {
            final ContainerNode invokeRpcResult = makeRPCOutput("bar");
            final DOMRpcResult rpcResult = new DefaultDOMRpcResult(invokeRpcResult);
            when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
            final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
            rpcInvoker1.tell(executeMsg, getRef());
            final RpcResponse rpcResponse = expectMsgClass(duration("5 seconds"), RpcResponse.class);
            assertEquals(rpcResult.getResult(), rpcResponse.getResultNormalizedNode());
        }
    };
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ExecuteRpc(org.opendaylight.controller.remote.rpc.messages.ExecuteRpc) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) TestKit(akka.testkit.javadsl.TestKit) RpcResponse(org.opendaylight.controller.remote.rpc.messages.RpcResponse) Test(org.junit.Test)

Example 59 with TestKit

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

the class RpcRegistrarTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.create("test");
    final TestKit testKit = new TestKit(system);
    final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build();
    final Props props = RpcRegistrar.props(config, service);
    testActorRef = new TestActorRef<>(system, props, testKit.getRef(), "actorRef");
    endpointAddress = new Address("http", "local");
    final DOMRpcIdentifier firstEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("first:identifier", "foo")));
    final DOMRpcIdentifier secondEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("second:identifier", "bar")));
    final TestKit senderKit = new TestKit(system);
    firstEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(firstEndpointId));
    secondEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(secondEndpointId));
    Mockito.doReturn(oldReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(firstEndpoint.getRpcs()));
    Mockito.doReturn(newReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(secondEndpoint.getRpcs()));
    rpcRegistrar = testActorRef.underlyingActor();
}
Also used : Address(akka.actor.Address) RemoteRpcEndpoint(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint) DOMRpcIdentifier(org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) Before(org.junit.Before)

Example 60 with TestKit

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

the class RpcRegistryTest method testRpcAddedOnMultiNodes.

/**
 * Three node cluster. Register rpc on 2 nodes. Ensure 3rd gets updated.
 */
@Test
public void testRpcAddedOnMultiNodes() throws Exception {
    final TestKit testKit = new TestKit(node3);
    // Add rpc on node 1
    List<DOMRpcIdentifier> addedRouteIds1 = createRouteIds();
    registry1.tell(new AddOrUpdateRoutes(addedRouteIds1), ActorRef.noSender());
    final UpdateRemoteEndpoints req1 = registrar3.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), UpdateRemoteEndpoints.class);
    // Add rpc on node 2
    List<DOMRpcIdentifier> addedRouteIds2 = createRouteIds();
    registry2.tell(new AddOrUpdateRoutes(addedRouteIds2), ActorRef.noSender());
    final UpdateRemoteEndpoints req2 = registrar3.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), UpdateRemoteEndpoints.class);
    Address node2Address = node2.provider().getDefaultAddress();
    Address node1Address = node1.provider().getDefaultAddress();
    Map<Address, Bucket<RoutingTable>> buckets = retrieveBuckets(registry3, testKit, node1Address, node2Address);
    verifyBucket(buckets.get(node1Address), addedRouteIds1);
    verifyBucket(buckets.get(node2Address), addedRouteIds2);
    Map<Address, Long> versions = retrieveVersions(registry3, testKit);
    Assert.assertEquals("Version for bucket " + node1Address, (Long) buckets.get(node1Address).getVersion(), versions.get(node1Address));
    Assert.assertEquals("Version for bucket " + node2Address, (Long) buckets.get(node2Address).getVersion(), versions.get(node2Address));
    assertEndpoints(req1, node1Address, invoker1);
    assertEndpoints(req2, node2Address, invoker2);
}
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) UpdateRemoteEndpoints(org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints) 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