Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nomad-lab-base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
nomad-lab-base
Commits
b4fd9381
Commit
b4fd9381
authored
7 years ago
by
Ihrig, Arvid Conrad (ari)
Browse files
Options
Downloads
Patches
Plain Diff
Integrated Pipeline: CalculationParsingEngine test tweaks
parent
2239775a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
integrated-pipeline/src/test/scala/eu/nomad_lab/integrated_pipeline_tests/CalculationParsingEngineSpec.scala
+42
-42
42 additions, 42 deletions
...egrated_pipeline_tests/CalculationParsingEngineSpec.scala
with
42 additions
and
42 deletions
integrated-pipeline/src/test/scala/eu/nomad_lab/integrated_pipeline_tests/CalculationParsingEngineSpec.scala
+
42
−
42
View file @
b4fd9381
...
...
@@ -2,22 +2,20 @@ package eu.nomad_lab.integrated_pipeline_tests
import
java.nio.file.Paths
import
eu.nomad_lab.TreeType
import
eu.nomad_lab.integrated_pipeline.messages.
{
FileParsingTask
,
FileTreeScanTask
,
InMemoryResult
}
import
eu.nomad_lab.integrated_pipeline.messages.InMemoryResult
import
eu.nomad_lab.integrated_pipeline.stream_components.CalculationParsingEngine
import
eu.nomad_lab.meta.KnownMetaInfoEnvs
import
eu.nomad_lab.parsers.ParseResult.ParseResult
import
eu.nomad_lab.parsers._
import
org.json4s.JsonAST.
{
JInt
,
JObject
,
JString
}
import
org.mockito.ArgumentMatchers._
import
org.mockito.ArgumentMatchers.
{
eq
=>
raw
}
import
org.mockito.ArgumentMatchers.
{
eq
=>
raw
,
_
}
import
org.mockito.Mockito._
import
org.mockito.invocation.InvocationOnMock
import
org.mockito.stubbing.Answer
import
org.scalatest.WordSpec
import
org.scalatest.mockito.MockitoSugar
class
CalculationParsingEngineSpec
extends
WordSpec
with
MockitoSugar
{
class
CalculationParsingEngineSpec
extends
WordSpec
with
MockitoSugar
with
TestDataBuilders
with
MessageMatchers
{
val
parserInfo
:
JObject
=
JObject
(
"name"
->
JString
(
"dummyParser"
)
...
...
@@ -32,16 +30,8 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar {
)
implicit
val
metaInfo
=
KnownMetaInfoEnvs
.
all
val
sampleTreeTask
=
FileTreeScanTask
(
treeBasePath
=
Paths
.
get
(
"s/foo"
),
treeType
=
TreeType
.
Directory
)
val
sampleParseRequest
=
FileParsingTask
(
treeTask
=
sampleTreeTask
,
relativePath
=
Paths
.
get
(
"bar/gus.out"
),
parserName
=
"dummyParser"
)
val
unusedPath
=
Paths
.
get
(
"."
)
val
sampleParseRequest
=
aFileParsingTask
().
withParserName
(
"dummyParser"
)
class
Fixture
{
val
dummyParserCollection
=
mock
[
ParserCollection
]
...
...
@@ -54,54 +44,62 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar {
when
(
dummyParserGenerator
.
name
).
thenReturn
(
"dummyParser"
)
val
worker
=
new
CalculationParsingEngine
(
dummyParserCollection
)
val
unusedPath
=
Paths
.
get
(
"."
)
def
prepareParser
Mock
Invocation
()
:
Unit
=
{
def
prepareParser
Standard
Invocation
()
:
Unit
=
{
when
(
dummyParser
.
parseExternal
(
any
(),
any
(),
any
(),
any
())).
thenAnswer
(
new
Answer
[
ParseResult
]
{
override
def
answer
(
invocation
:
InvocationOnMock
)
:
ParseResult
=
{
val
backend
=
invocation
.
getArgument
[
ParserBackendExternal
](
2
)
backend
.
startedParsingSession
(
Some
(
sampleParseRequest
.
mainFileUri
),
parserInfo
)
val
mainFileUri
=
invocation
.
getArgument
[
String
](
0
)
backend
.
startedParsingSession
(
Some
(
mainFileUri
),
parserInfo
)
sampleEvents
.
foreach
(
x
=>
x
.
emitOnBackend
(
backend
))
backend
.
finishedParsingSession
(
Some
(
ParseResult
.
ParseSkipped
),
mainFileUri
=
Some
(
sampleParseRequest
.
mainFileUri
)
mainFileUri
=
Some
(
mainFileUri
)
)
ParseResult
.
ParseSkipped
}
})
}
def
prepareParserFailureInvocation
()
:
Unit
=
{
when
(
dummyParser
.
parseExternal
(
any
(),
any
(),
any
(),
any
())).
thenAnswer
(
new
Answer
[
ParseResult
]
{
override
def
answer
(
invocation
:
InvocationOnMock
)
:
ParseResult
=
{
val
backend
=
invocation
.
getArgument
[
ParserBackendExternal
](
2
)
val
mainFileUri
=
invocation
.
getArgument
[
String
](
0
)
backend
.
startedParsingSession
(
Some
(
mainFileUri
),
parserInfo
)
sampleEvents
.
foreach
(
x
=>
x
.
emitOnBackend
(
backend
))
throw
new
UnsupportedOperationException
(
"parsing process just crashed!"
)
}
})
}
}
"a CalculationParser"
when
{
"parsing an already extracted valid calculation"
should
{
"record starting and finishing parse events"
in
new
Fixture
{
prepareParserMockInvocation
()
val
result
=
worker
.
processRequest
(
sampleParseRequest
,
unusedPath
)
"record starting and finishing parse events"
in
{
val
f
=
new
Fixture
f
.
prepareParserStandardInvocation
()
val
result
=
f
.
worker
.
processRequest
(
sampleParseRequest
,
unusedPath
)
assert
(
result
.
isInstanceOf
[
InMemoryResult
],
"results should have been kept in memory"
)
val
inMemory
=
result
.
asInstanceOf
[
InMemoryResult
]
assert
(
inMemory
.
start
.
nonEmpty
,
"expected a start event to be emitted"
)
assert
(
inMemory
.
end
.
nonEmpty
,
"expected a finish event to be emitted"
)
}
"record all emitted events in the correct order"
in
new
Fixture
{
prepareParserMockInvocation
()
val
result
=
worker
.
processRequest
(
sampleParseRequest
,
unusedPath
)
"record all emitted events in the correct order"
in
{
val
f
=
new
Fixture
f
.
prepareParserStandardInvocation
()
val
result
=
f
.
worker
.
processRequest
(
sampleParseRequest
,
unusedPath
)
assert
(
result
.
isInstanceOf
[
InMemoryResult
],
"results should have been kept in memory"
)
val
inMemory
=
result
.
asInstanceOf
[
InMemoryResult
]
inMemory
.
events
.
zip
(
sampleEvents
).
foreach
(
x
=>
assert
(
x
.
_1
==
x
.
_2
))
assert
(
inMemory
.
events
===
sampleEvents
,
"emitted and recorded events do not match"
)
}
"handle parsing failures and return an appropriate result"
in
new
Fixture
{
when
(
dummyParser
.
parseExternal
(
any
(),
any
(),
any
(),
any
())).
thenAnswer
(
new
Answer
[
ParseResult
]
{
override
def
answer
(
invocation
:
InvocationOnMock
)
:
ParseResult
=
{
val
backend
=
invocation
.
getArgument
[
ParserBackendExternal
](
2
)
backend
.
startedParsingSession
(
Some
(
sampleParseRequest
.
mainFileUri
),
parserInfo
)
sampleEvents
.
foreach
(
x
=>
x
.
emitOnBackend
(
backend
))
throw
new
UnsupportedOperationException
(
"parsing process just crashed!"
)
}
})
val
result
=
worker
.
processRequest
(
sampleParseRequest
,
unusedPath
)
"handle parsing failures and return an appropriate result"
in
{
val
f
=
new
Fixture
f
.
prepareParserFailureInvocation
()
val
result
=
f
.
worker
.
processRequest
(
sampleParseRequest
,
unusedPath
)
assert
(
result
.
isInstanceOf
[
InMemoryResult
],
"results should have been kept in memory"
)
val
inMemory
=
result
.
asInstanceOf
[
InMemoryResult
]
assert
(
inMemory
.
result
==
ParseResult
.
ParseFailure
)
...
...
@@ -109,9 +107,10 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar {
assert
(
inMemory
.
end
.
get
.
parserErrors
.
children
.
nonEmpty
,
"should have error messages"
)
}
"gracefully fail parsing requests with unknown parsers"
in
new
Fixture
{
val
anotherRequest
=
sampleParseRequest
.
copy
(
parserName
=
"nonSenseParser"
)
val
result
=
worker
.
processRequest
(
anotherRequest
,
unusedPath
)
"gracefully fail parsing requests with unknown parsers"
in
{
val
f
=
new
Fixture
val
anotherRequest
=
sampleParseRequest
.
withParserName
(
"nonSenseParser"
)
val
result
=
f
.
worker
.
processRequest
(
anotherRequest
,
unusedPath
)
assert
(
result
.
isInstanceOf
[
InMemoryResult
],
"results should have been kept in memory"
)
val
inMemory
=
result
.
asInstanceOf
[
InMemoryResult
]
assert
(
inMemory
.
result
==
ParseResult
.
ParseFailure
,
"should have a failed status"
)
...
...
@@ -119,11 +118,12 @@ class CalculationParsingEngineSpec extends WordSpec with MockitoSugar {
assert
(
inMemory
.
end
.
get
.
parserErrors
.
children
.
nonEmpty
,
"should have error messages"
)
}
"specify the correct main file to the parser"
in
new
Fixture
{
when
(
dummyParser
.
parseExternal
(
any
(),
any
(),
any
(),
any
())).
thenReturn
(
ParseResult
.
ParseSkipped
)
"specify the correct main file to the parser"
in
{
val
f
=
new
Fixture
when
(
f
.
dummyParser
.
parseExternal
(
any
(),
any
(),
any
(),
any
())).
thenReturn
(
ParseResult
.
ParseSkipped
)
val
targetPath
=
sampleParseRequest
.
treeTask
.
treeBasePath
.
resolve
(
sampleParseRequest
.
relativePath
)
val
result
=
worker
.
processRequest
(
sampleParseRequest
,
targetPath
)
verify
(
dummyParser
).
parseExternal
(
any
(),
raw
(
targetPath
),
any
(),
any
())
f
.
worker
.
processRequest
(
sampleParseRequest
,
targetPath
)
verify
(
f
.
dummyParser
).
parseExternal
(
any
(),
raw
(
targetPath
),
any
(),
any
())
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment