Merge "Table features : modified yang model. Patch set 2: Modified match types as...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / sal / binding / test / AbstractDataServiceTest.java
index 7d8a8f1fffa7703c2d1b567cbc372f694e4cdba0..9f3a6e8652f8c3d47dc65c2aafce56061d26aace 100644 (file)
@@ -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<String> predicate = new Predicate<String>() {
             @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<String> 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<Module> 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());
+
+    }
 }