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=4ba3d7a081ba5e7646a94d28b773ff2759b8a864;hp=a439e9ea262bfdfcf321367bc78c7a6eca1b0509;hb=3ec97cd0a86ad1b79f6854dc6924eb7b06e359a3;hpb=79501c28d5f3e179cb67390fb160a63fc44bac8f 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 a439e9ea26..4ba3d7a081 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 @@ -10,68 +10,57 @@ 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 javassist.ClassPool; +import java.util.Set; 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.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.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.BrokerService; import org.opendaylight.controller.sal.core.spi.data.DOMStore; -import org.opendaylight.controller.sal.dom.broker.BrokerImpl; -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.sal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils; +import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; +import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; +import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; import org.opendaylight.yangtools.yang.binding.YangModuleInfo; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @Beta +@Deprecated public class BindingTestContext implements AutoCloseable { - - private BindingToNormalizedNodeCodec codec; private RootBindingAwareBroker baBrokerImpl; - private NotificationBrokerImpl baNotifyImpl; + private HeliumNotificationProviderServiceAdapter baNotifyImpl; - private BrokerImpl biBrokerImpl; - private final ListeningExecutorService executor; - private final ClassPool classPool; private final boolean startWithSchema; @@ -79,9 +68,6 @@ public class BindingTestContext implements AutoCloseable { private ImmutableMap newDatastores; - @Deprecated - private DataProviderService baData; - private DOMDataBroker newDOMDataBroker; private final MockSchemaService mockSchemaService = new MockSchemaService(); @@ -92,20 +78,29 @@ public class BindingTestContext implements AutoCloseable { private BindingDOMRpcProviderServiceAdapter baProviderRpc; private DOMRpcRouter domRouter; + private org.opendaylight.mdsal.dom.broker.DOMRpcRouter delegateDomRouter; + private NotificationPublishService publishService; + private NotificationService listenService; + + private DOMNotificationPublishService domPublishService; + + private DOMNotificationService domListenService; + + private Set schemaModuleInfos; 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) { + + protected BindingTestContext(final ListeningExecutorService executor, final boolean startWithSchema) { this.executor = executor; - this.classPool = classPool; this.startWithSchema = startWithSchema; } @@ -113,24 +108,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 BindingDOMDataBrokerAdapter(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); + this.newDOMDataBroker = new SerializedDOMDataBroker(this.newDatastores, this.executor); - mockSchemaService.registerSchemaContextListener(configStore); - mockSchemaService.registerSchemaContextListener(operStore); + this.mockSchemaService.registerSchemaContextListener(configStore); + this.mockSchemaService.registerSchemaContextListener(operStore); } public void startBindingDataBroker() { @@ -138,71 +135,37 @@ 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(); - } - - public void startForwarding() { + checkState(this.executor != null, "Executor needs to be set"); + checkState(this.baNotifyImpl != null, "Notification Service must be started"); - } - - private ProviderSession createMockContext() { - - @SuppressWarnings("deprecation") - final ClassToInstanceMap domBrokerServices = ImmutableClassToInstanceMap - . builder() - // - .put(DOMRpcRouter.class, biBrokerImpl.getRouter()) // - .put(DOMMountPointService.class, biMountImpl) - .build(); + this.baConsumerRpc = new BindingDOMRpcServiceAdapter(getDomRpcInvoker(), this.codec); + this.baProviderRpc = new BindingDOMRpcProviderServiceAdapter(getDomRpcRegistry(), this.codec); - return new ProviderSession() { + this.baBrokerImpl = new RootBindingAwareBroker("test"); - @Override - public T getService(final Class service) { - return domBrokerServices.getInstance(service); - } + final MountPointService mountService = new BindingDOMMountPointServiceAdapter(this.biMountImpl, this.codec); + this.baBrokerImpl.setMountService(mountService); + this.baBrokerImpl.setRpcBroker(new HeliumRpcProviderRegistry(this.baConsumerRpc, this.baProviderRpc)); + this.baBrokerImpl.setNotificationBroker(this.baNotifyImpl); + this.baBrokerImpl.start(); + } - @Override - public boolean isClosed() { - return false; - } + public void startForwarding() { - @Override - public void close() { - } - }; } public void startBindingToDomMappingService() { - checkState(classPool != null, "ClassPool needs to be present"); - - final DataObjectSerializerGenerator generator = StreamWriterGenerator.create(JavassistUtils.forClassPool(classPool)); - final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(generator); + final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(); final GeneratedClassLoadingStrategy loading = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(); - codec = new BindingToNormalizedNodeCodec(loading, 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)); + private void updateYangSchema(final Set moduleInfos) { + this.mockSchemaService.changeSchema(getContext(moduleInfos)); } - private SchemaContext getContext(final ImmutableSet moduleInfos) { + private static SchemaContext getContext(final Set moduleInfos) { final ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create(); ctx.addModuleInfos(moduleInfos); return ctx.tryToCreateSchemaContext().get(); @@ -215,82 +178,78 @@ public class BindingTestContext implements AutoCloseable { startDomMountPoint(); startBindingToDomMappingService(); startNewDataBroker(); - startNewBindingDataBroker(); startBindingNotificationBroker(); startBindingBroker(); startForwarding(); - if (startWithSchema) { + + if (schemaModuleInfos != null) { + updateYangSchema(schemaModuleInfos); + } else if (this.startWithSchema) { loadYangSchemaFromClasspath(); } } - public void startNewBindingDataBroker() { - final HydrogenDataBrokerAdapter forwarded = new HydrogenDataBrokerAdapter(dataBroker); - baData = forwarded; - } - private void startDomMountPoint() { - biMountImpl = new DOMMountPointServiceImpl(); + this.biMountImpl = new DOMMountPointServiceImpl(); } private void startDomBroker() { - checkState(executor != null); - - domRouter = new DOMRpcRouter(); - mockSchemaService.registerSchemaContextListener(domRouter); - - final ClassToInstanceMap services = MutableClassToInstanceMap.create(); - services.put(DOMRpcService.class, domRouter); - - biBrokerImpl = new BrokerImpl(domRouter,services); + checkState(this.executor != null); + delegateDomRouter = org.opendaylight.mdsal.dom.broker.DOMRpcRouter.newInstance(mockSchemaService); + this.domRouter = new DOMRpcRouter(delegateDomRouter.getRpcService(), delegateDomRouter.getRpcProviderService()); } 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); } public void loadYangSchemaFromClasspath() { - final ImmutableSet moduleInfos = BindingReflections.loadModuleInfos(); - updateYangSchema(moduleInfos); - } - - @Deprecated - public DataProviderService getBindingDataBroker() { - return baData; + updateYangSchema(BindingReflections.loadModuleInfos()); } 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; + } + + public org.opendaylight.mdsal.dom.broker.DOMRpcRouter getDelegateDomRouter() { + return delegateDomRouter; } @Override - public void close() throws Exception { + public void close() { } - public MountProviderService getBindingMountProviderService() { - return baBrokerImpl.getLegacyMount(); + public MountPointService getBindingMountPointService() { + return this.baBrokerImpl.getMountService(); } public DOMMountPointService getDomMountProviderService() { - return biMountImpl; + return this.biMountImpl; } public DataBroker getDataBroker() { - return dataBroker; + return this.dataBroker; } - + public void setSchemaModuleInfos(Set moduleInfos) { + this.schemaModuleInfos = moduleInfos; + } }