Committed by
Gerrit Code Review
[ONOS-3113] Flow Classifier Manager test case fixed
Change-Id: Ie4a35ec65f85ebf5ce5c20849d471fd3f947c405
Showing
3 changed files
with
51 additions
and
0 deletions
... | @@ -52,5 +52,12 @@ | ... | @@ -52,5 +52,12 @@ |
52 | <artifactId>onos-core-serializers</artifactId> | 52 | <artifactId>onos-core-serializers</artifactId> |
53 | <version>${project.version}</version> | 53 | <version>${project.version}</version> |
54 | </dependency> | 54 | </dependency> |
55 | + <dependency> | ||
56 | + <groupId>org.onosproject</groupId> | ||
57 | + <artifactId>onos-core-common</artifactId> | ||
58 | + <version>${project.version}</version> | ||
59 | + <classifier>tests</classifier> | ||
60 | + <scope>test</scope> | ||
61 | + </dependency> | ||
55 | </dependencies> | 62 | </dependencies> |
56 | </project> | 63 | </project> | ... | ... |
... | @@ -28,6 +28,8 @@ import org.onlab.util.KryoNamespace; | ... | @@ -28,6 +28,8 @@ import org.onlab.util.KryoNamespace; |
28 | import org.onosproject.event.AbstractListenerManager; | 28 | import org.onosproject.event.AbstractListenerManager; |
29 | import org.onosproject.store.serializers.KryoNamespaces; | 29 | import org.onosproject.store.serializers.KryoNamespaces; |
30 | import org.onosproject.store.service.EventuallyConsistentMap; | 30 | import org.onosproject.store.service.EventuallyConsistentMap; |
31 | +import org.onosproject.store.service.EventuallyConsistentMapEvent; | ||
32 | +import org.onosproject.store.service.EventuallyConsistentMapListener; | ||
31 | import org.onosproject.store.service.MultiValuedTimestamp; | 33 | import org.onosproject.store.service.MultiValuedTimestamp; |
32 | import org.onosproject.store.service.StorageService; | 34 | import org.onosproject.store.service.StorageService; |
33 | import org.onosproject.store.service.WallClockTimestamp; | 35 | import org.onosproject.store.service.WallClockTimestamp; |
... | @@ -51,16 +53,21 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie | ... | @@ -51,16 +53,21 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie |
51 | private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; | 53 | private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; |
52 | private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; | 54 | private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id 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(FlowClassifierManager.class); | 58 | private final Logger log = getLogger(FlowClassifierManager.class); |
56 | 59 | ||
57 | private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; | 60 | private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; |
58 | 61 | ||
62 | + private EventuallyConsistentMapListener<FlowClassifierId, FlowClassifier> flowClassifierListener = | ||
63 | + new InnerFlowClassifierStoreListener(); | ||
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 | protected void activate() { | 69 | protected void activate() { |
70 | + eventDispatcher.addSink(FlowClassifierEvent.class, listenerRegistry); | ||
64 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | 71 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
65 | .register(KryoNamespaces.API) | 72 | .register(KryoNamespaces.API) |
66 | .register(MultiValuedTimestamp.class) | 73 | .register(MultiValuedTimestamp.class) |
... | @@ -69,11 +76,13 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie | ... | @@ -69,11 +76,13 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie |
69 | .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder() | 76 | .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder() |
70 | .withName("flowclassifierstore").withSerializer(serializer) | 77 | .withName("flowclassifierstore").withSerializer(serializer) |
71 | .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); | 78 | .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); |
79 | + flowClassifierStore.addListener(flowClassifierListener); | ||
72 | log.info("Flow Classifier service activated"); | 80 | log.info("Flow Classifier service activated"); |
73 | } | 81 | } |
74 | 82 | ||
75 | @Deactivate | 83 | @Deactivate |
76 | protected void deactivate() { | 84 | protected void deactivate() { |
85 | + eventDispatcher.removeSink(FlowClassifierEvent.class); | ||
77 | flowClassifierStore.destroy(); | 86 | flowClassifierStore.destroy(); |
78 | log.info("Flow Classifier service deactivated"); | 87 | log.info("Flow Classifier service deactivated"); |
79 | } | 88 | } |
... | @@ -144,4 +153,35 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie | ... | @@ -144,4 +153,35 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie |
144 | } | 153 | } |
145 | return true; | 154 | return true; |
146 | } | 155 | } |
156 | + | ||
157 | + private class InnerFlowClassifierStoreListener | ||
158 | + implements | ||
159 | + EventuallyConsistentMapListener<FlowClassifierId, FlowClassifier> { | ||
160 | + | ||
161 | + @Override | ||
162 | + public void event(EventuallyConsistentMapEvent<FlowClassifierId, FlowClassifier> event) { | ||
163 | + checkNotNull(event, EVENT_NOT_NULL); | ||
164 | + FlowClassifier flowClassifier = event.value(); | ||
165 | + if (EventuallyConsistentMapEvent.Type.PUT == event.type()) { | ||
166 | + notifyListeners(new FlowClassifierEvent( | ||
167 | + FlowClassifierEvent.Type.FLOW_CLASSIFIER_PUT, | ||
168 | + flowClassifier)); | ||
169 | + } | ||
170 | + if (EventuallyConsistentMapEvent.Type.REMOVE == event.type()) { | ||
171 | + notifyListeners(new FlowClassifierEvent( | ||
172 | + FlowClassifierEvent.Type.FLOW_CLASSIFIER_DELETE, | ||
173 | + flowClassifier)); | ||
174 | + } | ||
175 | + } | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Notifies specify event to all listeners. | ||
180 | + * | ||
181 | + * @param event flow classifier event | ||
182 | + */ | ||
183 | + private void notifyListeners(FlowClassifierEvent event) { | ||
184 | + checkNotNull(event, EVENT_NOT_NULL); | ||
185 | + post(event); | ||
186 | + } | ||
147 | } | 187 | } | ... | ... |
... | @@ -29,6 +29,9 @@ import org.onosproject.vtnrsc.FlowClassifierId; | ... | @@ -29,6 +29,9 @@ import org.onosproject.vtnrsc.FlowClassifierId; |
29 | import org.onosproject.vtnrsc.VirtualPortId; | 29 | import org.onosproject.vtnrsc.VirtualPortId; |
30 | import org.onosproject.vtnrsc.FlowClassifier; | 30 | import org.onosproject.vtnrsc.FlowClassifier; |
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 FlowClassifierManager class. | 37 | * Unit tests for FlowClassifierManager class. |
... | @@ -61,6 +64,7 @@ public class FlowClassifierManagerTest { | ... | @@ -61,6 +64,7 @@ public class FlowClassifierManagerTest { |
61 | public void testCreateFlowClassifier() { | 64 | public void testCreateFlowClassifier() { |
62 | // initialize flow classifier manager | 65 | // initialize flow classifier manager |
63 | flowClassifierMgr.storageService = storageService; | 66 | flowClassifierMgr.storageService = storageService; |
67 | + injectEventDispatcher(flowClassifierMgr, new TestEventDispatcher()); | ||
64 | flowClassifierMgr.activate(); | 68 | flowClassifierMgr.activate(); |
65 | 69 | ||
66 | // create flow classifier | 70 | // create flow classifier | ... | ... |
-
Please register or login to post a comment