tuxji commented on a change in pull request #738:
URL: https://github.com/apache/daffodil/pull/738#discussion_r796283065
##########
File path: daffodil-core/src/test/scala/org/apache/daffodil/util/TestUtils.scala
##########
@@ -371,3 +376,96 @@ class Fakes private () {
lazy val fakeDP = new FakeDataProcessor
}
+
+/**
+ * Testing class for streaming message parse behavior
+ */
+object StreamParser {
+ case class CompileFailure (diags: Seq[Diagnostic]) extends Exception("DFDL
Schema Compile Failure"){
+ override def getMessage() = diags.map{ _.toString }.mkString(",\n")
+ }
+
+ /**
+ * Result object for parse calls. Just a tuple.
+ */
+ case class Result (message: Node, // document that is the current parse
result, or null
+ diags: Seq[Diagnostic], // diagnostics.
+ isProcessingError: Boolean,
+ isValidationError: Boolean,
+ bitPos1b: Long) {
+
+ def toXML: Node = {
+ <Result>
+ { message }
+ { if (!diags.isEmpty) {
+ <diagnostics>
+ { diags map { diag => <diagnostic>{ diag.toString} </diagnostic> } }
+ </diagnostics>
+ }
+ else Null
+ }
+ </Result> %
+ (if (isProcessingError) new
UnprefixedAttribute("isProcessingError",isProcessingError.toString, Null) else
Null) %
+ (if (isValidationError) new UnprefixedAttribute("isValidationError",
isValidationError.toString, Null) else Null) %
+ new UnprefixedAttribute("bitPos1b", bitPos1b.toString, Null)
+ }
+ }
+
+
+ def doStreamTest(schema: Node, data: String): Seq[Result] = {
+ var mp = new StreamParser(schema)
+ val is: InputStream = new ByteArrayInputStream(data.getBytes("ascii"))
+ mp.setInputStream(is)
+ var r: StreamParser.Result = null
+ var results = new ArrayBuffer[Result]
+ do {
+ r = mp.parse
+ results += r
+ } while (!r.isProcessingError)
+ results.toSeq
+ }
+}
+
+class StreamParser(val schema: Node) {
+
+ val outputter = new ScalaXMLInfosetOutputter()
+ var dis: InputSourceDataInputStream = _
+ var dp: DFDL.DataProcessor = _
+ //
+ // First compile the DFDL Schema
+ val c = Compiler()
+ val pf = c.compileNode(schema)
+ val pfDiags = pf.getDiagnostics
+ if (pf.isError) throw new StreamParser.CompileFailure(pfDiags)
+ dp = pf.onPath("/")
+ .withValidationMode(ValidationMode.Full)
+ // .withDebuggerRunner(new TraceDebuggerRunner()) // DAFFODIL-2624 - cannot
trace in streaming SAPI
+ // .withDebugging(true)
+ val dpDiags = dp.getDiagnostics
+ if (dp.isError) throw new StreamParser.CompileFailure(dpDiags)
+ var compilationWarnings = if (!pfDiags.isEmpty) pfDiags else dpDiags //
dpDiags might be empty. That's ok.
+
+ def setInputStream(inputStream: InputStream): Unit = {
+ dis = InputSourceDataInputStream(inputStream)
+ }
+
+ // def hasMoreData = dis.hasData
Review comment:
If we don't need this method, I'd rather delete it instead of commenting
it out.
##########
File path: daffodil-core/src/test/scala/org/apache/daffodil/util/TestUtils.scala
##########
@@ -371,3 +376,96 @@ class Fakes private () {
lazy val fakeDP = new FakeDataProcessor
}
+
+/**
+ * Testing class for streaming message parse behavior
+ */
+object StreamParser {
+ case class CompileFailure (diags: Seq[Diagnostic]) extends Exception("DFDL
Schema Compile Failure"){
+ override def getMessage() = diags.map{ _.toString }.mkString(",\n")
+ }
+
+ /**
+ * Result object for parse calls. Just a tuple.
+ */
+ case class Result (message: Node, // document that is the current parse
result, or null
+ diags: Seq[Diagnostic], // diagnostics.
+ isProcessingError: Boolean,
+ isValidationError: Boolean,
+ bitPos1b: Long) {
+
+ def toXML: Node = {
+ <Result>
+ { message }
+ { if (!diags.isEmpty) {
+ <diagnostics>
+ { diags map { diag => <diagnostic>{ diag.toString} </diagnostic> } }
+ </diagnostics>
+ }
+ else Null
+ }
+ </Result> %
+ (if (isProcessingError) new
UnprefixedAttribute("isProcessingError",isProcessingError.toString, Null) else
Null) %
+ (if (isValidationError) new UnprefixedAttribute("isValidationError",
isValidationError.toString, Null) else Null) %
+ new UnprefixedAttribute("bitPos1b", bitPos1b.toString, Null)
+ }
+ }
+
+
+ def doStreamTest(schema: Node, data: String): Seq[Result] = {
+ var mp = new StreamParser(schema)
+ val is: InputStream = new ByteArrayInputStream(data.getBytes("ascii"))
+ mp.setInputStream(is)
+ var r: StreamParser.Result = null
+ var results = new ArrayBuffer[Result]
+ do {
+ r = mp.parse
+ results += r
+ } while (!r.isProcessingError)
+ results.toSeq
+ }
+}
+
+class StreamParser(val schema: Node) {
+
+ val outputter = new ScalaXMLInfosetOutputter()
+ var dis: InputSourceDataInputStream = _
+ var dp: DFDL.DataProcessor = _
+ //
+ // First compile the DFDL Schema
+ val c = Compiler()
+ val pf = c.compileNode(schema)
+ val pfDiags = pf.getDiagnostics
+ if (pf.isError) throw new StreamParser.CompileFailure(pfDiags)
+ dp = pf.onPath("/")
+ .withValidationMode(ValidationMode.Full)
+ // .withDebuggerRunner(new TraceDebuggerRunner()) // DAFFODIL-2624 - cannot
trace in streaming SAPI
+ // .withDebugging(true)
+ val dpDiags = dp.getDiagnostics
+ if (dp.isError) throw new StreamParser.CompileFailure(dpDiags)
+ var compilationWarnings = if (!pfDiags.isEmpty) pfDiags else dpDiags //
dpDiags might be empty. That's ok.
Review comment:
What's the reason for having compilationWarnings be a var instead of a
val? For that matter, what's the reason for splitting up the initialization
via both the constructor and setInputStream when the only caller of this class
is right above here in doStreamTest at line 416? If you pass inputStream to
the constructor, you can make dis and dp val's instead of var's too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]