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%2FAbstractDataServiceTest.java;h=591e07d00440465f1bc6763d8ef4ef1508d9191c;hp=c67a0176d2de550ed6287607b14b546df64d71f7;hb=c46e223995956f1f759c551163c212947c1e2fb7;hpb=a35fe9ae149bd4c7089d48665ccc8bff580bce53 diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/AbstractDataServiceTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/AbstractDataServiceTest.java index c67a0176d2..591e07d004 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/AbstractDataServiceTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/AbstractDataServiceTest.java @@ -1,153 +1,44 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.binding.test; -import java.io.File; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javassist.ClassPool; - -import org.junit.After; import org.junit.Before; import org.opendaylight.controller.sal.binding.api.data.DataProviderService; -import org.opendaylight.controller.sal.binding.impl.DataBrokerImpl; -import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentDataServiceConnector; -import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentMappingService; -import org.opendaylight.controller.sal.binding.dom.serializer.impl.RuntimeGeneratedMappingServiceImpl; -import org.opendaylight.controller.sal.core.api.data.DataBrokerService; -import org.opendaylight.controller.sal.core.api.data.DataStore; -import org.opendaylight.controller.sal.dom.broker.impl.DataStoreStatsWrapper; -import org.opendaylight.controller.sal.dom.broker.impl.HashMapDataStore; -import org.opendaylight.controller.sal.dom.broker.impl.SchemaAwareDataStoreAdapter; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import org.reflections.Reflections; -import org.reflections.scanners.ResourcesScanner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory; +import org.opendaylight.controller.sal.binding.test.util.BindingTestContext; +import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMappingService; -import com.google.common.base.Predicate; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +@SuppressWarnings("deprecation") public abstract class AbstractDataServiceTest { - private static Logger log = LoggerFactory.getLogger(AbstractDataServiceTest.class); protected org.opendaylight.controller.sal.core.api.data.DataProviderService biDataService; protected DataProviderService baDataService; - - /** - * Workaround for JUNIT sharing classloaders - * - */ - protected static final ClassPool POOL = new ClassPool(); - - protected RuntimeGeneratedMappingServiceImpl mappingServiceImpl; protected BindingIndependentMappingService mappingService; - protected DataBrokerImpl baDataImpl; - protected org.opendaylight.controller.sal.dom.broker.DataBrokerImpl biDataImpl; - protected ListeningExecutorService executor; - protected BindingIndependentDataServiceConnector connectorServiceImpl; - protected HashMapDataStore rawDataStore; - protected SchemaAwareDataStoreAdapter schemaAwareDataStore; - private DataStoreStatsWrapper dataStoreStats; - - protected DataStore dataStore; + protected BindingTestContext testContext; @Before public void setUp() { - executor = MoreExecutors.sameThreadExecutor(); - baDataImpl = new DataBrokerImpl(); - baDataService = baDataImpl; - baDataImpl.setExecutor(executor); - - biDataImpl = new org.opendaylight.controller.sal.dom.broker.DataBrokerImpl(); - biDataService = biDataImpl; - biDataImpl.setExecutor(executor); - - rawDataStore = new HashMapDataStore(); - schemaAwareDataStore = new SchemaAwareDataStoreAdapter(); - schemaAwareDataStore.changeDelegate(rawDataStore); - dataStoreStats = new DataStoreStatsWrapper(schemaAwareDataStore); - dataStore = dataStoreStats; - - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier treeRoot = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier - .builder().toInstance(); - biDataImpl.registerConfigurationReader(treeRoot, dataStore); - biDataImpl.registerOperationalReader(treeRoot, dataStore); - biDataImpl.registerCommitHandler(treeRoot, dataStore); - - mappingServiceImpl = new RuntimeGeneratedMappingServiceImpl(); - mappingServiceImpl.setPool(POOL); - mappingService = mappingServiceImpl; - File pathname = new File("target/gen-classes-debug"); - // System.out.println("Generated classes are captured in " + - // pathname.getAbsolutePath()); - mappingServiceImpl.start(null); - // mappingServiceImpl.getBinding().setClassFileCapturePath(pathname); - - connectorServiceImpl = new BindingIndependentDataServiceConnector(); - connectorServiceImpl.setBaDataService(baDataService); - connectorServiceImpl.setBiDataService(biDataService); - connectorServiceImpl.setMappingService(mappingServiceImpl); - connectorServiceImpl.start(); - - String[] yangFiles = getModelFilenames(); - if (yangFiles != null && yangFiles.length > 0) { - SchemaContext context = getContext(yangFiles); - mappingServiceImpl.onGlobalContextUpdated(context); - schemaAwareDataStore.onGlobalContextUpdated(context); - } - } - - protected String[] getModelFilenames() { - return getAllModelFilenames(); + ListeningExecutorService executor = MoreExecutors.sameThreadExecutor(); + BindingBrokerTestFactory factory = new BindingBrokerTestFactory(); + factory.setExecutor(executor); + factory.setStartWithParsedSchema(getStartWithSchema()); + testContext = factory.getTestContext(); + testContext.start(); + + baDataService = testContext.getBindingDataBroker(); + biDataService = testContext.getDomDataBroker(); + mappingService = testContext.getBindingToDomMappingService(); } - public static String[] getAllModelFilenames() { - Predicate predicate = new Predicate() { - @Override - public boolean apply(String input) { - return input.endsWith(".yang"); - } - }; - Reflections reflection = new Reflections("META-INF.yang", new ResourcesScanner()); - Set result = reflection.getResources(predicate); - return (String[]) result.toArray(new String[result.size()]); - } - - public static SchemaContext getContext(String[] yangFiles) { - - ClassLoader loader = AbstractDataServiceTest.class.getClassLoader(); - - List streams = new ArrayList<>(); - for (String string : yangFiles) { - InputStream stream = loader.getResourceAsStream(string); - streams.add(stream); - - } - YangParserImpl parser = new YangParserImpl(); - - Set modules = parser.parseYangModelsFromStreams(streams); - return parser.resolveSchemaContext(modules); - } - - @After - public void afterTest() { - - log.info("BIDataStore Statistics: Configuration Read Count: {} TotalTime: {} ms AverageTime (ns): {} ms", - dataStoreStats.getConfigurationReadCount(), dataStoreStats.getConfigurationReadTotalTime(), - dataStoreStats.getConfigurationReadAverageTime()); - - log.info("BIDataStore Statistics: Operational Read Count: {} TotalTime: {} ms AverageTime (ns): {} ms", - dataStoreStats.getOperationalReadCount(), dataStoreStats.getOperationalReadTotalTime(), - dataStoreStats.getOperationalReadAverageTime()); - - log.info("BIDataStore Statistics: Request Commit Count: {} TotalTime: {} ms AverageTime (ns): {} ms", - dataStoreStats.getRequestCommitCount(), dataStoreStats.getRequestCommitTotalTime(), - dataStoreStats.getRequestCommitAverageTime()); - + protected boolean getStartWithSchema() { + return true; } }