Search in sources :

Example 11 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class ModuleShardBackendResolverTest method createActorContextMock.

private static ActorContext createActorContextMock(final ActorSystem system, final ActorRef actor) {
    final ActorContext mock = mock(ActorContext.class);
    final Promise<PrimaryShardInfo> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
    final ActorSelection selection = system.actorSelection(actor.path());
    final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
    promise.success(shardInfo);
    when(mock.findPrimaryShardAsync("default")).thenReturn(promise.future());
    return mock;
}
Also used : ActorSelection(akka.actor.ActorSelection) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Example 12 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class ConnectClientSuccessProxyV1 method writeExternal.

@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    super.writeExternal(out);
    out.writeObject(Serialization.serializedActorPath(backend));
    out.writeInt(maxMessages);
    out.writeInt(alternates.size());
    for (ActorSelection b : alternates) {
        out.writeObject(b.toSerializationFormat());
    }
}
Also used : ActorSelection(akka.actor.ActorSelection)

Example 13 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method testForwardedReadyTransactionForwardedToLeader.

@SuppressWarnings("unchecked")
@Test
public void testForwardedReadyTransactionForwardedToLeader() throws Exception {
    initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
    followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");
    final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars");
    assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());
    carsFollowerShard.get().tell(GetShardDataTree.INSTANCE, followerTestKit.getRef());
    final DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);
    // Send a tx with immediate commit.
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
    new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);
    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
    ForwardedReadyTransaction forwardedReady = new ForwardedReadyTransaction(tx1, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx1, modification), true);
    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    Object resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
    }
    assertEquals("Response type", CommitTransactionReply.class, resp.getClass());
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1);
    // Send another tx without immediate commit.
    modification = dataTree.takeSnapshot().newModification();
    MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000));
    new WriteModification(CarsModel.newCarPath("sportage"), car2).apply(modification);
    forwardedReady = new ForwardedReadyTransaction(tx2, DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(Mockito.mock(ShardDataTreeTransactionParent.class), tx2, modification), false);
    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure) resp).cause());
    }
    assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());
    ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(((ReadyTransactionReply) resp).getCohortPath());
    final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
    Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
    final ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(leaderDistributedDataStore.getActorContext(), Arrays.asList(new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
    cohort.canCommit().get(5, TimeUnit.SECONDS);
    cohort.preCommit().get(5, TimeUnit.SECONDS);
    cohort.commit().get(5, TimeUnit.SECONDS);
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ActorSelection(akka.actor.ActorSelection) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ForwardedReadyTransaction(org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction) Test(org.junit.Test)

Example 14 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class DataTreeChangeListenerSupportTest method testInitialChangeListenerEventWithContainerPath.

@Test
public void testInitialChangeListenerEventWithContainerPath() throws DataValidationFailedException {
    writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
    Entry<MockDataTreeChangeListener, ActorSelection> entry = registerChangeListener(TEST_PATH, 1);
    MockDataTreeChangeListener listener = entry.getKey();
    listener.waitForChangeEvents();
    listener.verifyNotifiedData(TEST_PATH);
    listener.reset(1);
    writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
    listener.waitForChangeEvents();
    listener.verifyNotifiedData(TEST_PATH);
    listener.reset(1);
    TestKit kit = new TestKit(getSystem());
    entry.getValue().tell(CloseDataTreeNotificationListenerRegistration.getInstance(), kit.getRef());
    kit.expectMsgClass(kit.duration("5 seconds"), CloseDataTreeNotificationListenerRegistrationReply.class);
    writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
    listener.verifyNoNotifiedData(TEST_PATH);
}
Also used : MockDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener) ActorSelection(akka.actor.ActorSelection) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 15 with ActorSelection

use of akka.actor.ActorSelection in project controller by opendaylight.

the class ActorContextTest method testExecuteRemoteOperationAsync.

@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testExecuteRemoteOperationAsync() {
    new TestKit(getSystem()) {

        {
            ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
            ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(true, shardActorRef));
            ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, mock(ClusterWrapper.class), mock(Configuration.class));
            ActorSelection actor = actorContext.actorSelection(shardActorRef.path());
            Future<Object> future = actorContext.executeOperationAsync(actor, "hello");
            try {
                Object result = Await.result(future, Duration.create(3, TimeUnit.SECONDS));
                assertEquals("Result", "hello", result);
            } catch (Exception e) {
                throw new AssertionError(e);
            }
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorSelection(akka.actor.ActorSelection) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) EchoActor(org.opendaylight.controller.cluster.raft.utils.EchoActor) TestKit(akka.testkit.javadsl.TestKit) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Aggregations

ActorSelection (akka.actor.ActorSelection)43 ActorRef (akka.actor.ActorRef)9 Test (org.junit.Test)6 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)5 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)4 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)4 InvalidActorNameException (akka.actor.InvalidActorNameException)3 Status (akka.actor.Status)3 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 Timeout (akka.util.Timeout)3 ArrayList (java.util.ArrayList)3 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)3 AkkaException (akka.AkkaException)2 ActorIdentity (akka.actor.ActorIdentity)2 Identify (akka.actor.Identify)2 Failure (akka.actor.Status.Failure)2 Success (akka.actor.Status.Success)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)2