Committed by
bharat saraswal-huawei
[ONOS-3111] Port pair group manager test case fixed
Change-Id: I790efe18ef4c536f09e3b315c65d866ee558049d
Showing
2 changed files
with
46 additions
and
1 deletions
| ... | @@ -30,6 +30,8 @@ import org.onlab.util.KryoNamespace; | ... | @@ -30,6 +30,8 @@ import org.onlab.util.KryoNamespace; |
| 30 | import org.onosproject.event.AbstractListenerManager; | 30 | import org.onosproject.event.AbstractListenerManager; |
| 31 | import org.onosproject.store.serializers.KryoNamespaces; | 31 | import org.onosproject.store.serializers.KryoNamespaces; |
| 32 | import org.onosproject.store.service.EventuallyConsistentMap; | 32 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 33 | +import org.onosproject.store.service.EventuallyConsistentMapEvent; | ||
| 34 | +import org.onosproject.store.service.EventuallyConsistentMapListener; | ||
| 33 | import org.onosproject.store.service.MultiValuedTimestamp; | 35 | import org.onosproject.store.service.MultiValuedTimestamp; |
| 34 | import org.onosproject.store.service.StorageService; | 36 | import org.onosproject.store.service.StorageService; |
| 35 | import org.onosproject.store.service.WallClockTimestamp; | 37 | import org.onosproject.store.service.WallClockTimestamp; |
| ... | @@ -51,17 +53,21 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE | ... | @@ -51,17 +53,21 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE |
| 51 | private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null"; | 53 | private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null"; |
| 52 | private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null"; | 54 | private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null"; |
| 53 | private static final String LISTENER_NOT_NULL = "Listener cannot be null"; | 55 | private static final String LISTENER_NOT_NULL = "Listener cannot be null"; |
| 56 | + private static final String EVENT_NOT_NULL = "event cannot be null"; | ||
| 54 | 57 | ||
| 55 | private final Logger log = getLogger(getClass()); | 58 | private final Logger log = getLogger(getClass()); |
| 56 | 59 | ||
| 57 | private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore; | 60 | private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore; |
| 58 | 61 | ||
| 62 | + private EventuallyConsistentMapListener<PortPairGroupId, PortPairGroup> portPairGroupListener = | ||
| 63 | + new InnerPortPairGroupStoreListener(); | ||
| 64 | + | ||
| 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 65 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 60 | protected StorageService storageService; | 66 | protected StorageService storageService; |
| 61 | 67 | ||
| 62 | @Activate | 68 | @Activate |
| 63 | public void activate() { | 69 | public void activate() { |
| 64 | - | 70 | + eventDispatcher.addSink(PortPairGroupEvent.class, listenerRegistry); |
| 65 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | 71 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 66 | .register(KryoNamespaces.API) | 72 | .register(KryoNamespaces.API) |
| 67 | .register(MultiValuedTimestamp.class) | 73 | .register(MultiValuedTimestamp.class) |
| ... | @@ -72,11 +78,14 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE | ... | @@ -72,11 +78,14 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE |
| 72 | .withName("portpairgroupstore").withSerializer(serializer) | 78 | .withName("portpairgroupstore").withSerializer(serializer) |
| 73 | .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); | 79 | .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); |
| 74 | 80 | ||
| 81 | + portPairGroupStore.addListener(portPairGroupListener); | ||
| 82 | + | ||
| 75 | log.info("Started"); | 83 | log.info("Started"); |
| 76 | } | 84 | } |
| 77 | 85 | ||
| 78 | @Deactivate | 86 | @Deactivate |
| 79 | public void deactivate() { | 87 | public void deactivate() { |
| 88 | + eventDispatcher.removeSink(PortPairGroupEvent.class); | ||
| 80 | portPairGroupStore.destroy(); | 89 | portPairGroupStore.destroy(); |
| 81 | log.info("Stopped"); | 90 | log.info("Stopped"); |
| 82 | } | 91 | } |
| ... | @@ -148,4 +157,36 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE | ... | @@ -148,4 +157,36 @@ public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupE |
| 148 | } | 157 | } |
| 149 | return true; | 158 | return true; |
| 150 | } | 159 | } |
| 160 | + | ||
| 161 | + | ||
| 162 | + private class InnerPortPairGroupStoreListener | ||
| 163 | + implements | ||
| 164 | + EventuallyConsistentMapListener<PortPairGroupId, PortPairGroup> { | ||
| 165 | + | ||
| 166 | + @Override | ||
| 167 | + public void event(EventuallyConsistentMapEvent<PortPairGroupId, PortPairGroup> event) { | ||
| 168 | + checkNotNull(event, EVENT_NOT_NULL); | ||
| 169 | + PortPairGroup portPairGroup = event.value(); | ||
| 170 | + if (EventuallyConsistentMapEvent.Type.PUT == event.type()) { | ||
| 171 | + notifyListeners(new PortPairGroupEvent( | ||
| 172 | + PortPairGroupEvent.Type.PORT_PAIR_GROUP_PUT, | ||
| 173 | + portPairGroup)); | ||
| 174 | + } | ||
| 175 | + if (EventuallyConsistentMapEvent.Type.REMOVE == event.type()) { | ||
| 176 | + notifyListeners(new PortPairGroupEvent( | ||
| 177 | + PortPairGroupEvent.Type.PORT_PAIR_GROUP_DELETE, | ||
| 178 | + portPairGroup)); | ||
| 179 | + } | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * Notifies specify event to all listeners. | ||
| 185 | + * | ||
| 186 | + * @param event PortPairGroup event | ||
| 187 | + */ | ||
| 188 | + private void notifyListeners(PortPairGroupEvent event) { | ||
| 189 | + checkNotNull(event, EVENT_NOT_NULL); | ||
| 190 | + post(event); | ||
| 191 | + } | ||
| 151 | } | 192 | } | ... | ... |
| ... | @@ -29,6 +29,9 @@ import org.onosproject.vtnrsc.PortPairGroupId; | ... | @@ -29,6 +29,9 @@ import org.onosproject.vtnrsc.PortPairGroupId; |
| 29 | import org.onosproject.vtnrsc.TenantId; | 29 | import org.onosproject.vtnrsc.TenantId; |
| 30 | import org.onosproject.vtnrsc.DefaultPortPairGroup; | 30 | import org.onosproject.vtnrsc.DefaultPortPairGroup; |
| 31 | import org.onosproject.vtnrsc.util.VtnStorageServiceTest; | 31 | import org.onosproject.vtnrsc.util.VtnStorageServiceTest; |
| 32 | +import org.onosproject.common.event.impl.TestEventDispatcher; | ||
| 33 | + | ||
| 34 | +import static org.onosproject.net.NetTestTools.injectEventDispatcher; | ||
| 32 | 35 | ||
| 33 | /** | 36 | /** |
| 34 | * Unit tests for PortPairGroupManager class. | 37 | * Unit tests for PortPairGroupManager class. |
| ... | @@ -51,6 +54,7 @@ public class PortPairGroupManagerTest { | ... | @@ -51,6 +54,7 @@ public class PortPairGroupManagerTest { |
| 51 | public void testCreatePortPairGroup() { | 54 | public void testCreatePortPairGroup() { |
| 52 | // initialize port pair group manager | 55 | // initialize port pair group manager |
| 53 | portPairGroupMgr.storageService = storageService; | 56 | portPairGroupMgr.storageService = storageService; |
| 57 | + injectEventDispatcher(portPairGroupMgr, new TestEventDispatcher()); | ||
| 54 | portPairGroupMgr.activate(); | 58 | portPairGroupMgr.activate(); |
| 55 | 59 | ||
| 56 | // create port-pair-id list | 60 | // create port-pair-id list | ... | ... |
-
Please register or login to post a comment