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();
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations