X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Ftest%2FAbstractDataServiceTest.java;h=9f3a6e8652f8c3d47dc65c2aafce56061d26aace;hb=b2d4575c4425e3b3d5aeaf1190e01e5d5a5286aa;hp=7d8a8f1fffa7703c2d1b567cbc372f694e4cdba0;hpb=d6caaf86d29a8188ec2dce678315ef4417924e09;p=controller.git 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 7d8a8f1fff..9f3a6e8652 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 @@ -8,6 +8,7 @@ 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; @@ -15,78 +16,96 @@ import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndepende 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 com.google.common.base.Predicate; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; -public abstract class AbstractDataServiceTest { - protected DataBrokerService biDataService; +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 dataStore; - - + protected HashMapDataStore rawDataStore; + private SchemaAwareDataStoreAdapter schemaAwareDataStore; + private DataStoreStatsWrapper dataStoreStats; + + protected DataStore dataStore; + @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; + biDataService = biDataImpl; biDataImpl.setExecutor(executor); - - dataStore = new HashMapDataStore(); - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier treeRoot = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.builder().toInstance(); + + 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(); - //mappingServiceImpl.getBinding().setClassFileCapturePath(pathname); - + // 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) { - mappingServiceImpl.onGlobalContextUpdated(getContext(yangFiles)); + + String[] yangFiles = getModelFilenames(); + if (yangFiles != null && yangFiles.length > 0) { + SchemaContext context = getContext(yangFiles); + mappingServiceImpl.onGlobalContextUpdated(context); + schemaAwareDataStore.onGlobalContextUpdated(context); } } - - protected String[] getModelFilenames() { + protected String[] getModelFilenames() { return getAllModelFilenames(); } - + public static String[] getAllModelFilenames() { Predicate predicate = new Predicate() { @Override @@ -94,11 +113,11 @@ public abstract class AbstractDataServiceTest { return input.endsWith(".yang"); } }; - Reflections reflection= new Reflections("META-INF.yang", new ResourcesScanner()); + 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(); @@ -114,4 +133,21 @@ public abstract class AbstractDataServiceTest { Set modules = parser.parseYangModelsFromStreams(streams); return parser.resolveSchemaContext(modules); } + + @After + public void afterTest() { + + log.info("BIDataStore Statistics: Configuration Read Count: {} TotalTime: {} ns AverageTime (ns): {} ns", + dataStoreStats.getConfigurationReadCount(), dataStoreStats.getConfigurationReadTotalTime(), + dataStoreStats.getConfigurationReadAverageTime()); + + log.info("BIDataStore Statistics: Operational Read Count: {} TotalTime: {} ns AverageTime (ns): {} ns", + dataStoreStats.getOperationalReadCount(), dataStoreStats.getOperationalReadTotalTime(), + dataStoreStats.getOperationalReadAverageTime()); + + log.info("BIDataStore Statistics: Request Commit Count: {} TotalTime: {} ns AverageTime (ns): {} ns", + dataStoreStats.getRequestCommitCount(), dataStoreStats.getRequestCommitTotalTime(), + dataStoreStats.getRequestCommitAverageTime()); + + } }