Search in sources :

Example 51 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class EntityOwnershipShardTest method testOnRegisterCandidateLocalWithNoInitialLeader.

@Test
public void testOnRegisterCandidateLocalWithNoInitialLeader() throws Exception {
    testLog.info("testOnRegisterCandidateLocalWithNoInitialLeader starting");
    final ShardTestKit kit = new ShardTestKit(getSystem());
    dataStoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(2);
    ShardIdentifier leaderId = newShardId(LOCAL_MEMBER_NAME);
    ShardIdentifier peerId = newShardId(PEER_MEMBER_1_NAME);
    TestActorRef<TestEntityOwnershipShard> peer = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId, peerMap(leaderId.toString()), PEER_MEMBER_1_NAME)), peerId.toString());
    TestEntityOwnershipShard peerShard = peer.underlyingActor();
    peerShard.startDroppingMessagesOfType(RequestVote.class);
    peerShard.startDroppingMessagesOfType(ElectionTimeout.class);
    TestActorRef<EntityOwnershipShard> shard = actorFactory.createTestActor(newShardProps(leaderId, peerMap(peerId.toString()), LOCAL_MEMBER_NAME), leaderId.toString());
    YangInstanceIdentifier entityId = ENTITY_ID1;
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    shard.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Now allow RequestVotes to the peer so the shard becomes the leader. This should retry the commit.
    peerShard.stopDroppingMessagesOfType(RequestVote.class);
    verifyCommittedEntityCandidate(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
    verifyOwner(shard, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
    testLog.info("testOnRegisterCandidateLocalWithNoInitialLeader ending");
}
Also used : RegisterCandidateLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal) ShardTestKit(org.opendaylight.controller.cluster.datastore.ShardTestKit) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 52 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class NormalizedNodeStreamReaderWriterTest method testNormalizedNodeAndYangInstanceIdentifierStreaming.

@Test
public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter(ByteStreams.newDataOutput(byteArrayOutputStream));
    NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder().build();
    writer.writeNormalizedNode(testContainer);
    YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build();
    writer.writeYangInstanceIdentifier(path);
    NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(byteArrayOutputStream.toByteArray()));
    NormalizedNode<?, ?> node = reader.readNormalizedNode();
    Assert.assertEquals(testContainer, node);
    YangInstanceIdentifier newPath = reader.readYangInstanceIdentifier();
    Assert.assertEquals(path, newPath);
    writer.close();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 53 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class SerializationUtilsTest method testSerializeDeserializePathAndNode.

@Test
public void testSerializeDeserializePathAndNode() throws Exception {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final DataOutput out = new DataOutputStream(bos);
    final NormalizedNode<?, ?> node = createNormalizedNode();
    final YangInstanceIdentifier path = YangInstanceIdentifier.create(id("container1"));
    SerializationUtils.serializePathAndNode(path, node, out);
    final DataInputStream in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
    final AtomicBoolean applierCalled = new AtomicBoolean(false);
    SerializationUtils.deserializePathAndNode(in, applierCalled, (instance, deserializedPath, deserializedNode) -> {
        Assert.assertEquals(path, deserializedPath);
        Assert.assertEquals(node, deserializedNode);
        applierCalled.set(true);
    });
    Assert.assertTrue(applierCalled.get());
}
Also used : DataOutput(java.io.DataOutput) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 54 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class NormalizedNodePrunerTest method testInnerListNodeWithFullPathPrunedWhenSchemaMissing.

@Test
public void testInnerListNodeWithFullPathPrunedWhenSchemaMissing() throws IOException {
    YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME).node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).node(TestModel.INVALID_QNAME).build();
    NormalizedNodePruner pruner = prunerFullSchema(path);
    MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder(TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild(ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build();
    NormalizedNodeWriter.forStreamWriter(pruner).write(input);
    NormalizedNode<?, ?> actual = pruner.normalizedNode();
    assertNull(actual);
}
Also used : MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 55 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class NormalizedNodePrunerTest method testInnerContainerNodeWithParentPathPrunedWhenSchemaMissing.

@Test
public void testInnerContainerNodeWithParentPathPrunedWhenSchemaMissing() throws IOException {
    YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME).node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
    NormalizedNodePruner pruner = prunerFullSchema(path);
    MapNode innerList = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild(ImmutableNodes.containerNode(TestModel.INVALID_QNAME)).build()).build();
    NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(innerList).build();
    NormalizedNodeWriter.forStreamWriter(pruner).write(input);
    NormalizedNode<?, ?> expected = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").build()).build()).build();
    NormalizedNode<?, ?> actual = pruner.normalizedNode();
    assertEquals("normalizedNode", expected, actual);
}
Also used : MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)187 Test (org.junit.Test)111 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)34 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 ActorRef (akka.actor.ActorRef)19 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)19 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 TestActorRef (akka.testkit.TestActorRef)14 TestKit (akka.testkit.javadsl.TestKit)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)12 ArrayList (java.util.ArrayList)11 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)10 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)10 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)10 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)10 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9