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());
}
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);
}
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();
}
Aggregations