Search in sources :

Example 16 with DataTree

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.

the class CommitTransactionPayloadTest method testUnmodifiedRootCandidate.

@Test
public void testUnmodifiedRootCandidate() throws Exception {
    final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG));
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    modification.ready();
    candidate = dataTree.prepare(modification);
    CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate);
    assertCandidateEquals(candidate, payload.getCandidate().getValue());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 17 with DataTree

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.

the class ConnectClientSuccessTest method testGetDataTree.

@Test
public void testGetDataTree() {
    final DataTree tree = OBJECT.getDataTree().get();
    Assert.assertEquals(TREE, tree);
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) Test(org.junit.Test)

Example 18 with DataTree

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryForLocalLeaderShard.

@Test
public void testOnReceiveFindPrimaryForLocalLeaderShard() throws Exception {
    LOG.info("testOnReceiveFindPrimaryForLocalLeaderShard starting");
    new TestKit(getSystem()) {

        {
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            DataTree mockDataTree = mock(DataTree.class);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), getRef());
            MessageCollectorActor.expectFirstMatching(mockShardActor, RegisterRoleChangeListener.class);
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
            LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
            assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
        }
    };
    LOG.info("testOnReceiveFindPrimaryForLocalLeaderShard ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 19 with DataTree

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.

the class ShardManagerTest method testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId.

@Test
public void testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId() throws Exception {
    LOG.info("testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId starting");
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
            expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
            DataTree mockDataTree = mock(DataTree.class);
            shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), mockShardActor);
            shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, false), getRef());
            LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
            assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
        }
    };
    LOG.info("testOnReceiveFindPrimaryForFollowerShardWithNoInitialLeaderId starting");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 20 with DataTree

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.

the class ActorContextTest method testFindPrimaryShardAsyncLocalPrimaryFound.

@Test
public void testFindPrimaryShardAsyncLocalPrimaryFound() throws Exception {
    ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
    DatastoreContext dataStoreContext = DatastoreContext.newBuilder().logicalStoreType(LogicalDatastoreType.CONFIGURATION).shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
    final DataTree mockDataTree = Mockito.mock(DataTree.class);
    final String expPrimaryPath = "akka://test-system/find-primary-shard";
    ActorContext actorContext = new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {

        @Override
        protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
            return Futures.successful((Object) new LocalPrimaryShardFound(expPrimaryPath, mockDataTree));
        }
    };
    Future<PrimaryShardInfo> foobar = actorContext.findPrimaryShardAsync("foobar");
    PrimaryShardInfo actual = Await.result(foobar, Duration.apply(5000, TimeUnit.MILLISECONDS));
    assertNotNull(actual);
    assertEquals("LocalShardDataTree present", true, actual.getLocalShardDataTree().isPresent());
    assertSame("LocalShardDataTree", mockDataTree, actual.getLocalShardDataTree().get());
    assertTrue("Unexpected PrimaryShardActor path " + actual.getPrimaryShardActor().path(), expPrimaryPath.endsWith(actual.getPrimaryShardActor().pathString()));
    assertEquals("getPrimaryShardVersion", DataStoreVersions.CURRENT_VERSION, actual.getPrimaryShardVersion());
    Future<PrimaryShardInfo> cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
    PrimaryShardInfo cachedInfo = Await.result(cached, FiniteDuration.apply(1, TimeUnit.MILLISECONDS));
    assertEquals(cachedInfo, actual);
    actorContext.getPrimaryShardInfoCache().remove("foobar");
    cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
    assertNull(cached);
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) Timeout(akka.util.Timeout) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Aggregations

DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)33 Test (org.junit.Test)21 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)19 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)14 ActorRef (akka.actor.ActorRef)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)7 ShardSnapshotState (org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState)6 AddressFromURIString (akka.actor.AddressFromURIString)5 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)5 FiniteDuration (scala.concurrent.duration.FiniteDuration)5 TestActorRef (akka.testkit.TestActorRef)4 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)4 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)4 GetShardDataTree (org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree)4 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 TestKit (akka.testkit.javadsl.TestKit)3 Timeout (akka.util.Timeout)3 InOrder (org.mockito.InOrder)3