Search in sources :

Example 1 with CreateTransactionReply

use of org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply in project controller by opendaylight.

the class ShardTest method testCreateTransaction.

@Test
public void testCreateTransaction() {
    new ShardTestKit(getSystem()) {

        {
            final ActorRef shard = actorFactory.createActor(newShardProps(), "testCreateTransaction");
            waitUntilLeader(shard);
            shard.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shard.tell(new CreateTransaction(nextTransactionId(), TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
            final CreateTransactionReply reply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
            final String path = reply.getTransactionPath().toString();
            assertTrue("Unexpected transaction path " + path, path.startsWith(String.format("akka://test/user/testCreateTransaction/shard-%s-%s:ShardTransactionTest@0:", shardID.getShardName(), shardID.getMemberName().getName())));
        }
    };
}
Also used : CreateTransaction(org.opendaylight.controller.cluster.datastore.messages.CreateTransaction) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) Test(org.junit.Test)

Example 2 with CreateTransactionReply

use of org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply in project controller by opendaylight.

the class ShardTest method testCreateTransactionOnChain.

@Test
public void testCreateTransactionOnChain() {
    new ShardTestKit(getSystem()) {

        {
            final ActorRef shard = actorFactory.createActor(newShardProps(), "testCreateTransactionOnChain");
            waitUntilLeader(shard);
            shard.tell(new CreateTransaction(nextTransactionId(), TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
            final CreateTransactionReply reply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
            final String path = reply.getTransactionPath().toString();
            assertTrue("Unexpected transaction path " + path, path.startsWith(String.format("akka://test/user/testCreateTransactionOnChain/shard-%s-%s:ShardTransactionTest@0:", shardID.getShardName(), shardID.getMemberName().getName())));
        }
    };
}
Also used : CreateTransaction(org.opendaylight.controller.cluster.datastore.messages.CreateTransaction) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) Test(org.junit.Test)

Example 3 with CreateTransactionReply

use of org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply in project controller by opendaylight.

the class Shard method createTransaction.

@SuppressWarnings("checkstyle:IllegalCatch")
private void createTransaction(final CreateTransaction createTransaction) {
    try {
        if (TransactionType.fromInt(createTransaction.getTransactionType()) != TransactionType.READ_ONLY && failIfIsolatedLeader(getSender())) {
            return;
        }
        ActorRef transactionActor = createTransaction(createTransaction.getTransactionType(), createTransaction.getTransactionId());
        getSender().tell(new CreateTransactionReply(Serialization.serializedActorPath(transactionActor), createTransaction.getTransactionId(), createTransaction.getVersion()).toSerializable(), getSelf());
    } catch (Exception e) {
        getSender().tell(new Failure(e), getSelf());
    }
}
Also used : ActorRef(akka.actor.ActorRef) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) RetiredGenerationException(org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) LeadershipTransferFailedException(org.opendaylight.controller.cluster.raft.LeadershipTransferFailedException) IOException(java.io.IOException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) OutOfSequenceEnvelopeException(org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) Failure(akka.actor.Status.Failure)

Example 4 with CreateTransactionReply

use of org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply in project controller by opendaylight.

the class ShardTest method testBatchedModificationsOnTransactionChain.

@Test
public void testBatchedModificationsOnTransactionChain() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsOnTransactionChain");
            waitUntilLeader(shard);
            final LocalHistoryIdentifier historyId = nextHistoryId();
            final TransactionIdentifier transactionID1 = new TransactionIdentifier(historyId, 0);
            final TransactionIdentifier transactionID2 = new TransactionIdentifier(historyId, 1);
            final FiniteDuration duration = duration("5 seconds");
            // Send a BatchedModifications to start a chained write
            // transaction and ready it.
            final ContainerNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            shard.tell(newBatchedModifications(transactionID1, path, containerNode, true, false, 1), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // Create a read Tx on the same chain.
            shard.tell(new CreateTransaction(transactionID2, TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
            final CreateTransactionReply createReply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
            getSystem().actorSelection(createReply.getTransactionPath()).tell(new ReadData(path, DataStoreVersions.CURRENT_VERSION), getRef());
            final ReadDataReply readReply = expectMsgClass(duration("3 seconds"), ReadDataReply.class);
            assertEquals("Read node", containerNode, readReply.getNormalizedNode());
            // Commit the write transaction.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(duration, CanCommitTransactionReply.class));
            assertEquals("Can commit", true, canCommitReply.getCanCommit());
            shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CommitTransactionReply.class);
            // Verify data in the data store.
            final NormalizedNode<?, ?> actualNode = readStore(shard, path);
            assertEquals("Stored node", containerNode, actualNode);
        }
    };
}
Also used : CreateTransaction(org.opendaylight.controller.cluster.datastore.messages.CreateTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ReadDataReply(org.opendaylight.controller.cluster.datastore.messages.ReadDataReply) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Example 5 with CreateTransactionReply

use of org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply 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)

Aggregations

CreateTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply)5 ActorRef (akka.actor.ActorRef)4 Test (org.junit.Test)3 CreateTransaction (org.opendaylight.controller.cluster.datastore.messages.CreateTransaction)3 TestActorRef (akka.testkit.TestActorRef)2 ActorSystem (akka.actor.ActorSystem)1 Failure (akka.actor.Status.Failure)1 Timeout (akka.util.Timeout)1 IOException (java.io.IOException)1 Matchers.anyString (org.mockito.Matchers.anyString)1 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)1 OutOfSequenceEnvelopeException (org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException)1 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)1 RetiredGenerationException (org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException)1 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)1 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)1 PrimaryNotFoundException (org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException)1