From: Moiz Raja Date: Wed, 15 Apr 2015 18:26:20 +0000 (+0000) Subject: Merge "Bug 2948: Recovered log entries not applied after prior snapshot" X-Git-Tag: release/lithium~265 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=2720ff2c662769d1c72e5723c18be4f7d79cd642;hp=c190bfc14468c9ad954201a53326df941161c470 Merge "Bug 2948: Recovered log entries not applied after prior snapshot" --- diff --git a/opendaylight/md-sal/mdsal-artifacts/pom.xml b/opendaylight/md-sal/mdsal-artifacts/pom.xml index 23b2ea11fd..e8a40167cf 100644 --- a/opendaylight/md-sal/mdsal-artifacts/pom.xml +++ b/opendaylight/md-sal/mdsal-artifacts/pom.xml @@ -177,6 +177,18 @@ sal-remoterpc-connector ${project.version} + + org.opendaylight.controller + sal-akka-raft + ${project.version} + + + org.opendaylight.controller + sal-akka-raft + ${project.version} + test-jar + test + diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java index 7db7dcc333..d06a1a8273 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleFactoryTest.java @@ -49,4 +49,4 @@ public class MessageBusAppImplModuleFactoryTest { assertNotNull("Module has not been created correctly.", messageBusAppImplModuleFactory.createModule("instanceName1", dependencyResolverMock, dynamicMBeanWithInstanceMock, bundleContextMock)); } -} +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java index 85d1a1b109..e26502f949 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/config/yang/messagebus/app/impl/MessageBusAppImplModuleTest.java @@ -7,17 +7,37 @@ */ package org.opendaylight.controller.config.yang.messagebus.app.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.config.api.DependencyResolver; +import org.opendaylight.controller.config.api.JmxAttribute; import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.osgi.framework.BundleContext; +import javax.management.ObjectName; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + public class MessageBusAppImplModuleTest { MessageBusAppImplModule messageBusAppImplModule; @@ -55,5 +75,34 @@ public class MessageBusAppImplModuleTest { assertEquals("Set and/or get method/s don't work correctly.", bundleContext, messageBusAppImplModule.getBundleContext()); } - //TODO: create MessageBusAppImplModule.createInstance test -} + @Test + public void createInstanceTest() throws Exception{ + org.opendaylight.controller.sal.binding.api.BindingAwareBroker bindingAwareBrokerMock = mock(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class); + Broker brokerMock = mock(Broker.class); + doReturn(brokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class)); + doReturn(bindingAwareBrokerMock).when(dependencyResolverMock).resolveInstance(eq(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class)); + messageBusAppImplModule.resolveDependencies(); + + BindingAwareBroker.ProviderContext providerContext = mock(BindingAwareBroker.ProviderContext.class); + doReturn(providerContext).when(bindingAwareBrokerMock).registerProvider(any(BindingAwareProvider.class)); + Broker.ProviderSession providerSessionMock = mock(Broker.ProviderSession.class); + doReturn(providerSessionMock).when(brokerMock).registerProvider(any(Provider.class)); + DataBroker dataBrokerMock = mock(DataBroker.class); + doReturn(dataBrokerMock).when(providerContext).getSALService(eq(DataBroker.class)); + DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class); + doReturn(domNotificationPublishServiceMock).when(providerSessionMock).getService(DOMNotificationPublishService.class); + DOMMountPointService domMountPointServiceMock = mock(DOMMountPointService.class); + doReturn(domMountPointServiceMock).when(providerSessionMock).getService(DOMMountPointService.class); + MountPointService mountPointServiceMock = mock(MountPointService.class); + doReturn(mountPointServiceMock).when(providerContext).getSALService(eq(MountPointService.class)); + RpcProviderRegistry rpcProviderRegistryMock = mock(RpcProviderRegistry.class); + doReturn(rpcProviderRegistryMock).when(providerContext).getSALService(eq(RpcProviderRegistry.class)); + + WriteTransaction writeTransactionMock = mock(WriteTransaction.class); + doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction(); + doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class), eq(true)); + + assertNotNull("EventSourceRegistryWrapper has not been created correctly.", messageBusAppImplModule.createInstance()); + } + +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java new file mode 100644 index 0000000000..9cce623523 --- /dev/null +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceRegistrationImplTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.messagebus.app.impl; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.messagebus.spi.EventSource; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class EventSourceRegistrationImplTest { + + EventSourceRegistrationImplLocal eventSourceRegistrationImplLocal; + EventSourceTopology eventSourceTopologyMock; + + @BeforeClass + public static void initTestClass() throws IllegalAccessException, InstantiationException { + } + + @Before + public void setUp() throws Exception { + EventSource eventSourceMock = mock(EventSource.class); + eventSourceTopologyMock = mock(EventSourceTopology.class); + eventSourceRegistrationImplLocal = new EventSourceRegistrationImplLocal(eventSourceMock, eventSourceTopologyMock); + } + + @Test + public void removeRegistrationTest() { + eventSourceRegistrationImplLocal.removeRegistration(); + verify(eventSourceTopologyMock, times(1)).unRegister(any(EventSource.class)); + } + + + private class EventSourceRegistrationImplLocal extends EventSourceRegistrationImpl{ + + /** + * @param instance of EventSource that has been registered by {@link EventSourceRegistryImpl#registerEventSource(Node, org.opendaylight.controller.messagebus.spi.EventSource)} + * @param eventSourceTopology + */ + public EventSourceRegistrationImplLocal(EventSource instance, EventSourceTopology eventSourceTopology) { + super(instance, eventSourceTopology); + } + } + +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java index f369a128ad..9f513c464b 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopicTest.java @@ -74,7 +74,7 @@ public class EventSourceTopicTest { nodeIdMock = mock(NodeId.class); doReturn(nodeIdMock).when(dataObjectMock).getId(); - doReturn("0").when(nodeIdMock).getValue(); + doReturn("nodeIdPattern1").when(nodeIdMock).getValue(); } @Test @@ -84,4 +84,4 @@ public class EventSourceTopicTest { verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class)); } -} +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java index ced2e1f01b..50ae4d9389 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/EventSourceTopologyTest.java @@ -16,13 +16,16 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -57,6 +60,7 @@ public class EventSourceTopologyTest { CreateTopicInput createTopicInputMock; ListenerRegistration listenerRegistrationMock; NodeKey nodeKey; + RpcRegistration aggregatorRpcReg; @BeforeClass public static void initTestClass() throws IllegalAccessException, InstantiationException { @@ -76,7 +80,7 @@ public class EventSourceTopologyTest { } private void constructorTestHelper(){ - RpcRegistration aggregatorRpcReg = mock(RpcRegistration.class); + aggregatorRpcReg = mock(RpcRegistration.class); EventSourceService eventSourceService = mock(EventSourceService.class); doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), any(EventSourceTopology.class)); doReturn(eventSourceService).when(rpcProviderRegistryMock).getRpcService(EventSourceService.class); @@ -87,11 +91,11 @@ public class EventSourceTopologyTest { doReturn(checkedFutureMock).when(writeTransactionMock).submit(); } -//TODO: create test for createTopic -// public void createTopicTest() throws Exception{ -// createTopicTestHelper(); -// assertNotNull("Topic has not been created correctly.", eventSourceTopology.createTopic(createTopicInputMock)); -// } + @Test + public void createTopicTest() throws Exception{ + topicTestHelper(); + assertNotNull("Topic has not been created correctly.", eventSourceTopology.createTopic(createTopicInputMock)); + } private void topicTestHelper() throws Exception{ constructorTestHelper(); @@ -138,6 +142,19 @@ public class EventSourceTopologyTest { assertNotNull("Instance has not been created correctly.", eventSourceTopology.destroyTopic(destroyTopicInput)); } + @Test + public void closeTest() throws Exception{ + constructorTestHelper(); + topicTestHelper(); + Map> localMap = getTopicListenerRegistrations(); + DataChangeListener dataChangeListenerMock = mock(DataChangeListener.class); + ListenerRegistration listenerListenerRegistrationMock = (ListenerRegistration) mock(ListenerRegistration.class); + localMap.put(dataChangeListenerMock, listenerListenerRegistrationMock); + eventSourceTopology.close(); + verify(aggregatorRpcReg, times(1)).close(); + verify(listenerListenerRegistrationMock, times(1)).close(); + } + @Test public void registerTest() throws Exception { topicTestHelper(); @@ -154,4 +171,46 @@ public class EventSourceTopologyTest { verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class)); } -} + @Test + public void unregisterTest() throws Exception { + topicTestHelper(); + EventSource eventSourceMock = mock(EventSource.class); + NodeId nodeId = new NodeId("nodeIdValue1"); + nodeKey = new NodeKey(nodeId); + Map> localMap = getRoutedRpcRegistrations(); + NodeKey nodeKeyMock = mock(NodeKey.class); + doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey(); + BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = (BindingAwareBroker.RoutedRpcRegistration) mock(BindingAwareBroker.RoutedRpcRegistration.class); + localMap.put(nodeKeyMock, routedRpcRegistrationMock); + eventSourceTopology.unRegister(eventSourceMock); + verify(routedRpcRegistrationMock, times(1)).close(); + } + + @Test + public void registerEventSourceTest() throws Exception { + topicTestHelper(); + Node nodeMock = mock(Node.class); + EventSource eventSourceMock = mock(EventSource.class); + NodeId nodeId = new NodeId("nodeIdValue1"); + nodeKey = new NodeKey(nodeId); + doReturn(nodeKey).when(nodeMock).getKey(); + doReturn(nodeKey).when(eventSourceMock).getSourceNodeKey(); + BindingAwareBroker.RoutedRpcRegistration routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class); + doReturn(routedRpcRegistrationMock).when(rpcProviderRegistryMock).addRoutedRpcImplementation(EventSourceService.class, eventSourceMock); + doNothing().when(routedRpcRegistrationMock).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class)); + assertNotNull("Return value has not been created correctly.", eventSourceTopology.registerEventSource(eventSourceMock)); + } + + private Map getTopicListenerRegistrations() throws Exception{ + Field nesField = EventSourceTopology.class.getDeclaredField("topicListenerRegistrations"); + nesField.setAccessible(true); + return (Map) nesField.get(eventSourceTopology); + } + + private Map getRoutedRpcRegistrations() throws Exception{ + Field nesField = EventSourceTopology.class.getDeclaredField("routedRpcRegistrations"); + nesField.setAccessible(true); + return (Map) nesField.get(eventSourceTopology); + } + +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceManagerTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceManagerTest.java index 61fa30f40e..1d6b825c9f 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceManagerTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceManagerTest.java @@ -84,11 +84,11 @@ public class NetconfEventSourceManagerTest { netconfEventSourceManager = NetconfEventSourceManager.create(dataBrokerMock, - domNotificationPublishServiceMock, - domMountPointServiceMock, - mountPointServiceMock, - eventSourceRegistry, - namespaceToStreamList); + domNotificationPublishServiceMock, + domMountPointServiceMock, + mountPointServiceMock, + eventSourceRegistry, + namespaceToStreamList); } @Test @@ -125,12 +125,14 @@ public class NetconfEventSourceManagerTest { Map mapUpdate = new HashMap<>(); InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class); Node dataObjectMock = mock(Node.class); + if(create){ mapCreate.put(instanceIdentifierMock, dataObjectMock); } if(update){ mapUpdate.put(instanceIdentifierMock, dataObjectMock); } + doReturn(mapCreate).when(asyncDataChangeEventMock).getCreatedData(); doReturn(mapUpdate).when(asyncDataChangeEventMock).getUpdatedData(); NetconfNode netconfNodeMock = mock(NetconfNode.class); @@ -171,4 +173,4 @@ public class NetconfEventSourceManagerTest { doReturn(esrMock).when(eventSourceRegistry).registerEventSource(any(EventSource.class)); } -} +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java index 58da9e3eb1..ed9025780a 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/NetconfEventSourceTest.java @@ -7,22 +7,8 @@ */ package org.opendaylight.controller.messagebus.app.impl; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.lang.reflect.Field; -import java.net.URI; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.BindingService; @@ -53,21 +39,32 @@ import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; +import java.lang.reflect.Field; +import java.net.URI; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; public class NetconfEventSourceTest { NetconfEventSource netconfEventSource; DOMMountPoint domMountPointMock; JoinTopicInput joinTopicInputMock; - AsyncDataChangeEvent asyncDataChangeEventMock; - Node dataObjectMock; @Before public void setUp() throws Exception { Map streamMap = new HashMap<>(); - streamMap.put("string1", "string2"); + streamMap.put("uriStr1", "string2"); domMountPointMock = mock(DOMMountPoint.class); DOMNotificationPublishService domNotificationPublishServiceMock = mock(DOMNotificationPublishService.class); MountPoint mountPointMock = mock(MountPoint.class); @@ -80,9 +77,9 @@ public class NetconfEventSourceTest { doReturn(rpcConsumerRegistryMock).when(onlyOptionalMock).get(); doReturn(notificationsServiceMock).when(rpcConsumerRegistryMock).getRpcService(NotificationsService.class); org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node node - = mock(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class); + = mock(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class); org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId nodeId - = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId("NodeId1"); + = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId("NodeId1"); doReturn(nodeId).when(node).getNodeId(); netconfEventSource = new NetconfEventSource(node, streamMap, domMountPointMock, domNotificationPublishServiceMock, mountPointMock); } @@ -143,7 +140,7 @@ public class NetconfEventSourceTest { doReturn(topicId).when(joinTopicInputMock).getTopicId(); NotificationPattern notificationPatternMock = mock(NotificationPattern.class); doReturn(notificationPatternMock).when(joinTopicInputMock).getNotificationPattern(); - doReturn("regexString1").when(notificationPatternMock).getValue(); + doReturn("uriStr1").when(notificationPatternMock).getValue(); SchemaContext schemaContextMock = mock(SchemaContext.class); doReturn(schemaContextMock).when(domMountPointMock).getSchemaContext(); @@ -165,6 +162,13 @@ public class NetconfEventSourceTest { doReturn(domNotificationServiceMock).when(domNotificationServiceOptionalMock).get(); ListenerRegistration listenerRegistrationMock = mock(ListenerRegistration.class); doReturn(listenerRegistrationMock).when(domNotificationServiceMock).registerNotificationListener(any(NetconfEventSource.class), any(List.class)); + + Optional optionalMock = (Optional) mock(Optional.class); + doReturn(optionalMock).when(domMountPointMock).getService(DOMRpcService.class); + DOMRpcService domRpcServiceMock = mock(DOMRpcService.class); + doReturn(domRpcServiceMock).when(optionalMock).get(); + CheckedFuture checkedFutureMock = mock(CheckedFuture.class); + doReturn(checkedFutureMock).when(domRpcServiceMock).invokeRpc(any(SchemaPath.class), any(ContainerNode.class)); } //TODO: create Test for NetConfEventSource#onNotification @@ -175,4 +179,4 @@ public class NetconfEventSourceTest { return (Set) nesField.get(netconfEventSource); } -} +} \ No newline at end of file diff --git a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/TopicDOMNotificationTest.java b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/TopicDOMNotificationTest.java index 6dacb9738a..b3f6438cc4 100644 --- a/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/TopicDOMNotificationTest.java +++ b/opendaylight/md-sal/messagebus-impl/src/test/java/org/opendaylight/controller/messagebus/app/impl/TopicDOMNotificationTest.java @@ -57,4 +57,4 @@ public class TopicDOMNotificationTest { String bodyString = "TopicDOMNotification [body=" + containerNodeBodyMockToString + "]"; assertEquals("String has not been created correctly.", bodyString, topicDOMNotification.toString()); } -} +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java index 2c433f9007..bdfdd9b376 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java @@ -460,7 +460,7 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior { long followerNextIndex = followerLogInformation.getNextIndex(); boolean isFollowerActive = followerLogInformation.isFollowerActive(); boolean sendAppendEntries = false; - List entries = Collections.EMPTY_LIST; + List entries = Collections.emptyList(); if (mapFollowerToSnapshot.get(followerId) != null) { // if install snapshot is in process , then sent next chunk if possible diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java new file mode 100644 index 0000000000..03da29642c --- /dev/null +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.binding.impl; + +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.dom.api.DOMNotification; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; +import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory; +import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.yangtools.yang.binding.Notification; + +class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { + + private final NotificationInvokerFactory.NotificationInvoker invoker; + private final BindingNormalizedNodeSerializer codec; + + public BindingDOMNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, final NotificationInvokerFactory.NotificationInvoker invoker) { + this.codec = codec; + this.invoker = invoker; + } + + @Override + public void onNotification(@Nonnull final DOMNotification notification) { + final Notification baNotification = + codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); + invoker.getInvocationProxy().onNotification(baNotification); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java index 50a0a2815f..6006266cc2 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationServiceAdapter.java @@ -13,10 +13,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; -import javax.annotation.Nonnull; import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.binding.impl.BindingDOMAdapterBuilder.Factory; -import org.opendaylight.controller.md.sal.dom.api.DOMNotification; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; import org.opendaylight.controller.md.sal.dom.api.DOMService; @@ -44,16 +42,16 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService private final DOMNotificationService domNotifService; private final NotificationInvokerFactory notificationInvokerFactory; - public BindingDOMNotificationServiceAdapter(BindingNormalizedNodeSerializer codec, DOMNotificationService domNotifService, NotificationInvokerFactory notificationInvokerFactory) { + public BindingDOMNotificationServiceAdapter(final BindingNormalizedNodeSerializer codec, final DOMNotificationService domNotifService, final NotificationInvokerFactory notificationInvokerFactory) { this.codec = codec; this.domNotifService = domNotifService; this.notificationInvokerFactory = notificationInvokerFactory; } @Override - public ListenerRegistration registerNotificationListener(T listener) { + public ListenerRegistration registerNotificationListener(final T listener) { final NotificationInvokerFactory.NotificationInvoker invoker = notificationInvokerFactory.invokerFor(listener); - final DOMNotificationListener domListener = new NotificationInvokerImpl(invoker); + final DOMNotificationListener domListener = new BindingDOMNotificationListenerAdapter(codec, invoker); final Collection schemaPaths = convertNotifTypesToSchemaPath(invoker.getSupportedNotifications()); final ListenerRegistration domRegistration = domNotifService.registerNotificationListener(domListener, schemaPaths); @@ -62,9 +60,9 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService - private Collection convertNotifTypesToSchemaPath(Set> notificationTypes) { + private Collection convertNotifTypesToSchemaPath(final Set> notificationTypes) { final List schemaPaths = new ArrayList<>(); - for (Class notificationType : notificationTypes) { + for (final Class notificationType : notificationTypes) { schemaPaths.add(SchemaPath.create(true, BindingReflections.findQName(notificationType))); } return schemaPaths; @@ -78,7 +76,7 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService private static class ListenerRegistrationImpl extends AbstractListenerRegistration { private final ListenerRegistration listenerRegistration; - public ListenerRegistrationImpl(T listener, ListenerRegistration listenerRegistration) { + public ListenerRegistrationImpl(final T listener, final ListenerRegistration listenerRegistration) { super(listener); this.listenerRegistration = listenerRegistration; } @@ -89,30 +87,14 @@ public class BindingDOMNotificationServiceAdapter implements NotificationService } } - private class NotificationInvokerImpl implements DOMNotificationListener { - private final NotificationInvokerFactory.NotificationInvoker invoker; - - public NotificationInvokerImpl(NotificationInvokerFactory.NotificationInvoker invoker) { - this.invoker = invoker; - } - - @Override - public void onNotification(@Nonnull DOMNotification notification) { - final Notification baNotification = - codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); - invoker.getInvocationProxy().onNotification(baNotification); - - } - } - private static class Builder extends BindingDOMAdapterBuilder { @Override - protected NotificationService createInstance(BindingToNormalizedNodeCodec codec, - ClassToInstanceMap delegates) { - DOMNotificationService domNotification = delegates.getInstance(DOMNotificationService.class); - NotificationInvokerFactory invokerFactory = SingletonHolder.INVOKER_FACTORY; + protected NotificationService createInstance(final BindingToNormalizedNodeCodec codec, + final ClassToInstanceMap delegates) { + final DOMNotificationService domNotification = delegates.getInstance(DOMNotificationService.class); + final NotificationInvokerFactory invokerFactory = SingletonHolder.INVOKER_FACTORY; return new BindingDOMNotificationServiceAdapter(codec.getCodecRegistry(), domNotification, invokerFactory); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-distributed-datastore/pom.xml index 10ea2be2dd..159c9131df 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-distributed-datastore/pom.xml @@ -92,12 +92,10 @@ org.opendaylight.controller sal-akka-raft - 1.2.0-SNAPSHOT org.opendaylight.controller sal-akka-raft - 1.2.0-SNAPSHOT test-jar test diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index a0987cd5d6..71799c92d4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -40,6 +40,7 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransactio import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -219,7 +220,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction>> nodes; - private final InMemoryDOMDataStore dataStore; - - NormalizedNodeAggregator(YangInstanceIdentifier rootIdentifier, List>> nodes, - SchemaContext schemaContext){ + private final DataTree dataTree; + private NormalizedNodeAggregator(YangInstanceIdentifier rootIdentifier, List>> nodes, + SchemaContext schemaContext) { this.rootIdentifier = rootIdentifier; this.nodes = nodes; - this.dataStore = new InMemoryDOMDataStore("aggregator", executorService); - this.dataStore.onGlobalContextUpdated(schemaContext); + this.dataTree = InMemoryDataTreeFactory.getInstance().create(); + this.dataTree.setSchemaContext(schemaContext); } /** @@ -46,44 +37,35 @@ public class NormalizedNodeAggregator { * @param nodes * @param schemaContext * @return - * @throws ExecutionException - * @throws InterruptedException + * @throws DataValidationFailedException */ public static Optional> aggregate(YangInstanceIdentifier rootIdentifier, List>> nodes, - SchemaContext schemaContext) - throws ExecutionException, InterruptedException { + SchemaContext schemaContext) throws DataValidationFailedException { return new NormalizedNodeAggregator(rootIdentifier, nodes, schemaContext).aggregate(); } - private Optional> aggregate() throws ExecutionException, InterruptedException { + private Optional> aggregate() throws DataValidationFailedException { return combine().getRootNode(); } - private NormalizedNodeAggregator combine() throws InterruptedException, ExecutionException { - DOMStoreWriteTransaction domStoreWriteTransaction = dataStore.newWriteOnlyTransaction(); + private NormalizedNodeAggregator combine() throws DataValidationFailedException { + DataTreeModification mod = dataTree.takeSnapshot().newModification(); - for(Optional> node : nodes) { - if(node.isPresent()) { - domStoreWriteTransaction.merge(rootIdentifier, node.get()); + for (Optional> node : nodes) { + if (node.isPresent()) { + mod.merge(rootIdentifier, node.get()); } } - DOMStoreThreePhaseCommitCohort ready = domStoreWriteTransaction.ready(); - ready.canCommit().get(); - ready.preCommit().get(); - ready.commit().get(); + + dataTree.validate(mod); + final DataTreeCandidate candidate = dataTree.prepare(mod); + dataTree.commit(candidate); return this; } - private Optional> getRootNode() throws InterruptedException, ExecutionException { - DOMStoreReadTransaction readTransaction = dataStore.newReadOnlyTransaction(); - - CheckedFuture>, ReadFailedException> read = - readTransaction.read(rootIdentifier); - - return read.get(); + private Optional> getRootNode() { + return dataTree.takeSnapshot().readNode(rootIdentifier); } - - } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java index 40d3704d2c..8c8631089c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java @@ -29,13 +29,14 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class NormalizedNodeAggregatorTest { @Test - public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException { + public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException, DataValidationFailedException { SchemaContext schemaContext = SchemaContextHelper.full(); NormalizedNode expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME); NormalizedNode expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME); diff --git a/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml b/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml index a8c05a166d..4a17273232 100644 --- a/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml +++ b/opendaylight/md-sal/sal-dummy-distributed-datastore/pom.xml @@ -58,7 +58,6 @@ org.opendaylight.controller sal-akka-raft - 1.2.0-SNAPSHOT