Bharat saraswal
Committed by Gerrit Code Review

[ONOS-3113] Flow Classifier Manager test case fixed

Change-Id: Ie4a35ec65f85ebf5ce5c20849d471fd3f947c405
......@@ -52,5 +52,12 @@
<artifactId>onos-core-serializers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-common</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......
......@@ -28,6 +28,8 @@ import org.onlab.util.KryoNamespace;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.EventuallyConsistentMap;
import org.onosproject.store.service.EventuallyConsistentMapEvent;
import org.onosproject.store.service.EventuallyConsistentMapListener;
import org.onosproject.store.service.MultiValuedTimestamp;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.WallClockTimestamp;
......@@ -51,16 +53,21 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie
private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null";
private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null";
private static final String LISTENER_NOT_NULL = "Listener cannot be null";
private static final String EVENT_NOT_NULL = "event cannot be null";
private final Logger log = getLogger(FlowClassifierManager.class);
private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore;
private EventuallyConsistentMapListener<FlowClassifierId, FlowClassifier> flowClassifierListener =
new InnerFlowClassifierStoreListener();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
@Activate
protected void activate() {
eventDispatcher.addSink(FlowClassifierEvent.class, listenerRegistry);
KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
.register(KryoNamespaces.API)
.register(MultiValuedTimestamp.class)
......@@ -69,11 +76,13 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie
.<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder()
.withName("flowclassifierstore").withSerializer(serializer)
.withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
flowClassifierStore.addListener(flowClassifierListener);
log.info("Flow Classifier service activated");
}
@Deactivate
protected void deactivate() {
eventDispatcher.removeSink(FlowClassifierEvent.class);
flowClassifierStore.destroy();
log.info("Flow Classifier service deactivated");
}
......@@ -144,4 +153,35 @@ public class FlowClassifierManager extends AbstractListenerManager<FlowClassifie
}
return true;
}
private class InnerFlowClassifierStoreListener
implements
EventuallyConsistentMapListener<FlowClassifierId, FlowClassifier> {
@Override
public void event(EventuallyConsistentMapEvent<FlowClassifierId, FlowClassifier> event) {
checkNotNull(event, EVENT_NOT_NULL);
FlowClassifier flowClassifier = event.value();
if (EventuallyConsistentMapEvent.Type.PUT == event.type()) {
notifyListeners(new FlowClassifierEvent(
FlowClassifierEvent.Type.FLOW_CLASSIFIER_PUT,
flowClassifier));
}
if (EventuallyConsistentMapEvent.Type.REMOVE == event.type()) {
notifyListeners(new FlowClassifierEvent(
FlowClassifierEvent.Type.FLOW_CLASSIFIER_DELETE,
flowClassifier));
}
}
}
/**
* Notifies specify event to all listeners.
*
* @param event flow classifier event
*/
private void notifyListeners(FlowClassifierEvent event) {
checkNotNull(event, EVENT_NOT_NULL);
post(event);
}
}
......
......@@ -29,6 +29,9 @@ import org.onosproject.vtnrsc.FlowClassifierId;
import org.onosproject.vtnrsc.VirtualPortId;
import org.onosproject.vtnrsc.FlowClassifier;
import org.onosproject.vtnrsc.util.VtnStorageServiceTest;
import org.onosproject.common.event.impl.TestEventDispatcher;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
/**
* Unit tests for FlowClassifierManager class.
......@@ -61,6 +64,7 @@ public class FlowClassifierManagerTest {
public void testCreateFlowClassifier() {
// initialize flow classifier manager
flowClassifierMgr.storageService = storageService;
injectEventDispatcher(flowClassifierMgr, new TestEventDispatcher());
flowClassifierMgr.activate();
// create flow classifier
......