*/
package org.opendaylight.controller.messagebus.app.impl;
+import com.google.common.base.Preconditions;
import org.opendaylight.controller.messagebus.spi.EventSource;
import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
-import com.google.common.base.Preconditions;
-
-
-class EventSourceRegistrationImpl <T extends EventSource> extends AbstractObjectRegistration<T> implements EventSourceRegistration<T>{
+class EventSourceRegistrationImpl<T extends EventSource> extends AbstractObjectRegistration<T>
+ implements EventSourceRegistration<T> {
private final EventSourceTopology eventSourceTopology;
/**
- * @param instance of EventSource that has been registered by {@link EventSourceRegistryImpl#registerEventSource(Node, EventSource)}
+ * Constructor.
+ *
+ * @param instance of EventSource that has been registered by
+ * {@link EventSourceRegistryImpl#registerEventSource(Node, EventSource)}
*/
- public EventSourceRegistrationImpl(T instance, EventSourceTopology eventSourceTopology) {
+ EventSourceRegistrationImpl(T instance, EventSourceTopology eventSourceTopology) {
super(instance);
this.eventSourceTopology = Preconditions.checkNotNull(eventSourceTopology);
}
protected void removeRegistration() {
this.eventSourceTopology.unRegister(getInstance());
}
-
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.DisJoinTopicInput;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.LoggerFactory;
-public class EventSourceTopic implements DataTreeChangeListener<Node>, AutoCloseable {
+public final class EventSourceTopic implements DataTreeChangeListener<Node>, AutoCloseable {
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(EventSourceTopic.class);
private final NotificationPattern notificationPattern;
private final EventSourceService sourceService;
private ListenerRegistration<?> listenerRegistration;
private final CopyOnWriteArraySet<InstanceIdentifier<?>> joinedEventSources = new CopyOnWriteArraySet<>();
- public static EventSourceTopic create(final NotificationPattern notificationPattern, final String nodeIdRegexPattern, final EventSourceTopology eventSourceTopology){
- final EventSourceTopic est = new EventSourceTopic(notificationPattern, nodeIdRegexPattern, eventSourceTopology.getEventSourceService());
+ public static EventSourceTopic create(final NotificationPattern notificationPattern,
+ final String nodeIdRegexPattern, final EventSourceTopology eventSourceTopology) {
+ final EventSourceTopic est = new EventSourceTopic(notificationPattern, nodeIdRegexPattern,
+ eventSourceTopology.getEventSourceService());
est.registerListner(eventSourceTopology);
est.notifyExistingNodes(eventSourceTopology);
return est;
}
- private EventSourceTopic(final NotificationPattern notificationPattern, final String nodeIdRegexPattern, final EventSourceService sourceService) {
+ private EventSourceTopic(final NotificationPattern notificationPattern, final String nodeIdRegexPattern,
+ final EventSourceService sourceService) {
this.notificationPattern = Preconditions.checkNotNull(notificationPattern);
this.sourceService = Preconditions.checkNotNull(sourceService);
this.nodeIdPattern = Pattern.compile(nodeIdRegexPattern);
public void notifyNode(final InstanceIdentifier<?> nodeId) {
LOG.debug("Notify node: {}", nodeId);
try {
- final RpcResult<JoinTopicOutput> rpcResultJoinTopic = sourceService.joinTopic(getJoinTopicInputArgument(nodeId)).get();
- if(rpcResultJoinTopic.isSuccessful() == false){
- for(final RpcError err : rpcResultJoinTopic.getErrors()){
- LOG.error("Can not join topic: [{}] on node: [{}]. Error: {}",getTopicId().getValue(),nodeId.toString(),err.toString());
+ final RpcResult<JoinTopicOutput> rpcResultJoinTopic =
+ sourceService.joinTopic(getJoinTopicInputArgument(nodeId)).get();
+ if (!rpcResultJoinTopic.isSuccessful()) {
+ for (final RpcError err : rpcResultJoinTopic.getErrors()) {
+ LOG.error("Can not join topic: [{}] on node: [{}]. Error: {}", getTopicId().getValue(),
+ nodeId.toString(), err.toString());
}
} else {
joinedEventSources.add(nodeId);
}
- } catch (final Exception e) {
+ } catch (InterruptedException | ExecutionException e) {
LOG.error("Could not invoke join topic for node {}", nodeId);
}
}
- private void notifyExistingNodes(final EventSourceTopology eventSourceTopology){
+ private void notifyExistingNodes(final EventSourceTopology eventSourceTopology) {
LOG.debug("Notify existing nodes");
final Pattern nodeRegex = this.nodeIdPattern;
final ReadOnlyTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction();
- final CheckedFuture<Optional<Topology>, ReadFailedException> future =
+ final ListenableFuture<Optional<Topology>> future =
tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
- Futures.addCallback(future, new FutureCallback<Optional<Topology>>(){
-
+ Futures.addCallback(future, new FutureCallback<Optional<Topology>>() {
@Override
public void onSuccess(final Optional<Topology> data) {
- if(data.isPresent()) {
- final List<Node> nodes = data.get().getNode();
- if(nodes != null){
+ if (data.isPresent()) {
+ final List<Node> nodes = data.get().getNode();
+ if (nodes != null) {
for (final Node node : nodes) {
- if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
- notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, node.getKey()));
- }
- }
- }
+ if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
+ notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class,
+ node.getKey()));
+ }
+ }
+ }
}
tx.close();
}
@Override
- public void onFailure(final Throwable t) {
- LOG.error("Can not notify existing nodes", t);
+ public void onFailure(final Throwable ex) {
+ LOG.error("Can not notify existing nodes", ex);
tx.close();
}
-
- });
-
+ }, MoreExecutors.directExecutor());
}
private JoinTopicInput getJoinTopicInputArgument(final InstanceIdentifier<?> path) {
return nodeIdPattern;
}
- private DisJoinTopicInput getDisJoinTopicInputArgument(final InstanceIdentifier<?> eventSourceNodeId){
+ private DisJoinTopicInput getDisJoinTopicInputArgument(final InstanceIdentifier<?> eventSourceNodeId) {
final NodeRef nodeRef = new NodeRef(eventSourceNodeId);
final DisJoinTopicInput dji = new DisJoinTopicInputBuilder()
.setNode(nodeRef.getValue())
@Override
public void close() {
- if(this.listenerRegistration != null){
+ if (this.listenerRegistration != null) {
this.listenerRegistration.close();
}
- for(final InstanceIdentifier<?> eventSourceNodeId : joinedEventSources){
+ for (final InstanceIdentifier<?> eventSourceNodeId : joinedEventSources) {
try {
- final RpcResult<Void> result = sourceService.disJoinTopic(getDisJoinTopicInputArgument(eventSourceNodeId)).get();
- if(result.isSuccessful() == false){
- for(final RpcError err : result.getErrors()){
- LOG.error("Can not destroy topic: [{}] on node: [{}]. Error: {}",getTopicId().getValue(),eventSourceNodeId,err.toString());
+ final RpcResult<Void> result = sourceService
+ .disJoinTopic(getDisJoinTopicInputArgument(eventSourceNodeId)).get();
+ if (result.isSuccessful() == false) {
+ for (final RpcError err : result.getErrors()) {
+ LOG.error("Can not destroy topic: [{}] on node: [{}]. Error: {}", getTopicId().getValue(),
+ eventSourceNodeId, err.toString());
}
}
} catch (InterruptedException | ExecutionException ex) {
- LOG.error("Can not close event source topic / destroy topic {} on node {}.", this.topicId.getValue(), eventSourceNodeId, ex);
+ LOG.error("Can not close event source topic / destroy topic {} on node {}.", this.topicId.getValue(),
+ eventSourceNodeId, ex);
}
}
joinedEventSources.clear();
}
- private static String getUUIDIdent(){
+ private static String getUUIDIdent() {
final UUID uuid = UUID.randomUUID();
return uuid.toString();
}
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class EventSourceTopology implements EventAggregatorService, EventSourceRegistry {
private static final Logger LOG = LoggerFactory.getLogger(EventSourceTopology.class);
eventSourceService = rpcRegistry.getRpcService(EventSourceService.class);
final TopologyEventSource topologySource = new TopologyEventSourceBuilder().build();
- final TopologyTypes1 topologyTypeAugment = new TopologyTypes1Builder().setTopologyEventSource(topologySource).build();
+ final TopologyTypes1 topologyTypeAugment =
+ new TopologyTypes1Builder().setTopologyEventSource(topologySource).build();
putData(OPERATIONAL, TOPOLOGY_TYPE_PATH, topologyTypeAugment);
LOG.info("EventSourceRegistry has been initialized");
}
private <T extends DataObject> void putData(final LogicalDatastoreType store,
final InstanceIdentifier<T> path,
- final T data){
+ final T data) {
final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
tx.put(store, path, data, true);
- Futures.addCallback( tx.submit(), new FutureCallback<Void>(){
-
+ Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.trace("Data has put into datastore {} {}", store, path);
}
@Override
- public void onFailure(final Throwable t) {
- LOG.error("Can not put data into datastore [store: {}] [path: {}] [exception: {}]",store,path, t);
+ public void onFailure(final Throwable ex) {
+ LOG.error("Can not put data into datastore [store: {}] [path: {}] [exception: {}]",store,path, ex);
}
- });
-
+ }, MoreExecutors.directExecutor());
}
- private <T extends DataObject> void deleteData(final LogicalDatastoreType store, final InstanceIdentifier<T> path){
+ private <T extends DataObject> void deleteData(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path) {
final WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
tx.delete(OPERATIONAL, path);
- Futures.addCallback( tx.submit(), new FutureCallback<Void>(){
-
+ Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
LOG.trace("Data has deleted from datastore {} {}", store, path);
}
@Override
- public void onFailure(final Throwable t) {
- LOG.error("Can not delete data from datastore [store: {}] [path: {}] [exception: {}]",store,path, t);
+ public void onFailure(final Throwable ex) {
+ LOG.error("Can not delete data from datastore [store: {}] [path: {}] [exception: {}]",store,path, ex);
}
-
- });
+ }, MoreExecutors.directExecutor());
}
private void insert(final KeyedInstanceIdentifier<Node, NodeKey> sourcePath) {
final NodeKey nodeKey = sourcePath.getKey();
final InstanceIdentifier<Node1> augmentPath = sourcePath.augmentation(Node1.class);
- final Node1 nodeAgument = new Node1Builder().setEventSourceNode(new NodeId(nodeKey.getNodeId().getValue())).build();
+ final Node1 nodeAgument = new Node1Builder().setEventSourceNode(
+ new NodeId(nodeKey.getNodeId().getValue())).build();
putData(OPERATIONAL, augmentPath, nodeAgument);
}
- private void remove(final KeyedInstanceIdentifier<Node, NodeKey> sourcePath){
+ private void remove(final KeyedInstanceIdentifier<Node, NodeKey> sourcePath) {
final InstanceIdentifier<Node1> augmentPath = sourcePath.augmentation(Node1.class);
deleteData(OPERATIONAL, augmentPath);
}
@Override
public Future<RpcResult<Void>> destroyTopic(final DestroyTopicInput input) {
final EventSourceTopic topicToDestroy = eventSourceTopicMap.remove(input.getTopicId());
- if(topicToDestroy != null){
+ if (topicToDestroy != null) {
topicToDestroy.close();
}
return Util.resultRpcSuccessFor((Void) null);
@Override
public void close() {
aggregatorRpcReg.close();
- for(final EventSourceTopic est : eventSourceTopicMap.values()){
- est.close();
- }
+ eventSourceTopicMap.values().forEach(EventSourceTopic::close);
}
- public void register(final EventSource eventSource){
+ public void register(final EventSource eventSource) {
final NodeKey nodeKey = eventSource.getSourceNodeKey();
final KeyedInstanceIdentifier<Node, NodeKey> sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey);
- final RoutedRpcRegistration<EventSourceService> reg = rpcRegistry.addRoutedRpcImplementation(EventSourceService.class, eventSource);
+ final RoutedRpcRegistration<EventSourceService> reg = rpcRegistry.addRoutedRpcImplementation(
+ EventSourceService.class, eventSource);
reg.registerPath(NodeContext.class, sourcePath);
routedRpcRegistrations.put(nodeKey,reg);
insert(sourcePath);
}
- public void unRegister(final EventSource eventSource){
+ public void unRegister(final EventSource eventSource) {
final NodeKey nodeKey = eventSource.getSourceNodeKey();
final KeyedInstanceIdentifier<Node, NodeKey> sourcePath = EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, nodeKey);
final RoutedRpcRegistration<EventSourceService> removeRegistration = routedRpcRegistrations.remove(nodeKey);
- if(removeRegistration != null){
+ if (removeRegistration != null) {
removeRegistration.close();
- remove(sourcePath);
+ remove(sourcePath);
}
}
*/
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;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.messagebus.spi.EventSource;
+
public class EventSourceRegistrationImplTest {
EventSourceRegistrationImplLocal eventSourceRegistrationImplLocal;
public void setUp() throws Exception {
EventSource eventSourceMock = mock(EventSource.class);
eventSourceTopologyMock = mock(EventSourceTopology.class);
- eventSourceRegistrationImplLocal = new EventSourceRegistrationImplLocal(eventSourceMock, eventSourceTopologyMock);
+ eventSourceRegistrationImplLocal = new EventSourceRegistrationImplLocal(eventSourceMock,
+ eventSourceTopologyMock);
}
@Test
}
- 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) {
+ private class EventSourceRegistrationImplLocal extends EventSourceRegistrationImpl<EventSource> {
+ EventSourceRegistrationImplLocal(EventSource instance, EventSourceTopology eventSourceTopology) {
super(instance, eventSourceTopology);
}
}
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicStatus;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
public class EventSourceTopicTest {
@Before
public void setUp() throws Exception {
- NotificationPattern notificationPattern = new NotificationPattern("value1");
+ final NotificationPattern notificationPattern = new NotificationPattern("value1");
eventSourceServiceMock = mock(EventSourceService.class);
+ doReturn(RpcResultBuilder.success(new JoinTopicOutputBuilder().setStatus(JoinTopicStatus.Up).build())
+ .buildFuture()).when(eventSourceServiceMock).joinTopic(any(JoinTopicInput.class));
+
eventSourceTopologyMock = mock(EventSourceTopology.class);
dataBrokerMock = mock(DataBroker.class);
doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService();
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));
+ doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class),
+ any(InstanceIdentifier.class), any(DataObject.class),eq(true));
CheckedFuture checkedFutureWriteMock = mock(CheckedFuture.class);
doReturn(checkedFutureWriteMock).when(writeTransactionMock).submit();
ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
CheckedFuture checkedFutureReadMock = mock(CheckedFuture.class);
- doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
+ doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL,
+ EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock);
}
verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class));
}
- public NodeKey getNodeKey(String nodeId){
+ public NodeKey getNodeKey(String nodeId) {
return new NodeKey(new NodeId(nodeId));
}
}
assertNotNull("Instance has not been created correctly.", eventSourceTopology);
}
- private void constructorTestHelper(){
+ private void constructorTestHelper() {
aggregatorRpcReg = mock(RpcRegistration.class);
EventSourceService eventSourceService = mock(EventSourceService.class);
- doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class), any(EventSourceTopology.class));
+ doReturn(aggregatorRpcReg).when(rpcProviderRegistryMock).addRpcImplementation(eq(EventAggregatorService.class),
+ any(EventSourceTopology.class));
doReturn(eventSourceService).when(rpcProviderRegistryMock).getRpcService(EventSourceService.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));
+ doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+ any(DataObject.class),eq(true));
CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
doReturn(checkedFutureMock).when(writeTransactionMock).submit();
}
@Test
- public void createTopicTest() throws Exception{
+ public void createTopicTest() throws Exception {
topicTestHelper();
assertNotNull("Topic has not been created correctly.", eventSourceTopology.createTopic(createTopicInputMock));
}
@Test
- public void destroyTopicTest() throws Exception{
+ public void destroyTopicTest() throws Exception {
topicTestHelper();
TopicId topicId = new TopicId("topic-id-007");
Map<TopicId,EventSourceTopic> localMap = getEventSourceTopicMap();
- EventSourceTopic eventSourceTopicMock = mock(EventSourceTopic.class);
- localMap.put(topicId, eventSourceTopicMock);
+ EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"),
+ "pattern", eventSourceTopology);
+ localMap.put(topicId, eventSourceTopic);
DestroyTopicInput input = new DestroyTopicInputBuilder().setTopicId(topicId).build();
eventSourceTopology.destroyTopic(input);
- verify(eventSourceTopicMock, times(1)).close();
+ verify(listenerRegistrationMock, times(1)).close();
}
- private void topicTestHelper() throws Exception{
+ private void topicTestHelper() throws Exception {
constructorTestHelper();
createTopicInputMock = mock(CreateTopicInput.class);
eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock);
}
@Test
- public void closeTest() throws Exception{
+ public void closeTest() throws Exception {
constructorTestHelper();
topicTestHelper();
Map<TopicId,EventSourceTopic> localMap = getEventSourceTopicMap();
TopicId topicIdMock = mock(TopicId.class);
- EventSourceTopic eventSourceTopicMock = mock(EventSourceTopic.class);
- localMap.put(topicIdMock, eventSourceTopicMock);
+ EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"),
+ "pattern", eventSourceTopology);
+ localMap.put(topicIdMock, eventSourceTopic);
eventSourceTopology.close();
verify(aggregatorRpcReg, times(1)).close();
- verify(eventSourceTopicMock, times(1)).close();
+ verify(listenerRegistrationMock, times(1)).close();
}
@Test
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));
+ 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));
eventSourceTopology.register(eventSourceMock);
- verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class), any(KeyedInstanceIdentifier.class));
+ verify(routedRpcRegistrationMock, times(1)).registerPath(eq(NodeContext.class),
+ any(KeyedInstanceIdentifier.class));
}
@Test
EventSource eventSourceMock = mock(EventSource.class);
NodeId nodeId = new NodeId("nodeIdValue1");
nodeKey = new NodeKey(nodeId);
- Map<NodeKey, BindingAwareBroker.RoutedRpcRegistration<EventSourceService>> localMap = getRoutedRpcRegistrations();
+ Map<NodeKey, BindingAwareBroker.RoutedRpcRegistration<EventSourceService>> localMap =
+ getRoutedRpcRegistrations();
NodeKey nodeKeyMock = mock(NodeKey.class);
doReturn(nodeKeyMock).when(eventSourceMock).getSourceNodeKey();
- BindingAwareBroker.RoutedRpcRegistration<EventSourceService> routedRpcRegistrationMock = mock(BindingAwareBroker.RoutedRpcRegistration.class);
+ BindingAwareBroker.RoutedRpcRegistration<EventSourceService> routedRpcRegistrationMock =
+ mock(BindingAwareBroker.RoutedRpcRegistration.class);
localMap.put(nodeKeyMock, routedRpcRegistrationMock);
eventSourceTopology.unRegister(eventSourceMock);
verify(routedRpcRegistrationMock, times(1)).close();
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));
+ 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 getEventSourceTopicMap() throws Exception{
+ private Map getEventSourceTopicMap() throws Exception {
Field nesField = EventSourceTopology.class.getDeclaredField("eventSourceTopicMap");
nesField.setAccessible(true);
return (Map) nesField.get(eventSourceTopology);
}
- private Map getRoutedRpcRegistrations() throws Exception{
+ private Map getRoutedRpcRegistrations() throws Exception {
Field nesField = EventSourceTopology.class.getDeclaredField("routedRpcRegistrations");
nesField.setAccessible(true);
return (Map) nesField.get(eventSourceTopology);
package org.opendaylight.controller.messagebus.spi;
import java.util.List;
-
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
public interface EventSource extends EventSourceService, AutoCloseable {
/**
- * Identifier of node associated with event source
+ * Identifier of node associated with event source.
*
* @return instance of NodeKey
*/
* @return list of available notification
*/
List<SchemaPath> getAvailableNotifications();
-
}
* and it is used to unregister EventSource.
*
*/
-public interface EventSourceRegistration <T extends EventSource> extends ObjectRegistration<T>{
+public interface EventSourceRegistration<T extends EventSource> extends ObjectRegistration<T> {
@Override
void close();
-
}
* associated with the node identified via {@link EventSource#getSourceNodeKey}.
*
* @param eventSource the EventSource instance to register
- * @return an EventSourceRegistration instance that is used to unregister the EventSource via {@link EventSourceRegistration#close()}.
+ * @return an EventSourceRegistration instance that is used to unregister the EventSource
+ * via {@link EventSourceRegistration#close()}.
*/
<T extends EventSource> EventSourceRegistration<T> registerEventSource(T eventSource);
-
}
package org.opendaylight.controller.messagebus.app.util;
+import com.google.common.util.concurrent.Futures;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
-
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import com.google.common.util.concurrent.Futures;
-
-
public final class Util {
+ private Util() {
+ }
public static <T> Future<RpcResult<T>> resultRpcSuccessFor(final T output) {
final RpcResult<T> result = RpcResultBuilder.success(output).build();
}
/**
- * Method filters qnames based on wildcard strings
+ * Method filters qnames based on wildcard strings.
*
- * @param list
+ * @param list list of SchemaPaths
* @param pattern matching pattern
* @return list of filtered qnames
*/
}
/**
- * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html
- * @param wildcard
- * @return
+ * CREDIT to http://www.rgagnon.com/javadetails/java-0515.html.
*/
- public static String wildcardToRegex(final String wildcard){
+ public static String wildcardToRegex(final String wildcard) {
final StringBuilder s = new StringBuilder(wildcard.length());
s.append('^');
for (final char c : wildcard.toCharArray()) {
- switch(c) {
+ switch (c) {
case '*':
s.append(".*");
break;
public class TopicDOMNotificationTest {
- private static final String containerNodeBodyMockToString = "containerNodeBodyMock";
+ private static final String CONTAINER_NODE_BODY_MOCK_TO_STRING = "containerNodeBodyMock";
ContainerNode containerNodeBodyMock;
TopicDOMNotification topicDOMNotification;
@Before
public void setUp() throws Exception {
containerNodeBodyMock = mock(ContainerNode.class);
- doReturn(containerNodeBodyMockToString).when(containerNodeBodyMock).toString();
+ doReturn(CONTAINER_NODE_BODY_MOCK_TO_STRING).when(containerNodeBodyMock).toString();
topicDOMNotification = new TopicDOMNotification(containerNodeBodyMock);
}
@Test
public void getTypeTest() {
- SchemaPath TOPIC_NOTIFICATION_ID = SchemaPath.create(true, TopicNotification.QNAME);
- assertEquals("Type has not been created correctly.", TOPIC_NOTIFICATION_ID, topicDOMNotification.getType());
+ SchemaPath topicNotificationId = SchemaPath.create(true, TopicNotification.QNAME);
+ assertEquals("Type has not been created correctly.", topicNotificationId, topicDOMNotification.getType());
}
@Test
@Test
public void getToStringTest() {
- String bodyString = "TopicDOMNotification [body=" + containerNodeBodyMockToString + "]";
+ String bodyString = "TopicDOMNotification [body=" + CONTAINER_NODE_BODY_MOCK_TO_STRING + "]";
assertEquals("String has not been created correctly.", bodyString, topicDOMNotification.toString());
}
-}
\ No newline at end of file
+}
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
/**
- * @author ppalmar
+ * Unit tests for Util.
*
+ * @author ppalmar
*/
public class UtilTest {