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

Integrated Pipeline: refactored tests for ParsingResultsProcessingManager

parent 51286ce9
......@@ -15,7 +15,7 @@ import scala.collection.JavaConverters._
class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar with TestDataBuilders
with Matchers with MessageProcessorBehaviour[FileParsingResultSignal, FileTreeParsingResult] {
private class Fixture {
class Fixture {
val processingMock = mock[ParsingResultsProcessor]
when(processingMock.outputType).thenReturn(OutputType.Json)
......@@ -25,75 +25,39 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
}
}
def noResultsNoEndReceived(processing: ParsingResultsProcessor)(): ParsingResultsProcessingManager = {
new ParsingResultsProcessingManager {
override val processor: ParsingResultsProcessor = processing
}
def noResultsNoEndReceived(): Fixture = {
new Fixture
}
def twoResultsNoEndReceived(processing: ParsingResultsProcessor)(): ParsingResultsProcessingManager = {
val manager = new ParsingResultsProcessingManager {
override val processor: ParsingResultsProcessor = processing
}
manager.processSignal(anInMemoryResult())
manager.processSignal(anInMemoryResult())
manager
def twoResultsNoEndReceived(): Fixture = {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(anInMemoryResult())
f
}
def oneResultEndWithTwoEntriesReceived(processing: ParsingResultsProcessor)(): ParsingResultsProcessingManager = {
val manager = new ParsingResultsProcessingManager {
override val processor: ParsingResultsProcessor = processing
}
manager.processSignal(anInMemoryResult())
manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
manager
def oneResultEndWithTwoEntriesReceived(): Fixture = {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
f
}
def twoResultsEndWithTwoEntriesReceived(processing: ParsingResultsProcessor)(): ParsingResultsProcessingManager = {
val manager = new ParsingResultsProcessingManager {
override val processor: ParsingResultsProcessor = processing
}
manager.processSignal(anInMemoryResult())
manager.processSignal(anInMemoryResult())
manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
manager
def twoResultsEndWithTwoEntriesReceived(): Fixture = {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
f
}
"a ParsingResultsProcessorFlow" when {
"not having received any events" should {
behave like processorWithNoSignalReady(
noResultsNoEndReceived(mock[ParsingResultsProcessor]),
() => noResultsNoEndReceived().manager,
Seq(anInMemoryResult(), aFileParsingSignalEndTree())
)
}
"having received all parsing tasks but no end signal" should {
behave like processorWithNoSignalReady(
twoResultsNoEndReceived(mock[ParsingResultsProcessor]),
Seq(anInMemoryResult(), aFileParsingSignalEndTree())
)
}
"having received the end signal and all but one parsing results" should {
behave like processorWithNoSignalReady(
oneResultEndWithTwoEntriesReceived(mock[ParsingResultsProcessor]),
Seq(anInMemoryResult(), aFileParsingSignalEndTree())
)
}
"having received the end signal and all parsing results" should {
behave like processorWithOutboundSignalReady(
twoResultsEndWithTwoEntriesReceived(mock[ParsingResultsProcessor]),
Seq(anInMemoryResult(), aFileParsingSignalEndTree()),
have(
FileTreeParsingResultMatchers.numParsingTasks(2),
FileTreeParsingResultMatchers.treeTask(aFileTreeScanTask())
)
)
}
"handling a single tree-parsing request" should {
"start processing a file tree when the first signal associated with it arrives (result arrives first)" in {
val f = new Fixture
......@@ -121,45 +85,64 @@ class ParsingResultsProcessingManagerSpec extends WordSpec with MockitoSugar wit
results should contain allOf (Paths.get("foo"), Paths.get("magic"))
}
"finish processing a file tree when all signals associated with it arrived (result arrives last)" in {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
}
"having received all parsing tasks but no end signal" should {
behave like processorWithNoSignalReady(
() => twoResultsNoEndReceived().manager,
Seq(anInMemoryResult(), aFileParsingSignalEndTree())
)
"finish processing a file tree when the associated end signal arrives" in {
val f = twoResultsNoEndReceived()
f.manager.hasSignalToEmit() should be(false)
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
assert(!f.manager.hasSignalToEmit(), "no signal should be ready yet")
f.manager.processSignal(anInMemoryResult())
verify(f.processingMock).finishProcessingTreeResults(any())
assert(f.manager.hasSignalToEmit(), "a signal should be ready now")
f.manager.hasSignalToEmit() should be(true)
}
"finish processing a file tree when all signals associated with it arrived (end signal arrives last)" in {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
}
"having received the end signal and all but one parsing results" should {
behave like processorWithNoSignalReady(
() => oneResultEndWithTwoEntriesReceived().manager,
Seq(anInMemoryResult(), aFileParsingSignalEndTree())
)
"finish processing a file tree when the last associated parsing result arrived" in {
val f = oneResultEndWithTwoEntriesReceived()
f.manager.hasSignalToEmit() should be(false)
f.manager.processSignal(anInMemoryResult())
assert(!f.manager.hasSignalToEmit(), "no signal should be ready yet")
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
verify(f.processingMock).finishProcessingTreeResults(any())
assert(f.manager.hasSignalToEmit(), "a signal should be ready now")
f.manager.hasSignalToEmit() should be(true)
}
"call the file tree pre- and postprocessing operations in the correct order" in {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(1))
}
"having received the end signal and all parsing results" should {
behave like processorWithOutboundSignalReady(
() => twoResultsEndWithTwoEntriesReceived().manager,
Seq(anInMemoryResult(), aFileParsingSignalEndTree()),
have(
FileTreeParsingResultMatchers.numParsingTasks(2),
FileTreeParsingResultMatchers.treeTask(aFileTreeScanTask())
)
)
"have called the file tree pre- and postprocessing operations in the correct order" in {
val f = twoResultsEndWithTwoEntriesReceived()
f.orderingTest.verify(f.processingMock).startProcessingTreeResults(aFileTreeScanTask())
f.orderingTest.verify(f.processingMock).finishProcessingTreeResults(aFileTreeScanTask())
}
"be able to process the same file tree again after finishing it once" in {
val f = new Fixture
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(1))
verify(f.processingMock).finishProcessingTreeResults(aFileTreeScanTask())
val f = twoResultsEndWithTwoEntriesReceived()
f.manager.getNextSignalToEmit()
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(1))
f.manager.processSignal(anInMemoryResult())
f.manager.processSignal(aFileParsingSignalEndTree().withTaskCount(2))
verify(f.processingMock, times(2)).finishProcessingTreeResults(aFileTreeScanTask())
}
}
"handling multiple, possibly interleaved, tree results at the same time" 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