Commit 1aad8237 authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: defined ResultWriterEvents and property matchers

parent 99f64d99
package eu.nomad_lab.integrated_pipeline
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserEvent, ResultWriterProcessEvent, TreeParserEvent }
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserEvent, ResultWriterEvent, TreeParserEvent }
import scala.collection.parallel.mutable
......@@ -44,6 +44,6 @@ trait EventListener {
def processEvent(reporter: CalculationParserId, message: CalculationParserEvent): Unit = {}
def processEvent(reporter: ResultWriterId, message: ResultWriterProcessEvent): Unit = {}
def processEvent(reporter: ResultWriterId, message: ResultWriterEvent): Unit = {}
}
......@@ -42,6 +42,6 @@ trait EventLogger extends EventListener with StrictLogging {
super.processEvent(reporter, message)
}
override def processEvent(reporter: ResultWriterId, message: ResultWriterProcessEvent): Unit = ???
override def processEvent(reporter: ResultWriterId, message: ResultWriterEvent): Unit = ???
}
......@@ -48,5 +48,25 @@ case class CalculationParserEventEnd(
error: Option[String]
) extends CalculationParserEvent
sealed trait ResultWriterProcessEvent
sealed trait ResultWriterEvent {
def treeTask: FileTreeScanTask
}
case class ResultWriterEventStart(
treeTask: FileTreeScanTask
) extends ResultWriterEvent
case class ResultWriterEventResult(
treeTask: FileTreeScanTask,
relativePath: Path,
parser: String,
result: ParseResult,
error: Option[String]
) extends ResultWriterEvent
case class ResultWriterEventEnd(
treeTask: FileTreeScanTask,
numCalculations: Long,
numParsingFailures: Long,
outputLocation: Path
) extends ResultWriterEvent
\ No newline at end of file
package eu.nomad_lab.integrated_pipeline_tests
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserEvent, ResultWriterProcessEvent, TreeParserEvent }
import eu.nomad_lab.integrated_pipeline.messages.{ CalculationParserEvent, ResultWriterEvent, TreeParserEvent }
import eu.nomad_lab.integrated_pipeline._
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{ Matchers, WordSpec }
......@@ -14,7 +14,7 @@ trait EventListenerBehaviour extends Matchers with MockitoSugar with TestDataBui
aTreeParserEventEnd()
)
private val sampleCalculationParserEvents: Seq[CalculationParserEvent] = Seq()
private val sampleResultWriterEvents: Seq[ResultWriterProcessEvent] = Seq()
private val sampleResultWriterEvents: Seq[ResultWriterEvent] = Seq()
def eventListener(fixture: () => EventListener) {
......
......@@ -89,3 +89,73 @@ object CalculationParserEventMatchers {
)
}
object ResultWriterEventMatchers {
def basePath(expectedValue: Path): HavePropertyMatcher[ResultWriterEvent, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "tree base path",
expected = expectedValue,
test = (x: ResultWriterEvent) => x.treeTask.treeBasePath
)
def basePath(expectedValue: String): HavePropertyMatcher[ResultWriterEvent, Path] =
basePath(Paths.get(expectedValue))
def relativePath(expectedValue: Path): HavePropertyMatcher[ResultWriterEventResult, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: ResultWriterEventResult) => x.relativePath
)
def relativePath(expectedValue: String): HavePropertyMatcher[ResultWriterEventResult, Path] =
relativePath(Paths.get(expectedValue))
def parser(expectedValue: String): HavePropertyMatcher[ResultWriterEventResult, String] =
MatcherHelpers.propertyMatcher(
propertyName = "parser name",
expected = expectedValue,
test = (x: ResultWriterEventResult) => x.parser
)
def status(expectedValue: ParseResult): HavePropertyMatcher[ResultWriterEventResult, ParseResult] =
MatcherHelpers.propertyMatcher(
propertyName = "parsing result",
expected = expectedValue,
test = (x: ResultWriterEventResult) => x.result
)
def errorMessage(first: String, other: String*): HavePropertyMatcher[ResultWriterEventResult, String] =
MatcherHelpers.subStringPropertyMatcher(
propertyName = "error message content",
expected = first +: other,
test = (x: ResultWriterEventResult) => x.error.getOrElse(""),
display = (x: ResultWriterEventResult) => x.error.toString
)
def numCalculations(expectedValue: Long): HavePropertyMatcher[ResultWriterEventEnd, Long] =
MatcherHelpers.propertyMatcher(
propertyName = "number of processed calculations",
expected = expectedValue,
test = (x: ResultWriterEventEnd) => x.numCalculations
)
def numFailures(expectedValue: Long): HavePropertyMatcher[ResultWriterEventEnd, Long] =
MatcherHelpers.propertyMatcher(
propertyName = "number of failed calculations",
expected = expectedValue,
test = (x: ResultWriterEventEnd) => x.numParsingFailures
)
def outputPath(expectedValue: Path): HavePropertyMatcher[ResultWriterEventEnd, Path] =
MatcherHelpers.propertyMatcher(
propertyName = "relative file path",
expected = expectedValue,
test = (x: ResultWriterEventEnd) => x.outputLocation
)
def outputPath(expectedValue: String): HavePropertyMatcher[ResultWriterEventEnd, Path] =
outputPath(Paths.get(expectedValue))
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment