X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Ftest%2Futil%2FBindingTestContext.java;h=5bd1316504a02f8d5b4aa25a2cc4c911d1d852a8;hp=58d6a3de889b8759140b9ee7334719f3ab4780ca;hb=db89afdefb3cfa4454dfdc6008e1d54d3ede66fb;hpb=3ea96ea6cf7fb77ff3c984294c81f0997c667b1f diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java index 58d6a3de88..5bd1316504 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java @@ -8,84 +8,70 @@ package org.opendaylight.controller.sal.binding.test.util; import static com.google.common.base.Preconditions.checkState; - import com.google.common.annotations.Beta; import com.google.common.collect.ClassToInstanceMap; -import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.MutableClassToInstanceMap; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; -import java.util.Set; -import java.util.concurrent.Future; -import javassist.ClassPool; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.NotificationService; +import org.opendaylight.controller.md.sal.binding.compat.HeliumNotificationProviderServiceAdapter; import org.opendaylight.controller.md.sal.binding.compat.HeliumRpcProviderRegistry; import org.opendaylight.controller.md.sal.binding.compat.HydrogenDataBrokerAdapter; import org.opendaylight.controller.md.sal.binding.compat.HydrogenMountProvisionServiceAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter; import org.opendaylight.controller.md.sal.binding.impl.BindingDOMMountPointServiceAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationPublishServiceAdapter; +import org.opendaylight.controller.md.sal.binding.impl.BindingDOMNotificationServiceAdapter; import org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcProviderServiceAdapter; import org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcServiceAdapter; import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; -import org.opendaylight.controller.md.sal.binding.impl.ForwardedBindingDataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; +import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService; import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; +import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter; import org.opendaylight.controller.md.sal.dom.broker.impl.DOMRpcRouter; import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker; -import org.opendaylight.controller.md.sal.dom.broker.impl.compat.BackwardsCompatibleDataBroker; import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.controller.sal.binding.api.data.DataProviderService; import org.opendaylight.controller.sal.binding.api.mount.MountProviderService; -import org.opendaylight.controller.sal.binding.impl.NotificationBrokerImpl; import org.opendaylight.controller.sal.binding.impl.RootBindingAwareBroker; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration; -import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration; import org.opendaylight.controller.sal.core.api.BrokerService; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; -import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; import org.opendaylight.controller.sal.core.spi.data.DOMStore; import org.opendaylight.controller.sal.dom.broker.BrokerImpl; -import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareRpcBroker; +import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; +import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; import org.opendaylight.yangtools.binding.data.codec.gen.impl.DataObjectSerializerGenerator; import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator; import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl; -import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; import org.opendaylight.yangtools.yang.binding.util.BindingReflections; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import javassist.ClassPool; @Beta public class BindingTestContext implements AutoCloseable { - private RuntimeGeneratedMappingServiceImpl mappingServiceImpl; private BindingToNormalizedNodeCodec codec; private RootBindingAwareBroker baBrokerImpl; - private NotificationBrokerImpl baNotifyImpl; + private HeliumNotificationProviderServiceAdapter baNotifyImpl; - @Deprecated - private org.opendaylight.controller.sal.core.api.data.DataProviderService biDataLegacyBroker; private BrokerImpl biBrokerImpl; private final ListeningExecutorService executor; @@ -97,9 +83,6 @@ public class BindingTestContext implements AutoCloseable { private ImmutableMap newDatastores; - @Deprecated - private BackwardsCompatibleDataBroker biCompatibleBroker; - @Deprecated private DataProviderService baData; @@ -114,14 +97,22 @@ public class BindingTestContext implements AutoCloseable { private BindingDOMRpcProviderServiceAdapter baProviderRpc; private DOMRpcRouter domRouter; + private NotificationPublishService publishService; + + private NotificationService listenService; + + private DOMNotificationPublishService domPublishService; + + private DOMNotificationService domListenService; + public DOMDataBroker getDomAsyncDataBroker() { - return newDOMDataBroker; + return this.newDOMDataBroker; } public BindingToNormalizedNodeCodec getCodec() { - return codec; + return this.codec; } protected BindingTestContext(final ListeningExecutorService executor, final ClassPool classPool, final boolean startWithSchema) { @@ -134,27 +125,26 @@ public class BindingTestContext implements AutoCloseable { } public void startNewDataBroker() { - checkState(executor != null, "Executor needs to be set"); - checkState(newDOMDataBroker != null, "DOM Data Broker must be set"); - dataBroker = new ForwardedBindingDataBroker(newDOMDataBroker, codec); + checkState(this.executor != null, "Executor needs to be set"); + checkState(this.newDOMDataBroker != null, "DOM Data Broker must be set"); + this.dataBroker = new BindingDOMDataBrokerAdapter(this.newDOMDataBroker, this.codec); } public void startNewDomDataBroker() { - checkState(executor != null, "Executor needs to be set"); - final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); - final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); - newDatastores = ImmutableMap.builder() + checkState(this.executor != null, "Executor needs to be set"); + final InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", + MoreExecutors.newDirectExecutorService()); + final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", + MoreExecutors.newDirectExecutorService()); + this.newDatastores = ImmutableMap.builder() .put(LogicalDatastoreType.OPERATIONAL, operStore) .put(LogicalDatastoreType.CONFIGURATION, configStore) .build(); - newDOMDataBroker = new SerializedDOMDataBroker(newDatastores, executor); - - biCompatibleBroker = new BackwardsCompatibleDataBroker(newDOMDataBroker,mockSchemaService); + this.newDOMDataBroker = new SerializedDOMDataBroker(this.newDatastores, this.executor); - mockSchemaService.registerSchemaContextListener(configStore); - mockSchemaService.registerSchemaContextListener(operStore); - biDataLegacyBroker = biCompatibleBroker; + this.mockSchemaService.registerSchemaContextListener(configStore); + this.mockSchemaService.registerSchemaContextListener(operStore); } public void startBindingDataBroker() { @@ -162,103 +152,40 @@ public class BindingTestContext implements AutoCloseable { } public void startBindingBroker() { - checkState(executor != null, "Executor needs to be set"); - checkState(baData != null, "Binding Data Broker must be started"); - checkState(baNotifyImpl != null, "Notification Service must be started"); - - baConsumerRpc = new BindingDOMRpcServiceAdapter(getDomRpcInvoker(), codec); - baProviderRpc = new BindingDOMRpcProviderServiceAdapter(getDomRpcRegistry(), codec); - - baBrokerImpl = new RootBindingAwareBroker("test"); - - final MountPointService mountService = new BindingDOMMountPointServiceAdapter(biMountImpl, codec); - baBrokerImpl.setMountService(mountService); - baBrokerImpl.setLegacyMountManager(new HydrogenMountProvisionServiceAdapter(mountService)); - baBrokerImpl.setRpcBroker(new HeliumRpcProviderRegistry(baConsumerRpc,baProviderRpc)); - baBrokerImpl.setLegacyDataBroker(baData); - baBrokerImpl.setNotificationBroker(baNotifyImpl); - baBrokerImpl.start(); + checkState(this.executor != null, "Executor needs to be set"); + checkState(this.baData != null, "Binding Data Broker must be started"); + checkState(this.baNotifyImpl != null, "Notification Service must be started"); + + this.baConsumerRpc = new BindingDOMRpcServiceAdapter(getDomRpcInvoker(), this.codec); + this.baProviderRpc = new BindingDOMRpcProviderServiceAdapter(getDomRpcRegistry(), this.codec); + + this.baBrokerImpl = new RootBindingAwareBroker("test"); + + final MountPointService mountService = new BindingDOMMountPointServiceAdapter(this.biMountImpl, this.codec); + this.baBrokerImpl.setMountService(mountService); + this.baBrokerImpl.setLegacyMountManager(new HydrogenMountProvisionServiceAdapter(mountService)); + this.baBrokerImpl.setRpcBroker(new HeliumRpcProviderRegistry(this.baConsumerRpc, this.baProviderRpc)); + this.baBrokerImpl.setLegacyDataBroker(this.baData); + this.baBrokerImpl.setNotificationBroker(this.baNotifyImpl); + this.baBrokerImpl.start(); } public void startForwarding() { } - private ProviderSession createMockContext() { - - @SuppressWarnings("deprecation") - final ClassToInstanceMap domBrokerServices = ImmutableClassToInstanceMap - . builder() - // - .put(org.opendaylight.controller.sal.core.api.data.DataProviderService.class, biDataLegacyBroker) // - .put(RpcProvisionRegistry.class, biBrokerImpl.getRouter()) // - .put(DOMMountPointService.class, biMountImpl) - .build(); - - return new ProviderSession() { - - @Override - public Future> rpc(final QName rpc, final CompositeNode input) { - throw new UnsupportedOperationException(); - } - - @Override - public T getService(final Class service) { - return domBrokerServices.getInstance(service); - } - - @Override - public boolean isClosed() { - return false; - } - - @Override - public Set getSupportedRpcs() { - return null; - } - - @Override - public void close() { - } - - @Override - public ListenerRegistration addRpcRegistrationListener( - final RpcRegistrationListener listener) { - return null; - } - - @Override - public RpcRegistration addRpcImplementation(final QName rpcType, final RpcImplementation implementation) - throws IllegalArgumentException { - return null; - } - - @Override - public RoutedRpcRegistration addRoutedRpcImplementation(final QName rpcType, final RpcImplementation implementation) { - return null; - } - - @Override - public RoutedRpcRegistration addMountedRpcImplementation(final QName rpcType, final RpcImplementation implementation) { - return null; - } - }; - } - public void startBindingToDomMappingService() { - checkState(classPool != null, "ClassPool needs to be present"); - mappingServiceImpl = new RuntimeGeneratedMappingServiceImpl(classPool); - mockSchemaService.registerSchemaContextListener(mappingServiceImpl); + checkState(this.classPool != null, "ClassPool needs to be present"); - final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(classPool)); + final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(this.classPool)); final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(generator); final GeneratedClassLoadingStrategy loading = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(); - codec = new BindingToNormalizedNodeCodec(loading, mappingServiceImpl, codecRegistry); - mockSchemaService.registerSchemaContextListener(codec); + this.codec = new BindingToNormalizedNodeCodec(loading, codecRegistry); + this.mockSchemaService.registerSchemaContextListener(this.codec); } private void updateYangSchema(final ImmutableSet moduleInfos) { - mockSchemaService.changeSchema(getContext(moduleInfos)); + this.mockSchemaService.changeSchema(getContext(moduleInfos)); } private SchemaContext getContext(final ImmutableSet moduleInfos) { @@ -279,38 +206,41 @@ public class BindingTestContext implements AutoCloseable { startBindingBroker(); startForwarding(); - if (startWithSchema) { + if (this.startWithSchema) { loadYangSchemaFromClasspath(); } } public void startNewBindingDataBroker() { - final HydrogenDataBrokerAdapter forwarded = new HydrogenDataBrokerAdapter(dataBroker); - baData = forwarded; + final HydrogenDataBrokerAdapter forwarded = new HydrogenDataBrokerAdapter(this.dataBroker); + this.baData = forwarded; } private void startDomMountPoint() { - biMountImpl = new DOMMountPointServiceImpl(); + this.biMountImpl = new DOMMountPointServiceImpl(); } private void startDomBroker() { - checkState(executor != null); - - final SchemaAwareRpcBroker router = new SchemaAwareRpcBroker("/", mockSchemaService); + checkState(this.executor != null); - domRouter = new DOMRpcRouter(); - mockSchemaService.registerSchemaContextListener(domRouter); + this.domRouter = new DOMRpcRouter(); + this.mockSchemaService.registerSchemaContextListener(this.domRouter); final ClassToInstanceMap services = MutableClassToInstanceMap.create(); - services.put(DOMRpcService.class, domRouter); + services.put(DOMRpcService.class, this.domRouter); - biBrokerImpl = new BrokerImpl(router,services); + this.biBrokerImpl = new BrokerImpl(this.domRouter,services); } public void startBindingNotificationBroker() { - checkState(executor != null); - baNotifyImpl = new NotificationBrokerImpl(executor); + checkState(this.executor != null); + final DOMNotificationRouter router = DOMNotificationRouter.create(16); + this.domPublishService = router; + this.domListenService = router; + this.publishService = new BindingDOMNotificationPublishServiceAdapter(this.codec, this.domPublishService); + this.listenService = new BindingDOMNotificationServiceAdapter(this.codec, this.domListenService); + this.baNotifyImpl = new HeliumNotificationProviderServiceAdapter(this.publishService,this.listenService); } @@ -321,28 +251,19 @@ public class BindingTestContext implements AutoCloseable { @Deprecated public DataProviderService getBindingDataBroker() { - return baData; - } - - @Deprecated - public org.opendaylight.controller.sal.core.api.data.DataProviderService getDomDataBroker() { - return biDataLegacyBroker; - } - - public BindingIndependentMappingService getBindingToDomMappingService() { - return mappingServiceImpl; + return this.baData; } public RpcProviderRegistry getBindingRpcRegistry() { - return baBrokerImpl.getRoot(); + return this.baBrokerImpl.getRoot(); } public DOMRpcProviderService getDomRpcRegistry() { - return domRouter; + return this.domRouter; } public DOMRpcService getDomRpcInvoker() { - return domRouter; + return this.domRouter; } @Override @@ -351,15 +272,15 @@ public class BindingTestContext implements AutoCloseable { } public MountProviderService getBindingMountProviderService() { - return baBrokerImpl.getLegacyMount(); + return this.baBrokerImpl.getLegacyMount(); } public DOMMountPointService getDomMountProviderService() { - return biMountImpl; + return this.biMountImpl; } public DataBroker getDataBroker() { - return dataBroker; + return this.dataBroker; }