Commit 4dcd72ed authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

Integrated Pipeline: added unit-tests for logging CalculationParserEvents

parent 767cfeac
package eu.nomad_lab.integrated_pipeline
import com.typesafe.scalalogging.StrictLogging
import eu.nomad_lab.integrated_pipeline.messages._
import eu.nomad_lab.parsers.ParseResult
import org.apache.logging.log4j.scala.Logging
import org.apache.logging.log4j.{ Marker, MarkerManager }
......@@ -18,7 +19,7 @@ object EventLogger {
* event logging class with multiple features.
*/
trait EventLogger extends EventListener with Logging {
import EventLogger.baseMarker
import EventLogger._
override def processEvent(reporter: TreeParserId, message: TreeParserEvent): Unit = {
message match {
......@@ -54,11 +55,24 @@ trait EventLogger extends EventListener with Logging {
s"[CalculationParser ${reporter.name}] start parsing file " +
s"'${x.relativePath}' in file tree '${x.treeTask.treeBasePath}' (parser '${x.parser}')"
)
case x: CalculationParserEventEnd => logger.info(
baseMarker,
s"[CalculationParser ${reporter.name}] finished parsing file '${x.relativePath}' in file " +
s"tree '${x.treeTask.treeBasePath}': ${x.result} (parser '${x.parser}')"
)
case x: CalculationParserEventEnd =>
x.result match {
case ParseResult.ParseSuccess => logger.info(
parseSuccessMarker,
s"[CalculationParser ${reporter.name}] finished parsing file '${x.relativePath}' in " +
s"file tree '${x.treeTask.treeBasePath}' (parser '${x.parser}')"
)
case ParseResult.ParseSkipped => logger.info(
parseSkippedMarker,
s"[CalculationParser ${reporter.name}] skipped parsing file '${x.relativePath}' in " +
s"file tree '${x.treeTask.treeBasePath}' (parser '${x.parser}')"
)
case ParseResult.ParseFailure => logger.warn(
parseFailureMarker,
s"[CalculationParser ${reporter.name}] failed parsing file '${x.relativePath}' in " +
s"file tree '${x.treeTask.treeBasePath}': ${x.error.get} (parser '${x.parser}')"
)
}
}
super.processEvent(reporter, message)
}
......
......@@ -3,6 +3,7 @@ package eu.nomad_lab.integrated_pipeline_tests
import eu.nomad_lab.TreeType
import eu.nomad_lab.integrated_pipeline._
import eu.nomad_lab.integrated_pipeline_tests.helpers.{ CustomMatchers, LoggingTestWrapper }
import eu.nomad_lab.parsers.ParseResult
import org.scalatest.mockito.MockitoSugar
class EventLoggerSpec extends LoggingTestWrapper with MockitoSugar with EventListenerBehaviour
......@@ -90,6 +91,48 @@ class EventLoggerSpec extends LoggingTestWrapper with MockitoSugar with EventLis
behave like eventListener(createFixture)
behave like eventListenerWithRegisteredCalculationParser(createFixture)
"log calculation parsing started events as info messages" in { log =>
val f = createFixture()
val message = aCalculationParserEventStart().withBasePath("/foo/bar").
withRelativePath("magic/file.out").withParser("magicTestParser")
f.logger.processEvent(f.calculationParserId.get, message)
exactly(1, log.messages()) should (startWith("INFO") and
includeAll("/foo/bar", "magic/file.out", "start parsing", "magicTestParser"))
}
"log successful calculation parsing end events as info messages" in { log =>
val f = createFixture()
val message = aCalculationParserEventEnd().withBasePath("/foo/bar").
withRelativePath("magic/file.out").withParser("magicTestParser").
withStatus(ParseResult.ParseSuccess)
f.logger.processEvent(f.calculationParserId.get, message)
exactly(1, log.messages()) should (startWith("INFO") and
includeAll("/foo/bar", "magic/file.out", "finished parsing", "magicTestParser",
"ParsingSuccess"))
}
"log failed calculation parsing end events as warning messages" in { log =>
val f = createFixture()
val message = aCalculationParserEventEnd().withBasePath("/foo/bar").
withRelativePath("magic/file.out").withParser("magicTestParser").
withStatus(ParseResult.ParseFailure).withErrorMessage(Some("test crash"))
f.logger.processEvent(f.calculationParserId.get, message)
exactly(1, log.messages()) should (startWith("WARN") and
includeAll("/foo/bar", "magic/file.out", "failed parsing", "magicTestParser",
"test crash", "ParsingFailure"))
}
"log skipped calculation parsing end events as info messages" in { log =>
val f = createFixture()
val message = aCalculationParserEventEnd().withBasePath("/foo/bar").
withRelativePath("magic/file.out").withParser("magicTestParser").
withStatus(ParseResult.ParseSkipped)
f.logger.processEvent(f.calculationParserId.get, message)
exactly(1, log.messages()) should (startWith("INFO") and
includeAll("/foo/bar", "magic/file.out", "skipped parsing", "magicTestParser",
"ParsingSkipped"))
}
}
"having received a registration from a ResultsWriter" should {
......
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