当前位置: 首页>>代码示例>>Java>>正文


Java MergeModification类代码示例

本文整理汇总了Java中org.opendaylight.controller.cluster.datastore.modification.MergeModification的典型用法代码示例。如果您正苦于以下问题:Java MergeModification类的具体用法?Java MergeModification怎么用?Java MergeModification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MergeModification类属于org.opendaylight.controller.cluster.datastore.modification包,在下文中一共展示了MergeModification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRegisterCandidateLocal

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
private void onRegisterCandidateLocal(final RegisterCandidateLocal registerCandidate) {
    LOG.debug("{}: onRegisterCandidateLocal: {}", persistenceId(), registerCandidate);

    NormalizedNode<?, ?> entityOwners = entityOwnersWithCandidate(registerCandidate.getEntity().getType(),
            registerCandidate.getEntity().getIdentifier(), localMemberName.getName());
    commitCoordinator.commitModification(new MergeModification(ENTITY_OWNERS_PATH, entityOwners), this);

    getSender().tell(SuccessReply.INSTANCE, getSelf());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:EntityOwnershipShard.java

示例2: testToAndFromBinary

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testToAndFromBinary() {
    TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
    dataTree.setSchemaContext(TestModel.createTestContext());
    DataTreeModification modification = dataTree.takeSnapshot().newModification();

    ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
    MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
    new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);

    TransactionIdentifier txId = nextTransactionId();
    ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);

    ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer();

    byte[] bytes = serializer.toBinary(readyMessage);

    Object deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);

    assertNotNull("fromBinary returned null", deserialized);
    assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
    BatchedModifications batched = (BatchedModifications)deserialized;
    assertEquals("getTransactionID", txId, batched.getTransactionId());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());

    List<Modification> batchedMods = batched.getModifications();
    assertEquals("getModifications size", 2, batchedMods.size());

    Modification mod = batchedMods.get(0);
    assertEquals("Modification type", WriteModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification)mod).getPath());
    assertEquals("Modification getData", writeData, ((WriteModification)mod).getData());

    mod = batchedMods.get(1);
    assertEquals("Modification type", MergeModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification)mod).getPath());
    assertEquals("Modification getData", mergeData, ((MergeModification)mod).getData());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:40,代码来源:ReadyLocalTransactionSerializerTest.java

示例3: testMerge

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testMerge() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
    localTransactionContext.executeModification(new MergeModification(yangInstanceIdentifier, normalizedNode));
    verify(readWriteTransaction).merge(yangInstanceIdentifier, normalizedNode);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:8,代码来源:LocalTransactionContextTest.java

示例4: testReadyWithMergeError

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testReadyWithMergeError() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
    RuntimeException error = new RuntimeException("mock");
    doThrow(error).when(readWriteTransaction).merge(yangInstanceIdentifier, normalizedNode);

    localTransactionContext.executeModification(new MergeModification(yangInstanceIdentifier, normalizedNode));
    localTransactionContext.executeModification(new MergeModification(yangInstanceIdentifier, normalizedNode));

    verify(readWriteTransaction).merge(yangInstanceIdentifier, normalizedNode);

    doReadyWithExpectedError(error);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:15,代码来源:LocalTransactionContextTest.java

示例5: mergeToStore

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
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));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:13,代码来源:AbstractShardTest.java

示例6: testBatchedModificationsWithOperationFailure

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testBatchedModificationsWithOperationFailure() throws Exception {
    new ShardTestKit(getSystem()) {
        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(
                    newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
                    "testBatchedModificationsWithOperationFailure");

            waitUntilLeader(shard);

            // Test merge with invalid data. An exception should occur when
            // the merge is applied. Note that
            // write will not validate the children for performance reasons.

            final TransactionIdentifier transactionID = nextTransactionId();

            final ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
                    .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
                    .withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();

            BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
            batched.addModification(new MergeModification(TestModel.TEST_PATH, invalidData));
            shard.tell(batched, getRef());
            Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);

            final Throwable cause = failure.cause();

            batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);

            shard.tell(batched, getRef());

            failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            assertEquals("Failure cause", cause, failure.cause());
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:39,代码来源:ShardTest.java

