From e3c31cee916480b2d9d169c1f5afb1c42efaabe1 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Fri, 29 Jul 2016 16:27:12 +0200 Subject: HONEYCOMB-130: Rename infra packages(remove vpp/v3po) Change-Id: Ic5b90e397e3743623d01b206bc60bc5c7df6b981 Signed-off-by: Maros Marsalek --- .../main/config/notification-to-netconf-config.xml | 4 +- .../impl/HoneycombNotificationCollector.java | 66 ++++++++++++ .../impl/NotificationProducerRegistry.java | 112 +++++++++++++++++++++ .../impl/NotificationProducerTracker.java | 109 ++++++++++++++++++++ .../impl/HoneycombNotificationCollector.java | 66 ------------ .../impl/NotificationProducerRegistry.java | 112 --------------------- .../impl/NotificationProducerTracker.java | 109 -------------------- .../HoneycombNotificationManagerModule.java | 10 +- ...ycombNotificationToNetconfTranslatorModule.java | 4 +- .../impl/HoneycombNotificationCollectorTest.java | 63 ++++++++++++ .../impl/NotificationProducerRegistryTest.java | 98 ++++++++++++++++++ .../impl/NotificationProducerTrackerTest.java | 67 ++++++++++++ .../impl/HoneycombNotificationCollectorTest.java | 63 ------------ .../impl/NotificationProducerRegistryTest.java | 98 ------------------ .../impl/NotificationProducerTrackerTest.java | 67 ------------ 15 files changed, 524 insertions(+), 524 deletions(-) create mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollector.java create mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistry.java create mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerTracker.java delete mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollector.java delete mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistry.java delete mode 100644 infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTracker.java create mode 100644 infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollectorTest.java create mode 100644 infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistryTest.java create mode 100644 infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerTrackerTest.java delete mode 100644 infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollectorTest.java delete mode 100644 infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistryTest.java delete mode 100644 infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTrackerTest.java (limited to 'infra/notification/impl/src') diff --git a/infra/notification/impl/src/main/config/notification-to-netconf-config.xml b/infra/notification/impl/src/main/config/notification-to-netconf-config.xml index d2aac0932..d64de6413 100644 --- a/infra/notification/impl/src/main/config/notification-to-netconf-config.xml +++ b/infra/notification/impl/src/main/config/notification-to-netconf-config.xml @@ -29,13 +29,13 @@ prefix:netconf-notification-registry - vpp-netconf-notification-manager + honeycomb-netconf-notification-manager prefix:netconf-notification-collector - vpp-netconf-notification-manager + honeycomb-netconf-notification-manager dom:schema-service diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollector.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollector.java new file mode 100644 index 000000000..c37e6925c --- /dev/null +++ b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollector.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.notification.impl; + +import io.fd.honeycomb.notification.NotificationCollector; +import java.util.Collection; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Notification collector based on MD-SAL's {@link NotificationPublishService}. + */ +public final class HoneycombNotificationCollector implements NotificationCollector, AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(HoneycombNotificationCollector.class); + + private final NotificationPublishService bindingDOMNotificationPublishServiceAdapter; + private final NotificationProducerRegistry notificationProducerRegistry; + + public HoneycombNotificationCollector( + @Nonnull final NotificationPublishService bindingDOMNotificationPublishServiceAdapter, + @Nonnull final NotificationProducerRegistry notificationProducerRegistry) { + this.bindingDOMNotificationPublishServiceAdapter = bindingDOMNotificationPublishServiceAdapter; + this.notificationProducerRegistry = notificationProducerRegistry; + } + + @Override + public void close() throws Exception { + LOG.trace("Closing"); + } + + @Override + public void onNotification(@Nonnull final Notification notification) { + LOG.debug("Notification: {} pushed into collector", notification.getClass().getSimpleName()); + LOG.trace("Notification: {} pushed into collector", notification); + try { + bindingDOMNotificationPublishServiceAdapter.putNotification(notification); + } catch (InterruptedException e) { + LOG.warn("Interrupted", e); + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } + } + + @Override + @Nonnull + public Collection> getNotificationTypes() { + return notificationProducerRegistry.getNotificationTypes(); + } +} diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistry.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistry.java new file mode 100644 index 000000000..7b46c60b7 --- /dev/null +++ b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistry.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.notification.impl; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import io.fd.honeycomb.notification.ManagedNotificationProducer; +import io.fd.honeycomb.notification.NotificationProducer; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.concurrent.ThreadSafe; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.common.QName; + +/** + * Holds the collection of registered notification producers. + * Provides additional information about the types of notifications produced per producer and overall. + */ +@ThreadSafe +public final class NotificationProducerRegistry { + + private final Set> notificationTypes; + private final Map notificationQNameToProducer; + private final Multimap notificationProducerQNames; + + public NotificationProducerRegistry(final List notificationProducersDependency) { + this.notificationTypes = toTypes(notificationProducersDependency); + this.notificationQNameToProducer = toQNameMap(notificationProducersDependency); + this.notificationProducerQNames = toQNameMapReversed(notificationProducersDependency); + } + + private static Multimap toQNameMapReversed(final List notificationProducers) { + final Multimap multimap = HashMultimap.create(); + + for (ManagedNotificationProducer producer : notificationProducers) { + for (Class aClass : producer.getNotificationTypes()) { + multimap.put(producer, getQName(aClass)); + } + } + return multimap; + } + + private static Set> toTypes(final List notificationProducersDependency) { + // Get all notification types registered from HC notification producers + return notificationProducersDependency + .stream() + .flatMap(producer -> producer.getNotificationTypes().stream()) + .collect(Collectors.toSet()); + } + + + private static Map toQNameMap(final List producerDependencies) { + // Only a single notification producer per notification type is allowed + final Map qNamesToProducers = Maps.newHashMap(); + for (ManagedNotificationProducer notificationProducer : producerDependencies) { + for (QName qName : typesToQNames(notificationProducer.getNotificationTypes())) { + final NotificationProducer previousProducer = qNamesToProducers.put(qName, notificationProducer); + checkArgument(previousProducer == null, "2 producers of the same notification type: %s. " + + "Producer 1: {} Producer 2: {}" , qName, previousProducer, notificationProducer); + } + } + return qNamesToProducers; + } + + + private static Set typesToQNames(final Collection> notificationTypes) { + return notificationTypes + .stream() + .map(NotificationProducerRegistry::getQName) + .collect(Collectors.toSet()); + } + + + public static QName getQName(final Class aClass) { + try { + return (QName) aClass.getField("QNAME").get(null); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new IllegalArgumentException("Unable to retrieve QName for notification of type: " + aClass, e); + } + } + + Set> getNotificationTypes() { + return notificationTypes; + } + + Map getNotificationQNameToProducer() { + return notificationQNameToProducer; + } + + Multimap getNotificationProducerQNames() { + return notificationProducerQNames; + } +} diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerTracker.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerTracker.java new file mode 100644 index 000000000..808512c21 --- /dev/null +++ b/infra/notification/impl/src/main/java/io/fd/honeycomb/notification/impl/NotificationProducerTracker.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.notification.impl; + +import static com.google.common.base.Preconditions.checkState; + +import com.google.common.collect.Sets; +import io.fd.honeycomb.notification.ManagedNotificationProducer; +import io.fd.honeycomb.notification.NotificationCollector; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import javax.annotation.Nonnull; +import javax.annotation.concurrent.ThreadSafe; +import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListener; +import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Starts & stops notification producer dependencies on demand. + * Uses {@link DOMNotificationSubscriptionListenerRegistry} to receive subscription change notifications. + */ +@ThreadSafe +public final class NotificationProducerTracker + implements DOMNotificationSubscriptionListener, AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(NotificationProducerTracker.class); + + private final ListenerRegistration subscriptionListener; + private final NotificationProducerRegistry registry; + private final NotificationCollector collector; + + private final Set alreadyStartedProducers = new HashSet<>(); + + public NotificationProducerTracker(@Nonnull final NotificationProducerRegistry registry, + @Nonnull final NotificationCollector collector, + @Nonnull final DOMNotificationSubscriptionListenerRegistry notificationRouter) { + this.registry = registry; + this.collector = collector; + this.subscriptionListener = notificationRouter.registerSubscriptionListener(this); + } + + @Override + public synchronized void onSubscriptionChanged(final Set set) { + LOG.debug("Subscriptions changed. Current subscriptions: {}", set); + final Set currentSubscriptions = set.stream().map(SchemaPath::getLastComponent).collect(Collectors.toSet()); + final Set startedQNames = getStartedQNames(alreadyStartedProducers); + final Sets.SetView newSubscriptions = Sets.difference(currentSubscriptions, startedQNames); + LOG.debug("Subscriptions changed. New subscriptions: {}", newSubscriptions); + final Sets.SetView deletedSubscriptions = Sets.difference(startedQNames, currentSubscriptions); + LOG.debug("Subscriptions changed. Deleted subscriptions: {}", deletedSubscriptions); + + newSubscriptions.stream().forEach(newSub -> { + if(!registry.getNotificationQNameToProducer().containsKey(newSub)) { + return; + } + final ManagedNotificationProducer producer = registry.getNotificationQNameToProducer().get(newSub); + if(alreadyStartedProducers.contains(producer)) { + return; + } + LOG.debug("Starting notification producer: {}", producer); + producer.start(collector); + alreadyStartedProducers.add(producer); + }); + + deletedSubscriptions.stream().forEach(newSub -> { + checkState(registry.getNotificationQNameToProducer().containsKey(newSub)); + final ManagedNotificationProducer producer = registry.getNotificationQNameToProducer().get(newSub); + checkState(alreadyStartedProducers.contains(producer)); + LOG.debug("Stopping notification producer: {}", producer); + producer.stop(); + alreadyStartedProducers.remove(producer); + }); + + } + + private Set getStartedQNames(final Set alreadyStartedProducers) { + return alreadyStartedProducers.stream() + .flatMap(p -> registry.getNotificationProducerQNames().get(p).stream()) + .collect(Collectors.toSet()); + } + + @Override + public synchronized void close() throws Exception { + LOG.trace("Closing"); + subscriptionListener.close(); + // Stop all producers + LOG.debug("Stopping all producers: {}", alreadyStartedProducers); + alreadyStartedProducers.forEach(ManagedNotificationProducer::stop); + alreadyStartedProducers.clear(); + } +} diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollector.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollector.java deleted file mode 100644 index e7d54e318..000000000 --- a/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollector.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fd.honeycomb.v3po.notification.impl; - -import io.fd.honeycomb.v3po.notification.NotificationCollector; -import java.util.Collection; -import javax.annotation.Nonnull; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Notification collector based on MD-SAL's {@link NotificationPublishService}. - */ -public final class HoneycombNotificationCollector implements NotificationCollector, AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(HoneycombNotificationCollector.class); - - private final NotificationPublishService bindingDOMNotificationPublishServiceAdapter; - private final NotificationProducerRegistry notificationProducerRegistry; - - public HoneycombNotificationCollector( - @Nonnull final NotificationPublishService bindingDOMNotificationPublishServiceAdapter, - @Nonnull final NotificationProducerRegistry notificationProducerRegistry) { - this.bindingDOMNotificationPublishServiceAdapter = bindingDOMNotificationPublishServiceAdapter; - this.notificationProducerRegistry = notificationProducerRegistry; - } - - @Override - public void close() throws Exception { - LOG.trace("Closing"); - } - - @Override - public void onNotification(@Nonnull final Notification notification) { - LOG.debug("Notification: {} pushed into collector", notification.getClass().getSimpleName()); - LOG.trace("Notification: {} pushed into collector", notification); - try { - bindingDOMNotificationPublishServiceAdapter.putNotification(notification); - } catch (InterruptedException e) { - LOG.warn("Interrupted", e); - Thread.currentThread().interrupt(); - throw new RuntimeException(e); - } - } - - @Override - @Nonnull - public Collection> getNotificationTypes() { - return notificationProducerRegistry.getNotificationTypes(); - } -} diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistry.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistry.java deleted file mode 100644 index 8fba700bd..000000000 --- a/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistry.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fd.honeycomb.v3po.notification.impl; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import io.fd.honeycomb.v3po.notification.ManagedNotificationProducer; -import io.fd.honeycomb.v3po.notification.NotificationProducer; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.concurrent.ThreadSafe; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.opendaylight.yangtools.yang.common.QName; - -/** - * Holds the collection of registered notification producers. - * Provides additional information about the types of notifications produced per producer and overall. - */ -@ThreadSafe -public final class NotificationProducerRegistry { - - private final Set> notificationTypes; - private final Map notificationQNameToProducer; - private final Multimap notificationProducerQNames; - - public NotificationProducerRegistry(final List notificationProducersDependency) { - this.notificationTypes = toTypes(notificationProducersDependency); - this.notificationQNameToProducer = toQNameMap(notificationProducersDependency); - this.notificationProducerQNames = toQNameMapReversed(notificationProducersDependency); - } - - private static Multimap toQNameMapReversed(final List notificationProducers) { - final Multimap multimap = HashMultimap.create(); - - for (ManagedNotificationProducer producer : notificationProducers) { - for (Class aClass : producer.getNotificationTypes()) { - multimap.put(producer, getQName(aClass)); - } - } - return multimap; - } - - private static Set> toTypes(final List notificationProducersDependency) { - // Get all notification types registered from HC notification producers - return notificationProducersDependency - .stream() - .flatMap(producer -> producer.getNotificationTypes().stream()) - .collect(Collectors.toSet()); - } - - - private static Map toQNameMap(final List producerDependencies) { - // Only a single notification producer per notification type is allowed - final Map qNamesToProducers = Maps.newHashMap(); - for (ManagedNotificationProducer notificationProducer : producerDependencies) { - for (QName qName : typesToQNames(notificationProducer.getNotificationTypes())) { - final NotificationProducer previousProducer = qNamesToProducers.put(qName, notificationProducer); - checkArgument(previousProducer == null, "2 producers of the same notification type: %s. " + - "Producer 1: {} Producer 2: {}" , qName, previousProducer, notificationProducer); - } - } - return qNamesToProducers; - } - - - private static Set typesToQNames(final Collection> notificationTypes) { - return notificationTypes - .stream() - .map(NotificationProducerRegistry::getQName) - .collect(Collectors.toSet()); - } - - - public static QName getQName(final Class aClass) { - try { - return (QName) aClass.getField("QNAME").get(null); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new IllegalArgumentException("Unable to retrieve QName for notification of type: " + aClass, e); - } - } - - Set> getNotificationTypes() { - return notificationTypes; - } - - Map getNotificationQNameToProducer() { - return notificationQNameToProducer; - } - - Multimap getNotificationProducerQNames() { - return notificationProducerQNames; - } -} diff --git a/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTracker.java b/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTracker.java deleted file mode 100644 index cefb50ac9..000000000 --- a/infra/notification/impl/src/main/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTracker.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fd.honeycomb.v3po.notification.impl; - -import static com.google.common.base.Preconditions.checkState; - -import com.google.common.collect.Sets; -import io.fd.honeycomb.v3po.notification.ManagedNotificationProducer; -import io.fd.honeycomb.v3po.notification.NotificationCollector; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.ThreadSafe; -import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListener; -import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Starts & stops notification producer dependencies on demand. - * Uses {@link DOMNotificationSubscriptionListenerRegistry} to receive subscription change notifications. - */ -@ThreadSafe -public final class NotificationProducerTracker - implements DOMNotificationSubscriptionListener, AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(NotificationProducerTracker.class); - - private final ListenerRegistration subscriptionListener; - private final NotificationProducerRegistry registry; - private final NotificationCollector collector; - - private final Set alreadyStartedProducers = new HashSet<>(); - - public NotificationProducerTracker(@Nonnull final NotificationProducerRegistry registry, - @Nonnull final NotificationCollector collector, - @Nonnull final DOMNotificationSubscriptionListenerRegistry notificationRouter) { - this.registry = registry; - this.collector = collector; - this.subscriptionListener = notificationRouter.registerSubscriptionListener(this); - } - - @Override - public synchronized void onSubscriptionChanged(final Set set) { - LOG.debug("Subscriptions changed. Current subscriptions: {}", set); - final Set currentSubscriptions = set.stream().map(SchemaPath::getLastComponent).collect(Collectors.toSet()); - final Set startedQNames = getStartedQNames(alreadyStartedProducers); - final Sets.SetView newSubscriptions = Sets.difference(currentSubscriptions, startedQNames); - LOG.debug("Subscriptions changed. New subscriptions: {}", newSubscriptions); - final Sets.SetView deletedSubscriptions = Sets.difference(startedQNames, currentSubscriptions); - LOG.debug("Subscriptions changed. Deleted subscriptions: {}", deletedSubscriptions); - - newSubscriptions.stream().forEach(newSub -> { - if(!registry.getNotificationQNameToProducer().containsKey(newSub)) { - return; - } - final ManagedNotificationProducer producer = registry.getNotificationQNameToProducer().get(newSub); - if(alreadyStartedProducers.contains(producer)) { - return; - } - LOG.debug("Starting notification producer: {}", producer); - producer.start(collector); - alreadyStartedProducers.add(producer); - }); - - deletedSubscriptions.stream().forEach(newSub -> { - checkState(registry.getNotificationQNameToProducer().containsKey(newSub)); - final ManagedNotificationProducer producer = registry.getNotificationQNameToProducer().get(newSub); - checkState(alreadyStartedProducers.contains(producer)); - LOG.debug("Stopping notification producer: {}", producer); - producer.stop(); - alreadyStartedProducers.remove(producer); - }); - - } - - private Set getStartedQNames(final Set alreadyStartedProducers) { - return alreadyStartedProducers.stream() - .flatMap(p -> registry.getNotificationProducerQNames().get(p).stream()) - .collect(Collectors.toSet()); - } - - @Override - public synchronized void close() throws Exception { - LOG.trace("Closing"); - subscriptionListener.close(); - // Stop all producers - LOG.debug("Stopping all producers: {}", alreadyStartedProducers); - alreadyStartedProducers.forEach(ManagedNotificationProducer::stop); - alreadyStartedProducers.clear(); - } -} diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java index 4a9440cbc..056b38798 100644 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java +++ b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationManagerModule.java @@ -1,10 +1,10 @@ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; -import io.fd.honeycomb.v3po.notification.NotificationCollector; -import io.fd.honeycomb.v3po.notification.NotificationProducer; -import io.fd.honeycomb.v3po.notification.impl.HoneycombNotificationCollector; -import io.fd.honeycomb.v3po.notification.impl.NotificationProducerRegistry; -import io.fd.honeycomb.v3po.notification.impl.NotificationProducerTracker; +import io.fd.honeycomb.notification.NotificationCollector; +import io.fd.honeycomb.notification.NotificationProducer; +import io.fd.honeycomb.notification.impl.HoneycombNotificationCollector; +import io.fd.honeycomb.notification.impl.NotificationProducerRegistry; +import io.fd.honeycomb.notification.impl.NotificationProducerTracker; import java.util.Collection; import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter; import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; diff --git a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java index 4d85d64c5..734d340e8 100644 --- a/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java +++ b/infra/notification/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/notification/impl/rev160601/HoneycombNotificationToNetconfTranslatorModule.java @@ -1,8 +1,8 @@ package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601; import com.google.common.annotations.VisibleForTesting; -import io.fd.honeycomb.v3po.notification.NotificationCollector; -import io.fd.honeycomb.v3po.notification.impl.NotificationProducerRegistry; +import io.fd.honeycomb.notification.NotificationCollector; +import io.fd.honeycomb.notification.impl.NotificationProducerRegistry; import java.io.IOException; import java.util.Set; import java.util.stream.Collectors; diff --git a/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollectorTest.java b/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollectorTest.java new file mode 100644 index 000000000..ef9f548b7 --- /dev/null +++ b/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/HoneycombNotificationCollectorTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.notification.impl; + +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.verify; + +import com.google.common.collect.Lists; +import io.fd.honeycomb.notification.ManagedNotificationProducer; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStartBuilder; + +public class HoneycombNotificationCollectorTest { + + private NotificationProducerRegistry notificationRegistry; + @Mock + private NotificationPublishService notificationService; + @Mock + private ManagedNotificationProducer producer; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + notificationRegistry = new NotificationProducerRegistry(Lists.newArrayList(producer)); + } + + @Test + public void testNotificationTypes() throws Exception { + final HoneycombNotificationCollector honeycombNotificationCollector = + new HoneycombNotificationCollector(notificationService, notificationRegistry); + + honeycombNotificationCollector.getNotificationTypes(); + verify(producer, atLeast(1)).getNotificationTypes(); + } + + @Test + public void testCollect() throws Exception { + final HoneycombNotificationCollector honeycombNotificationCollector = + new HoneycombNotificationCollector(notificationService, notificationRegistry); + + final NetconfSessionStart notif = new NetconfSessionStartBuilder().build(); + honeycombNotificationCollector.onNotification(notif); + verify(notificationService).putNotification(notif); + } +} \ No newline at end of file diff --git a/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistryTest.java b/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistryTest.java new file mode 100644 index 000000000..a09803f02 --- /dev/null +++ b/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerRegistryTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.notification.impl; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.doReturn; + +import com.google.common.collect.Lists; +import com.google.common.collect.Multimap; +import io.fd.honeycomb.notification.ManagedNotificationProducer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.Set; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.common.QName; + +public class NotificationProducerRegistryTest { + + @Mock + private ManagedNotificationProducer producer; + @Mock + private ManagedNotificationProducer producer2; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + doReturn(Collections.singleton(NetconfCapabilityChange.class)) + .when(producer).getNotificationTypes(); + final ArrayList producer2Notifications = Lists.newArrayList(); + producer2Notifications.add(NetconfSessionStart.class); + producer2Notifications.add(NetconfSessionEnd.class); + doReturn(producer2Notifications).when(producer2).getNotificationTypes(); + } + + @Test + public void testNotificationTypes() throws Exception { + final NotificationProducerRegistry notificationRegistry = + new NotificationProducerRegistry(Lists.newArrayList(producer, producer2)); + + final Set> notificationTypes = + notificationRegistry.getNotificationTypes(); + + Assert.assertThat(notificationTypes, hasItem(NetconfSessionEnd.class)); + Assert.assertThat(notificationTypes, hasItem(NetconfSessionStart.class)); + Assert.assertThat(notificationTypes, hasItem(NetconfCapabilityChange.class)); + } + + @Test + public void testNotificationTypesMapped() throws Exception { + final NotificationProducerRegistry notificationRegistry = + new NotificationProducerRegistry(Lists.newArrayList(producer, producer2)); + + final Multimap notificationTypes = + notificationRegistry.getNotificationProducerQNames(); + + Assert.assertThat(notificationTypes.keySet(), hasItem(producer)); + Assert.assertThat(notificationTypes.get(producer), hasItem(NetconfCapabilityChange.QNAME)); + Assert.assertThat(notificationTypes.keySet(), hasItem(producer2)); + Assert.assertThat(notificationTypes.get(producer2), hasItem(NetconfSessionStart.QNAME)); + Assert.assertThat(notificationTypes.get(producer2), hasItem(NetconfSessionEnd.QNAME)); + + final Map notificationQNameToProducer = + notificationRegistry.getNotificationQNameToProducer(); + + Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfCapabilityChange.QNAME)); + Assert.assertThat(notificationQNameToProducer.get(NetconfCapabilityChange.QNAME), is(producer)); + + Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfSessionStart.QNAME)); + Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfSessionEnd.QNAME)); + Assert.assertThat(notificationQNameToProducer.get(NetconfSessionStart.QNAME), is(producer2)); + Assert.assertThat(notificationQNameToProducer.get(NetconfSessionEnd.QNAME), is(producer2)); + + + } +} \ No newline at end of file diff --git a/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerTrackerTest.java b/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerTrackerTest.java new file mode 100644 index 000000000..4de2e7773 --- /dev/null +++ b/infra/notification/impl/src/test/java/io/fd/honeycomb/notification/impl/NotificationProducerTrackerTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.fd.honeycomb.notification.impl; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import io.fd.honeycomb.notification.ManagedNotificationProducer; +import io.fd.honeycomb.notification.NotificationCollector; +import java.util.Collections; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; + +public class NotificationProducerTrackerTest { + + private NotificationProducerRegistry registry; + @Mock + private DOMNotificationSubscriptionListenerRegistry subscriptionRegistry; + @Mock + private NotificationCollector collector; + @Mock + private ManagedNotificationProducer producer; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + doReturn(Collections.singleton(NetconfSessionStart.class)).when(producer).getNotificationTypes(); + registry = new NotificationProducerRegistry(Lists.newArrayList(producer)); + } + + @Test + public void name() throws Exception { + final NotificationProducerTracker notificationProducerTracker = + new NotificationProducerTracker(registry, collector, subscriptionRegistry); + verify(subscriptionRegistry).registerSubscriptionListener(notificationProducerTracker); + + final Set subscriptions = Sets.newHashSet(); + subscriptions.add(SchemaPath.create(true, NetconfSessionStart.QNAME)); + notificationProducerTracker.onSubscriptionChanged(subscriptions); + + verify(producer).start(collector); + + notificationProducerTracker.onSubscriptionChanged(Sets.newHashSet()); + verify(producer).stop(); + } +} \ No newline at end of file diff --git a/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollectorTest.java b/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollectorTest.java deleted file mode 100644 index f55d3abdf..000000000 --- a/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/HoneycombNotificationCollectorTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fd.honeycomb.v3po.notification.impl; - -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.verify; - -import com.google.common.collect.Lists; -import io.fd.honeycomb.v3po.notification.ManagedNotificationProducer; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStartBuilder; - -public class HoneycombNotificationCollectorTest { - - private NotificationProducerRegistry notificationRegistry; - @Mock - private NotificationPublishService notificationService; - @Mock - private ManagedNotificationProducer producer; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - notificationRegistry = new NotificationProducerRegistry(Lists.newArrayList(producer)); - } - - @Test - public void testNotificationTypes() throws Exception { - final HoneycombNotificationCollector honeycombNotificationCollector = - new HoneycombNotificationCollector(notificationService, notificationRegistry); - - honeycombNotificationCollector.getNotificationTypes(); - verify(producer, atLeast(1)).getNotificationTypes(); - } - - @Test - public void testCollect() throws Exception { - final HoneycombNotificationCollector honeycombNotificationCollector = - new HoneycombNotificationCollector(notificationService, notificationRegistry); - - final NetconfSessionStart notif = new NetconfSessionStartBuilder().build(); - honeycombNotificationCollector.onNotification(notif); - verify(notificationService).putNotification(notif); - } -} \ No newline at end of file diff --git a/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistryTest.java b/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistryTest.java deleted file mode 100644 index 5fdf502b9..000000000 --- a/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerRegistryTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fd.honeycomb.v3po.notification.impl; - -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.Mockito.doReturn; - -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import io.fd.honeycomb.v3po.notification.ManagedNotificationProducer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; -import org.opendaylight.yangtools.yang.binding.Notification; -import org.opendaylight.yangtools.yang.common.QName; - -public class NotificationProducerRegistryTest { - - @Mock - private ManagedNotificationProducer producer; - @Mock - private ManagedNotificationProducer producer2; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - doReturn(Collections.singleton(NetconfCapabilityChange.class)) - .when(producer).getNotificationTypes(); - final ArrayList producer2Notifications = Lists.newArrayList(); - producer2Notifications.add(NetconfSessionStart.class); - producer2Notifications.add(NetconfSessionEnd.class); - doReturn(producer2Notifications).when(producer2).getNotificationTypes(); - } - - @Test - public void testNotificationTypes() throws Exception { - final NotificationProducerRegistry notificationRegistry = - new NotificationProducerRegistry(Lists.newArrayList(producer, producer2)); - - final Set> notificationTypes = - notificationRegistry.getNotificationTypes(); - - Assert.assertThat(notificationTypes, hasItem(NetconfSessionEnd.class)); - Assert.assertThat(notificationTypes, hasItem(NetconfSessionStart.class)); - Assert.assertThat(notificationTypes, hasItem(NetconfCapabilityChange.class)); - } - - @Test - public void testNotificationTypesMapped() throws Exception { - final NotificationProducerRegistry notificationRegistry = - new NotificationProducerRegistry(Lists.newArrayList(producer, producer2)); - - final Multimap notificationTypes = - notificationRegistry.getNotificationProducerQNames(); - - Assert.assertThat(notificationTypes.keySet(), hasItem(producer)); - Assert.assertThat(notificationTypes.get(producer), hasItem(NetconfCapabilityChange.QNAME)); - Assert.assertThat(notificationTypes.keySet(), hasItem(producer2)); - Assert.assertThat(notificationTypes.get(producer2), hasItem(NetconfSessionStart.QNAME)); - Assert.assertThat(notificationTypes.get(producer2), hasItem(NetconfSessionEnd.QNAME)); - - final Map notificationQNameToProducer = - notificationRegistry.getNotificationQNameToProducer(); - - Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfCapabilityChange.QNAME)); - Assert.assertThat(notificationQNameToProducer.get(NetconfCapabilityChange.QNAME), is(producer)); - - Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfSessionStart.QNAME)); - Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfSessionEnd.QNAME)); - Assert.assertThat(notificationQNameToProducer.get(NetconfSessionStart.QNAME), is(producer2)); - Assert.assertThat(notificationQNameToProducer.get(NetconfSessionEnd.QNAME), is(producer2)); - - - } -} \ No newline at end of file diff --git a/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTrackerTest.java b/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTrackerTest.java deleted file mode 100644 index b62bf0709..000000000 --- a/infra/notification/impl/src/test/java/io/fd/honeycomb/v3po/notification/impl/NotificationProducerTrackerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2016 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.fd.honeycomb.v3po.notification.impl; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import io.fd.honeycomb.v3po.notification.ManagedNotificationProducer; -import io.fd.honeycomb.v3po.notification.NotificationCollector; -import java.util.Collections; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.dom.spi.DOMNotificationSubscriptionListenerRegistry; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -public class NotificationProducerTrackerTest { - - private NotificationProducerRegistry registry; - @Mock - private DOMNotificationSubscriptionListenerRegistry subscriptionRegistry; - @Mock - private NotificationCollector collector; - @Mock - private ManagedNotificationProducer producer; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - doReturn(Collections.singleton(NetconfSessionStart.class)).when(producer).getNotificationTypes(); - registry = new NotificationProducerRegistry(Lists.newArrayList(producer)); - } - - @Test - public void name() throws Exception { - final NotificationProducerTracker notificationProducerTracker = - new NotificationProducerTracker(registry, collector, subscriptionRegistry); - verify(subscriptionRegistry).registerSubscriptionListener(notificationProducerTracker); - - final Set subscriptions = Sets.newHashSet(); - subscriptions.add(SchemaPath.create(true, NetconfSessionStart.QNAME)); - notificationProducerTracker.onSubscriptionChanged(subscriptions); - - verify(producer).start(collector); - - notificationProducerTracker.onSubscriptionChanged(Sets.newHashSet()); - verify(producer).stop(); - } -} \ No newline at end of file -- cgit 1.2.3-korg