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

Integrated Pipeline: TreeParser now rejects non-existent file tree roots gracefully

parent 1dbd28ef
......@@ -20,10 +20,17 @@ trait TreeParser extends MessageProcessor[FileTreeScanTask, FileParsingTaskSigna
final override def processSignal(in: FileTreeScanTask): Unit = {
if (readyForInbound) {
eventListener.processEvent(myId, TreeParserEventStart(in))
generator = Some(createProcessor(in))
request = Some(in)
taskCount = 0
readyForInbound = false
if (in.treeBasePath.toFile.exists()) {
generator = Some(createProcessor(in))
request = Some(in)
taskCount = 0
readyForInbound = false
} else {
eventListener.processEvent(myId, TreeParserEventTreeFailure(
in,
new IllegalArgumentException(s"file tree root '${in.treeBasePath}' does not exist, ignoring task")
))
}
} else {
throw new IllegalStateException("cannot process message, still digesting previous message")
}
......
......@@ -21,7 +21,7 @@ class UnderDevelopment extends LoggingTestAsyncWrapper with CustomMatchers {
val finished = Main.mainWithFuture(f.generateConsoleArgumentList(Some(info)))
finished.map { _ =>
atLeast(1, log.messages()) should (startWith("ERROR") and
includeAll("purely-imaginary", "not exist", "skipping file tree"))
includeAll("purely-imaginary", "not exist", "encountered failure", "ignoring task"))
}
}
}
......
......@@ -18,7 +18,8 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
private def argsCaptor(): ArgumentCaptor[TreeParserEvent] = ArgumentCaptor.forClass(classOf[TreeParserEvent])
private val sampleTreeTask = aFileTreeScanTask().withBasePath("/foo").build()
private val sampleTreeTask = aFileTreeScanTask().withBasePath(".").build()
private val invalidTreeTask = aFileTreeScanTask().withBasePath("/imaginary/foo/magic").build()
class Fixture(sampleData: Iterator[Either[TreeParserEventScanError, FileParsingTask]]) {
val events = mock[EventListener]
......@@ -102,7 +103,26 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
f.treeParser.processSignal(sampleTreeTask)
val captor = argsCaptor()
verify(f.events).processEvent(any(), captor.capture())
captor.getValue should (be(a[TreeParserEventStart]) and have(basePath("/foo")))
captor.getValue should (be(a[TreeParserEventStart]) and have(basePath(".")))
}
"ignore file tree scan tasks if the tree root does not exist on file-system" in {
val f = createFixture()
f.treeParser.processSignal(invalidTreeTask)
f.treeParser.hasSignalToEmit() should be(false)
}
"send an error event to the eventListener if the tree root does not exist on file-system" in {
import MatcherTreeParserEventTreeFailure._
val f = createFixture()
f.treeParser.processSignal(invalidTreeTask)
val captor = argsCaptor()
verify(f.events, atLeastOnce).processEvent(any(), captor.capture())
val events = captor.getAllValues.asScala.collect { case x: TreeParserEventTreeFailure => x }
exactly(1, events) should have(
basePath("/imaginary/foo/magic"),
errorMessage("tree root", "not exist")
)
}
}
......@@ -174,7 +194,7 @@ class TreeParserSpec extends WordSpec with TestDataBuilders with MockitoSugar
verify(f.events, Mockito.atLeast(1)).processEvent(any(), captor.capture())
val event = captor.getValue
event should be(a[TreeParserEventEnd])
event.asInstanceOf[TreeParserEventEnd] should have(basePath("/foo"), numCandidates(3))
event.asInstanceOf[TreeParserEventEnd] should have(basePath("."), numCandidates(3))
}
}
......
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