示例7: testReadyLocalTransactionWithImmediateCommit

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testReadyLocalTransactionWithImmediateCommit() throws Exception {
    new ShardTestKit(getSystem()) {
        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(
                    newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
                    "testReadyLocalTransactionWithImmediateCommit");

            waitUntilLeader(shard);

            final ShardDataTree dataStore = shard.underlyingActor().getDataStore();

            final DataTreeModification modification = dataStore.newModification();

            final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
            final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
            new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);

            final TransactionIdentifier txId = nextTransactionId();
            modification.ready();
            final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);

            shard.tell(readyMessage, getRef());

            expectMsgClass(CommitTransactionReply.class);

            final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
            assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:33,代码来源:ShardTest.java

示例8: merge

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Override
public final void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
    getModifications().addModification(new MergeModification(current().node(child), data));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:5,代码来源:AbstractBatchedModificationsCursor.java

示例9: merge

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Override
public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
    executeModification(new MergeModification(path, data));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:5,代码来源:TransactionProxy.java

示例10: testSerialization

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testSerialization() {
    YangInstanceIdentifier writePath = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
            new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
            new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();

    YangInstanceIdentifier deletePath = TestModel.TEST_PATH;

    final TransactionIdentifier tx1 = nextTransactionId();
    BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
    batched.addModification(new WriteModification(writePath, writeData));
    batched.addModification(new MergeModification(mergePath, mergeData));
    batched.addModification(new DeleteModification(deletePath));
    batched.setReady(true);
    batched.setTotalMessagesSent(5);

    BatchedModifications clone = (BatchedModifications) SerializationUtils.clone(
            (Serializable) batched.toSerializable());

    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
    assertEquals("getTransactionID", tx1, clone.getTransactionId());
    assertEquals("isReady", true, clone.isReady());
    assertEquals("getTotalMessagesSent", 5, clone.getTotalMessagesSent());

    assertEquals("getModifications size", 3, clone.getModifications().size());

    WriteModification write = (WriteModification)clone.getModifications().get(0);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, write.getVersion());
    assertEquals("getPath", writePath, write.getPath());
    assertEquals("getData", writeData, write.getData());

    MergeModification merge = (MergeModification)clone.getModifications().get(1);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, merge.getVersion());
    assertEquals("getPath", mergePath, merge.getPath());
    assertEquals("getData", mergeData, merge.getData());

    DeleteModification delete = (DeleteModification)clone.getModifications().get(2);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, delete.getVersion());
    assertEquals("getPath", deletePath, delete.getPath());

    // Test with different params.
    final TransactionIdentifier tx2 = nextTransactionId();
    batched = new BatchedModifications(tx2, (short)10000);

    clone = (BatchedModifications) SerializationUtils.clone((Serializable) batched.toSerializable());

    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
    assertEquals("getTransactionID", tx2, clone.getTransactionId());
    assertEquals("isReady", false, clone.isReady());

    assertEquals("getModifications size", 0, clone.getModifications().size());

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:59,代码来源:BatchedModificationsTest.java

示例11: testModificationOperationBatching

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
private void testModificationOperationBatching(final TransactionType type) throws Exception {
    int shardBatchedModificationCount = 3;
    dataStoreContextBuilder.shardBatchedModificationCount(shardBatchedModificationCount);

    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), type);

    expectBatchedModifications(actorRef, shardBatchedModificationCount);

    YangInstanceIdentifier writePath1 = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);

    YangInstanceIdentifier writePath2 = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> writeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);

    YangInstanceIdentifier writePath3 = TestModel.INNER_LIST_PATH;
    NormalizedNode<?, ?> writeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);

    YangInstanceIdentifier mergePath1 = TestModel.TEST_PATH;
    NormalizedNode<?, ?> mergeNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);

    YangInstanceIdentifier mergePath2 = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> mergeNode2 = ImmutableNodes.containerNode(TestModel.OUTER_LIST_QNAME);

    YangInstanceIdentifier mergePath3 = TestModel.INNER_LIST_PATH;
    NormalizedNode<?, ?> mergeNode3 = ImmutableNodes.containerNode(TestModel.INNER_LIST_QNAME);

    YangInstanceIdentifier deletePath1 = TestModel.TEST_PATH;
    YangInstanceIdentifier deletePath2 = TestModel.OUTER_LIST_PATH;

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, type);

    transactionProxy.write(writePath1, writeNode1);
    transactionProxy.write(writePath2, writeNode2);
    transactionProxy.delete(deletePath1);
    transactionProxy.merge(mergePath1, mergeNode1);
    transactionProxy.merge(mergePath2, mergeNode2);
    transactionProxy.write(writePath3, writeNode3);
    transactionProxy.merge(mergePath3, mergeNode3);
    transactionProxy.delete(deletePath2);

    // This sends the last batch.
    transactionProxy.ready();

    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 3, batchedModifications.size());

    verifyBatchedModifications(batchedModifications.get(0), false, new WriteModification(writePath1, writeNode1),
            new WriteModification(writePath2, writeNode2), new DeleteModification(deletePath1));

    verifyBatchedModifications(batchedModifications.get(1), false, new MergeModification(mergePath1, mergeNode1),
            new MergeModification(mergePath2, mergeNode2), new WriteModification(writePath3, writeNode3));

    verifyBatchedModifications(batchedModifications.get(2), true, true,
            new MergeModification(mergePath3, mergeNode3), new DeleteModification(deletePath2));

    assertEquals("getTotalMessageCount", 3, batchedModifications.get(2).getTotalMessagesSent());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:58,代码来源:TransactionProxyTest.java

