You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by mb...@apache.org on 2018/02/15 19:36:13 UTC

[incubator-daffodil] branch master updated: Schema cache now works whether you check all top-levels or not.

This is an automated email from the ASF dual-hosted git repository.

mbeckerle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git


The following commit(s) were added to refs/heads/master by this push:
     new 836d657  Schema cache now works whether you check all top-levels or not.
836d657 is described below

commit 836d657ca5bd99577110e8c30007591a26ee4317
Author: Michael Beckerle <mb...@tresys.com>
AuthorDate: Wed Feb 14 15:38:51 2018 -0500

    Schema cache now works whether you check all top-levels or not.
    
    DAFFODIL-1893
---
 .../scala/org/apache/daffodil/tdml/SchemaCache.scala   | 18 ++++++++++++++----
 .../scala/org/apache/daffodil/tdml/TDMLRunner.scala    | 12 +++++++-----
 .../org/apache/daffodil/tdml/TestSchemaCache.scala     |  2 +-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/SchemaCache.scala b/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/SchemaCache.scala
index 6238192..1640bb9 100644
--- a/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/SchemaCache.scala
+++ b/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/SchemaCache.scala
@@ -43,9 +43,9 @@ object SchemaDataProcessorCache extends SchemaCache[(Seq[Diagnostic], DFDL.DataP
 class SchemaCache[CachedType, DiagnosticType] {
 
   private class Cache
-    extends mutable.HashMap[(URISchemaSource, Boolean), (URISchemaSource, CachedType)] {
+    extends mutable.HashMap[(URISchemaSource, Boolean, Boolean, String, String), (URISchemaSource, CachedType)] {
 
-    override def getOrElseUpdate(key: (URISchemaSource, Boolean), body: => (URISchemaSource, CachedType)) = synchronized {
+    override def getOrElseUpdate(key: (URISchemaSource, Boolean, Boolean, String, String), body: => (URISchemaSource, CachedType)) = synchronized {
       super.getOrElseUpdate(key, body)
     }
 
@@ -78,10 +78,20 @@ class SchemaCache[CachedType, DiagnosticType] {
    * If the same URI is used, and it identifies a file, then if the modification time
    * is such that the file is newer then when last compiled, the newer file will
    * be compiled and cached.
+   * 
+   * If compileAllTopLevels is true, then all elements are compiled. If false, and
+   * no rootElementName is null, then the first element of the first schema file 
+   * is used as the single root element. Otherwise the rootElementName must be 
+   * provided. If ambiguous, the rootElementNamespace must also be supplied but this 
+   * can be null if the name alone is unambiguous.
+   *  
    */
-  def compileAndCache(uss: URISchemaSource, useSerializedProcessor: Boolean)(doCompileByName: => CompileResult): CompileResult = {
+  def compileAndCache(uss: URISchemaSource, useSerializedProcessor: Boolean,
+      compileAllTopLevels: Boolean,
+      rootElementName: String,
+      rootElementNamespace: String)(doCompileByName: => CompileResult): CompileResult = {
     lazy val doCompile = doCompileByName // exactly once
-    val key = (uss, useSerializedProcessor)
+    val key = (uss, useSerializedProcessor, compileAllTopLevels, rootElementName, rootElementNamespace)
     synchronized {
       // if the file is newer then when last compiled, drop from the cache.
       val optExistingEntry = compiledSchemaCache.get(key)
diff --git a/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala b/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
index 4f85f7f..0a90c66 100644
--- a/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
+++ b/daffodil-tdml/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
@@ -63,7 +63,6 @@ import java.io.ByteArrayInputStream
 import scala.language.postfixOps
 import java.nio.file.Paths
 import java.nio.file.Files
-import org.apache.daffodil.equality._
 import org.apache.commons.io.IOUtils
 import org.apache.daffodil.processors.HasSetDebugger
 import org.apache.daffodil.processors.UnparseResult
@@ -424,10 +423,13 @@ abstract class TestCase(testCaseXML: NodeSeq, val parent: DFDLTestSuite)
 
   final protected def getProcessor(schemaSource: DaffodilSchemaSource, useSerializedProcessor: Boolean): DFDLTestSuite.CompileResult = {
     val res: DFDLTestSuite.CompileResult = schemaSource match {
-      case uss: URISchemaSource if parent.checkAllTopLevel =#= true =>
-        SchemaDataProcessorCache.compileAndCache(uss, useSerializedProcessor) {
-          compileProcessor(uss, useSerializedProcessor)
-        }
+      case uss: URISchemaSource =>
+        SchemaDataProcessorCache.compileAndCache(uss, useSerializedProcessor,
+          parent.checkAllTopLevel,
+          root,
+          null) {
+            compileProcessor(uss, useSerializedProcessor)
+          }
       case _ => {
         compileProcessor(schemaSource, useSerializedProcessor)
       }
diff --git a/daffodil-tdml/src/test/scala/org/apache/daffodil/tdml/TestSchemaCache.scala b/daffodil-tdml/src/test/scala/org/apache/daffodil/tdml/TestSchemaCache.scala
index 938d1c2..25de0fa 100644
--- a/daffodil-tdml/src/test/scala/org/apache/daffodil/tdml/TestSchemaCache.scala
+++ b/daffodil-tdml/src/test/scala/org/apache/daffodil/tdml/TestSchemaCache.scala
@@ -65,7 +65,7 @@ class TestSchemaCache {
   }
 
   def compileTheSchema(uss: URISchemaSource) {
-    SCache.compileAndCache(uss, false) {
+    SCache.compileAndCache(uss, false, false, null, null) {
       compileCount += 1
       uss.newInputSource().getByteStream().close()
       Right(null)

-- 
To stop receiving notification emails like this one, please contact
mbeckerle@apache.org.