Search in sources :

Example 6 with BatchedModifications

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

the class AbstractTransactionProxyTest method verifyBatchedModifications.

protected void verifyBatchedModifications(final Object message, final boolean expIsReady, final boolean expIsDoCommitOnReady, final Modification... expected) {
    assertEquals("Message type", BatchedModifications.class, message.getClass());
    BatchedModifications batchedModifications = (BatchedModifications) message;
    assertEquals("BatchedModifications size", expected.length, batchedModifications.getModifications().size());
    assertEquals("isReady", expIsReady, batchedModifications.isReady());
    assertEquals("isDoCommitOnReady", expIsDoCommitOnReady, batchedModifications.isDoCommitOnReady());
    for (int i = 0; i < batchedModifications.getModifications().size(); i++) {
        Modification actual = batchedModifications.getModifications().get(i);
        assertEquals("Modification type", expected[i].getClass(), actual.getClass());
        assertEquals("getPath", ((AbstractModification) expected[i]).getPath(), ((AbstractModification) actual).getPath());
        if (actual instanceof WriteModification) {
            assertEquals("getData", ((WriteModification) expected[i]).getData(), ((WriteModification) actual).getData());
        }
    }
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) AbstractModification(org.opendaylight.controller.cluster.datastore.modification.AbstractModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 7 with BatchedModifications

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

the class AbstractShardTest method newBatchedModifications.

static BatchedModifications newBatchedModifications(final TransactionIdentifier transactionID, final YangInstanceIdentifier path, final NormalizedNode<?, ?> data, final boolean ready, final boolean doCommitOnReady, final int messagesSent) {
    final BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
    batched.addModification(new WriteModification(path, data));
    batched.setReady(ready);
    batched.setDoCommitOnReady(doCommitOnReady);
    batched.setTotalMessagesSent(messagesSent);
    return batched;
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 8 with BatchedModifications

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

the class AbstractShardTest method writeToStore.

public static void writeToStore(final ShardDataTree store, final YangInstanceIdentifier id, final NormalizedNode<?, ?> node) throws DataValidationFailedException {
    BatchedModifications batched = newBatchedModifications(nextTransactionId(), id, node, true, true, 1);
    DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
    batched.apply(modification);
    store.notifyListeners(commitTransaction(store.getDataTree(), modification));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 9 with BatchedModifications

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

the class AbstractShardTest method mergeToStore.

public void mergeToStore(final ShardDataTree store, final YangInstanceIdentifier id, final NormalizedNode<?, ?> node) throws DataValidationFailedException {
    final BatchedModifications batched = new BatchedModifications(nextTransactionId(), CURRENT_VERSION);
    batched.addModification(new MergeModification(id, node));
    batched.setReady(true);
    batched.setDoCommitOnReady(true);
    batched.setTotalMessagesSent(1);
    DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
    batched.apply(modification);
    store.notifyListeners(commitTransaction(store.getDataTree(), modification));
}
Also used : MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 10 with BatchedModifications

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

Aggregations

BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)31 Test (org.junit.Test)17 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)13 ActorRef (akka.actor.ActorRef)12 Failure (akka.actor.Status.Failure)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)6 TestActorRef (akka.testkit.TestActorRef)5 TestKit (akka.testkit.javadsl.TestKit)5 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)5 Timeout (akka.util.Timeout)4 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)4 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)4 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)4 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)3 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)3 InOrder (org.mockito.InOrder)2 BatchedModificationsReply (org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply)2 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)2