示例12: testOnReceiveBatchedModifications

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testOnReceiveBatchedModifications() throws Exception {
    new JavaTestKit(getSystem()) {
        {
            ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
            DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
            ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent,
                    nextTransactionId(), mockModification);
            final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModifications");

            YangInstanceIdentifier writePath = TestModel.TEST_PATH;
            NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create()
                    .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
                    .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

            YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
            NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create()
                    .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME))
                    .build();

            YangInstanceIdentifier deletePath = TestModel.TEST_PATH;

            BatchedModifications batched = new BatchedModifications(nextTransactionId(),
                    DataStoreVersions.CURRENT_VERSION);
            batched.addModification(new WriteModification(writePath, writeData));
            batched.addModification(new MergeModification(mergePath, mergeData));
            batched.addModification(new DeleteModification(deletePath));

            transaction.tell(batched, getRef());

            BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"),
                    BatchedModificationsReply.class);
            assertEquals("getNumBatched", 3, reply.getNumBatched());

            InOrder inOrder = Mockito.inOrder(mockModification);
            inOrder.verify(mockModification).write(writePath, writeData);
            inOrder.verify(mockModification).merge(mergePath, mergeData);
            inOrder.verify(mockModification).delete(deletePath);
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:42,代码来源:ShardTransactionTest.java

