Search in sources :

Example 1 with ShardDataTree

use of org.opendaylight.controller.cluster.datastore.ShardDataTree in project controller by opendaylight.

the class PruningDataTreeModificationTest method testWriteRootNodeWithInvalidChild.

@Test
public void testWriteRootNodeWithInvalidChild() throws Exception {
    final Shard mockShard = Mockito.mock(Shard.class);
    ShardDataTree shardDataTree = new ShardDataTree(mockShard, SCHEMA_CONTEXT, TreeType.CONFIGURATION);
    NormalizedNode<?, ?> root = shardDataTree.readNode(YangInstanceIdentifier.EMPTY).get();
    NormalizedNode<?, ?> normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(root.getNodeType())).withChild(ImmutableNodes.containerNode(AUG_CONTAINER)).build();
    pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
    dataTree.commit(getCandidate());
    Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
    assertEquals("Root present", true, actual.isPresent());
    assertEquals("Root node", root, actual.get());
}
Also used : Shard(org.opendaylight.controller.cluster.datastore.Shard) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ShardDataTree(org.opendaylight.controller.cluster.datastore.ShardDataTree) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 2 with ShardDataTree

use of org.opendaylight.controller.cluster.datastore.ShardDataTree in project controller by opendaylight.

the class CandidateListChangeListenerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    shardDataTree = new ShardDataTree(mockShard, SchemaContextHelper.entityOwners(), TreeType.OPERATIONAL);
}
Also used : ShardDataTree(org.opendaylight.controller.cluster.datastore.ShardDataTree) Before(org.junit.Before)

Example 3 with ShardDataTree

use of org.opendaylight.controller.cluster.datastore.ShardDataTree in project controller by opendaylight.

the class DistributedEntityOwnershipServiceTest method testGetOwnershipState.

@Test
public void testGetOwnershipState() throws Exception {
    DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
    final Shard mockShard = Mockito.mock(Shard.class);
    ShardDataTree shardDataTree = new ShardDataTree(mockShard, SchemaContextHelper.entityOwners(), TreeType.OPERATIONAL);
    when(service.getLocalEntityOwnershipShardDataTree()).thenReturn(shardDataTree.getDataTree());
    DOMEntity entity1 = new DOMEntity(ENTITY_TYPE, "one");
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity1.getIdentifier(), "member-1"), shardDataTree);
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithEntityTypeEntry(entityTypeEntryWithEntityEntry(entity1.getType(), entityEntryWithOwner(entity1.getIdentifier(), "member-1"))), shardDataTree);
    verifyGetOwnershipState(service, entity1, EntityOwnershipState.IS_OWNER);
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity1.getIdentifier(), "member-2"), shardDataTree);
    writeNode(entityPath(entity1.getType(), entity1.getIdentifier()), entityEntryWithOwner(entity1.getIdentifier(), "member-2"), shardDataTree);
    verifyGetOwnershipState(service, entity1, EntityOwnershipState.OWNED_BY_OTHER);
    writeNode(entityPath(entity1.getType(), entity1.getIdentifier()), entityEntryWithOwner(entity1.getIdentifier(), ""), shardDataTree);
    verifyGetOwnershipState(service, entity1, EntityOwnershipState.NO_OWNER);
    DOMEntity entity2 = new DOMEntity(ENTITY_TYPE, "two");
    Optional<EntityOwnershipState> state = service.getOwnershipState(entity2);
    assertEquals("getOwnershipState present", false, state.isPresent());
    writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, entity2.getIdentifier(), "member-1"), shardDataTree);
    writeNode(entityPath(entity2.getType(), entity2.getIdentifier()), ImmutableNodes.mapEntry(ENTITY_QNAME, ENTITY_ID_QNAME, entity2.getIdentifier()), shardDataTree);
    verifyGetOwnershipState(service, entity2, EntityOwnershipState.NO_OWNER);
    deleteNode(candidatePath(entityPath(entity2.getType(), entity2.getIdentifier()), "member-1"), shardDataTree);
    Optional<EntityOwnershipState> state2 = service.getOwnershipState(entity2);
    assertEquals("getOwnershipState present", false, state2.isPresent());
    service.close();
}
Also used : EntityOwnershipState(org.opendaylight.mdsal.eos.common.api.EntityOwnershipState) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) Shard(org.opendaylight.controller.cluster.datastore.Shard) ShardDataTree(org.opendaylight.controller.cluster.datastore.ShardDataTree) Test(org.junit.Test)

Aggregations

ShardDataTree (org.opendaylight.controller.cluster.datastore.ShardDataTree)3 Test (org.junit.Test)2 Shard (org.opendaylight.controller.cluster.datastore.Shard)2 Before (org.junit.Before)1 EntityOwnershipState (org.opendaylight.mdsal.eos.common.api.EntityOwnershipState)1 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1