Search in sources :

Example 76 with ActorSystem

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

the class ActorContextTest method testClientDispatcherIsNotGlobalDispatcher.

@Test
public void testClientDispatcherIsNotGlobalDispatcher() {
    ActorSystem actorSystem = ActorSystem.create("with-custom-dispatchers", ConfigFactory.load("application-with-custom-dispatchers.conf"));
    ActorContext actorContext = new ActorContext(actorSystem, mock(ActorRef.class), mock(ClusterWrapper.class), mock(Configuration.class), DatastoreContext.newBuilder().build(), new PrimaryShardInfoFutureCache());
    assertNotEquals(actorSystem.dispatchers().defaultGlobalDispatcher(), actorContext.getClientDispatcher());
    actorSystem.terminate();
}
Also used : ActorSystem(akka.actor.ActorSystem) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 77 with ActorSystem

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

the class DistributedDataStoreRemotingIntegrationTest method testWriteTransactionWithSingleShard.

@Test
public void testWriteTransactionWithSingleShard() throws Exception {
    final String testName = "testWriteTransactionWithSingleShard";
    initDatastoresWithCars(testName);
    final String followerCarShardName = "member-2-shard-cars-" + testName;
    DOMStoreWriteTransaction writeTx = followerDistributedDataStore.newWriteOnlyTransaction();
    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
    writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
    writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    final YangInstanceIdentifier car1Path = CarsModel.newCarPath("optima");
    writeTx.merge(car1Path, car1);
    final MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(25000));
    final YangInstanceIdentifier car2Path = CarsModel.newCarPath("sportage");
    writeTx.merge(car2Path, car2);
    followerTestKit.doCommit(writeTx.ready());
    verifyCars(followerDistributedDataStore.newReadOnlyTransaction(), car1, car2);
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
    // Test delete
    writeTx = followerDistributedDataStore.newWriteOnlyTransaction();
    writeTx.delete(car1Path);
    followerTestKit.doCommit(writeTx.ready());
    verifyExists(followerDistributedDataStore.newReadOnlyTransaction(), car2Path);
    verifyCars(followerDistributedDataStore.newReadOnlyTransaction(), car2);
    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car2);
    // Re-instate the follower member 2 as a single-node to verify replication and recovery.
    // The following is a bit tricky. Before we reinstate the follower we need to ensure it has persisted and
    // applied and all the log entries from the leader. Since we've verified the car data above we know that
    // all the transactions have been applied on the leader so we first read and capture its lastAppliedIndex.
    final AtomicLong leaderLastAppliedIndex = new AtomicLong();
    IntegrationTestKit.verifyShardState(leaderDistributedDataStore, CARS[0], state -> leaderLastAppliedIndex.set(state.getLastApplied()));
    // Now we need to make sure the follower has persisted the leader's lastAppliedIndex via ApplyJournalEntries.
    // However we don't know exactly how many ApplyJournalEntries messages there will be as it can differ between
    // the tell-based and ask-based front-ends. For ask-based there will be exactly 2 ApplyJournalEntries but
    // tell-based persists additional payloads which could be replicated and applied in a batch resulting in
    // either 2 or 3 ApplyJournalEntries. To handle this we read the follower's persisted ApplyJournalEntries
    // until we find the one that encompasses the leader's lastAppliedIndex.
    Stopwatch sw = Stopwatch.createStarted();
    boolean done = false;
    while (!done) {
        final List<ApplyJournalEntries> entries = InMemoryJournal.get(followerCarShardName, ApplyJournalEntries.class);
        for (ApplyJournalEntries aje : entries) {
            if (aje.getToIndex() >= leaderLastAppliedIndex.get()) {
                done = true;
                break;
            }
        }
        assertTrue("Follower did not persist ApplyJournalEntries containing leader's lastAppliedIndex " + leaderLastAppliedIndex + ". Entries persisted: " + entries, sw.elapsed(TimeUnit.SECONDS) <= 5);
        Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
    }
    TestKit.shutdownActorSystem(leaderSystem, Boolean.TRUE);
    TestKit.shutdownActorSystem(followerSystem, Boolean.TRUE);
    final ActorSystem newSystem = newActorSystem("reinstated-member2", "Member2");
    try (AbstractDataStore member2Datastore = new IntegrationTestKit(newSystem, leaderDatastoreContextBuilder, commitTimeout).setupAbstractDataStore(testParameter, testName, "module-shards-member2", true, CARS)) {
        verifyCars(member2Datastore.newReadOnlyTransaction(), car2);
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) AtomicLong(java.util.concurrent.atomic.AtomicLong) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) Stopwatch(com.google.common.base.Stopwatch) AddressFromURIString(akka.actor.AddressFromURIString) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 78 with ActorSystem

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