示例13: testReadyLocalTransactionForwardedToLeader

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testReadyLocalTransactionForwardedToLeader() throws Exception {
    initDatastoresWithCars("testReadyLocalTransactionForwardedToLeader");
    followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");

    final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext()
            .findLocalShard("cars");
    assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());

    final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
    dataTree.setSchemaContext(SchemaContextHelper.full());

    // Send a tx with immediate commit.

    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
    new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);

    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);
    modification.ready();

    ReadyLocalTransaction readyLocal = new ReadyLocalTransaction(tx1 , modification, true);

    carsFollowerShard.get().tell(readyLocal, followerTestKit.getRef());
    Object resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure)resp).cause());
    }

    assertEquals("Response type", CommitTransactionReply.class, resp.getClass());

    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1);

    // Send another tx without immediate commit.

    modification = dataTree.takeSnapshot().newModification();
    MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000));
    new WriteModification(CarsModel.newCarPath("sportage"), car2).apply(modification);
    modification.ready();

    readyLocal = new ReadyLocalTransaction(tx2 , modification, false);

    carsFollowerShard.get().tell(readyLocal, followerTestKit.getRef());
    resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure)resp).cause());
    }

    assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());

    final ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(
            ((ReadyTransactionReply)resp).getCohortPath());

    final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
    Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
    ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(
            leaderDistributedDataStore.getActorContext(), Arrays.asList(
                    new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
    cohort.canCommit().get(5, TimeUnit.SECONDS);
    cohort.preCommit().get(5, TimeUnit.SECONDS);
    cohort.commit().get(5, TimeUnit.SECONDS);

    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:67,代码来源:DistributedDataStoreRemotingIntegrationTest.java

示例14: testForwardedReadyTransactionForwardedToLeader

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testForwardedReadyTransactionForwardedToLeader() throws Exception {
    initDatastoresWithCars("testForwardedReadyTransactionForwardedToLeader");
    followerTestKit.waitUntilLeader(followerDistributedDataStore.getActorContext(), "cars");

    final Optional<ActorRef> carsFollowerShard = followerDistributedDataStore.getActorContext()
            .findLocalShard("cars");
    assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent());

    carsFollowerShard.get().tell(GetShardDataTree.INSTANCE, followerTestKit.getRef());
    final DataTree dataTree = followerTestKit.expectMsgClass(DataTree.class);

    // Send a tx with immediate commit.

    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    new WriteModification(CarsModel.BASE_PATH, CarsModel.emptyContainer()).apply(modification);
    new MergeModification(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()).apply(modification);

    final MapEntryNode car1 = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
    new WriteModification(CarsModel.newCarPath("optima"), car1).apply(modification);

    ForwardedReadyTransaction forwardedReady = new ForwardedReadyTransaction(tx1,
            DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(
                    Mockito.mock(ShardDataTreeTransactionParent.class), tx1, modification), true);

    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    Object resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure)resp).cause());
    }

    assertEquals("Response type", CommitTransactionReply.class, resp.getClass());

    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1);

    // Send another tx without immediate commit.

    modification = dataTree.takeSnapshot().newModification();
    MapEntryNode car2 = CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000));
    new WriteModification(CarsModel.newCarPath("sportage"), car2).apply(modification);

    forwardedReady = new ForwardedReadyTransaction(tx2,
            DataStoreVersions.CURRENT_VERSION, new ReadWriteShardDataTreeTransaction(
                    Mockito.mock(ShardDataTreeTransactionParent.class), tx2, modification), false);

    carsFollowerShard.get().tell(forwardedReady, followerTestKit.getRef());
    resp = followerTestKit.expectMsgClass(Object.class);
    if (resp instanceof akka.actor.Status.Failure) {
        throw new AssertionError("Unexpected failure response", ((akka.actor.Status.Failure)resp).cause());
    }

    assertEquals("Response type", ReadyTransactionReply.class, resp.getClass());

    ActorSelection txActor = leaderDistributedDataStore.getActorContext().actorSelection(
            ((ReadyTransactionReply)resp).getCohortPath());

    final Supplier<Short> versionSupplier = Mockito.mock(Supplier.class);
    Mockito.doReturn(DataStoreVersions.CURRENT_VERSION).when(versionSupplier).get();
    final ThreePhaseCommitCohortProxy cohort = new ThreePhaseCommitCohortProxy(
            leaderDistributedDataStore.getActorContext(), Arrays.asList(
                    new ThreePhaseCommitCohortProxy.CohortInfo(Futures.successful(txActor), versionSupplier)), tx2);
    cohort.canCommit().get(5, TimeUnit.SECONDS);
    cohort.preCommit().get(5, TimeUnit.SECONDS);
    cohort.commit().get(5, TimeUnit.SECONDS);

    verifyCars(leaderDistributedDataStore.newReadOnlyTransaction(), car1, car2);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:69,代码来源:DistributedDataStoreRemotingIntegrationTest.java

示例15: testReadyLocalTransactionWithThreePhaseCommit

import org.opendaylight.controller.cluster.datastore.modification.MergeModification; //导入依赖的package包/类
@Test
public void testReadyLocalTransactionWithThreePhaseCommit() throws Exception {
    new ShardTestKit(getSystem()) {
        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(
                    newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()),
                    "testReadyLocalTransactionWithThreePhaseCommit");

            waitUntilLeader(shard);

            final ShardDataTree dataStore = shard.underlyingActor().getDataStore();

            final DataTreeModification modification = dataStore.newModification();

            final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
            final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
            new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);

            final TransactionIdentifier txId = nextTransactionId();
            modification.ready();
            final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, false);

            shard.tell(readyMessage, getRef());

            expectMsgClass(ReadyTransactionReply.class);

            // Send the CanCommitTransaction message.

            shard.tell(new CanCommitTransaction(txId, CURRENT_VERSION).toSerializable(), getRef());
            final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply
                    .fromSerializable(expectMsgClass(CanCommitTransactionReply.class));
            assertEquals("Can commit", true, canCommitReply.getCanCommit());

            // Send the CanCommitTransaction message.

            shard.tell(new CommitTransaction(txId, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(CommitTransactionReply.class);

            final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
            assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
        }
    };
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:45,代码来源:ShardTest.java


注:本文中的org.opendaylight.controller.cluster.datastore.modification.MergeModification类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。