Search in sources :

Example 1 with CommitTransactionReply

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

the class TransactionProxyTest method testReadyWithNoModifications.

@Test
public void testReadyWithNoModifications() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.read(TestModel.TEST_PATH);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), true, true);
}
Also used : CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 2 with CommitTransactionReply

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

the class TransactionProxyTest method testReadyWithReadWrite.

@Test
public void testReadyWithReadWrite() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.read(TestModel.TEST_PATH);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), true, true, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
    assertEquals("getTotalMessageCount", 1, batchedModifications.get(0).getTotalMessagesSent());
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 3 with CommitTransactionReply

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

the class TransactionProxyTest method testReadyWithWriteOnlyAndLastBatchEmpty.

@Test
public void testReadyWithWriteOnlyAndLastBatchEmpty() throws Exception {
    dataStoreContextBuilder.shardBatchedModificationCount(1).writeOnlyTransactionOptimizationsEnabled(true);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 2, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
    verifyBatchedModifications(batchedModifications.get(1), true, true);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 4 with CommitTransactionReply

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

the class TransactionProxyTest method testReadyWithDebugContextEnabled.

@Test
public void testReadyWithDebugContextEnabled() throws Exception {
    dataStoreContextBuilder.transactionDebugContextEnabled(true);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.merge(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof DebugThreePhaseCommitCohort);
    verifyCohortFutures((DebugThreePhaseCommitCohort) ready, new CommitTransactionReply().toSerializable());
}
Also used : CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 5 with CommitTransactionReply

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

the class TransactionProxyTest method testReadyWithLocalTransaction.

@Test
public void testReadyWithLocalTransaction() throws Exception {
    ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
    doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
    doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, createDataTree()))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    expectReadyLocalTransaction(shardActorRef, true);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
}
Also used : CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)6 Test (org.junit.Test)6 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)6 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)6 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)6 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)4 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)3 Timeout (akka.util.Timeout)2 DoNothingActor (org.opendaylight.controller.cluster.raft.utils.DoNothingActor)1