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