the class TransactionProxyTest method completeOperationLocal.

private void completeOperationLocal(final TransactionProxyOperation operation, final DataTree dataTree) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
    doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, dataTree))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    long start = System.nanoTime();
    operation.run(transactionProxy);
    long end = System.nanoTime();
    long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInMillis());
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s", expected, end - start), end - start <= expected);
}
Also used : ActorSystem(akka.actor.ActorSystem) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef)

Example 79 with ActorSystem

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

the class TransactionProxyTest method completeOperation.

private void completeOperation(final TransactionProxyOperation operation, final boolean shardFound) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    } else {
        doReturn(Futures.failed(new PrimaryNotFoundException("test"))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }
    ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    String actorPath = txActorRef.path().toString();
    CreateTransactionReply createTransactionReply = new CreateTransactionReply(actorPath, nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
    doReturn(actorSystem.actorSelection(actorPath)).when(mockActorContext).actorSelection(actorPath);
    doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE), any(Timeout.class));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    long start = System.nanoTime();
    operation.run(transactionProxy);
    long end = System.nanoTime();
    long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext().getOperationTimeoutInMillis());
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s", expected, end - start), end - start <= expected);
}
Also used : ActorSystem(akka.actor.ActorSystem) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) Matchers.anyString(org.mockito.Matchers.anyString)

Example 80 with ActorSystem

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

the class TransactionProxyTest method throttleOperation.

private void throttleOperation(final TransactionProxyOperation operation, final int outstandingOpsLimit, final boolean shardFound, final long expectedCompletionTime) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    // Note that we setting batchedModificationCount to one less than what we need because in TransactionProxy
    // we now allow one extra permit to be allowed for ready
    doReturn(dataStoreContextBuilder.operationTimeoutInSeconds(2).shardBatchedModificationCount(outstandingOpsLimit - 1).build()).when(mockActorContext).getDatastoreContext();
    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext).findPrimaryShardAsync(eq("cars"));
    } else {
        doReturn(Futures.failed(new Exception("not found"))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }
    doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE), any(Timeout.class));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    long start = System.nanoTime();
    operation.run(transactionProxy);
    long end = System.nanoTime();
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s", expectedCompletionTime, end - start), end - start > expectedCompletionTime && end - start < expectedCompletionTime * 2);
}
Also used : ActorSystem(akka.actor.ActorSystem) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) TimeoutException(org.opendaylight.controller.cluster.datastore.exceptions.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ActorSystem (akka.actor.ActorSystem)91 ActorRef (akka.actor.ActorRef)54 Test (org.junit.Test)51 Configuration (org.apache.flink.configuration.Configuration)27 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 File (java.io.File)11 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)11 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)11 Props (akka.actor.Props)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 TestActorRef (akka.testkit.TestActorRef)8 IOException (java.io.IOException)8 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Deadline (scala.concurrent.duration.Deadline)8 AddressFromURIString (akka.actor.AddressFromURIString)7 ActorMaterializer (akka.stream.ActorMaterializer)7 Materializer (akka.stream.Materializer)7 Sink (akka.stream.javadsl.Sink)7 Source (akka.stream.javadsl.Source)7