Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
1c21dd07
Commit
1c21dd07
authored
Nov 18, 2015
by
Peter van 't Hof
Browse files
Added tests for resources
parent
cf01cf3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/CommandLineResources.scala
View file @
1c21dd07
...
...
@@ -43,10 +43,12 @@ trait CommandLineResources extends CommandLineFunction with Configurable {
* @return number of threads
*/
private
def
getThreads
(
default
:
Int
)
:
Int
=
{
val
maxThreads
:
Int
=
config
(
"maxthreads"
,
default
=
24
)
val
maxThreads
:
Option
[
Int
]
=
config
(
"maxthreads"
)
val
threads
:
Int
=
config
(
"threads"
,
default
=
default
)
if
(
maxThreads
>
threads
)
threads
else
maxThreads
maxThreads
match
{
case
Some
(
max
)
=>
if
(
max
>
threads
)
threads
else
max
case
_
=>
threads
}
}
def
setResources
()
:
Unit
=
{
...
...
@@ -79,7 +81,7 @@ trait CommandLineResources extends CommandLineFunction with Configurable {
if
(
vmem
.
isDefined
)
jobResourceRequests
=
jobResourceRequests
.
filterNot
(
_
.
contains
(
"h_vmem="
))
if
(
retry
>
0
)
logger
.
info
(
"Auto raise memory on retry"
)
retry
+=
1
this
.
freeze
()
this
.
freeze
FieldValues
()
}
var
threadsCorrection
=
0
...
...
public/biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/CommandLineResourcesTest.scala
0 → 100644
View file @
1c21dd07
package
nl.lumc.sasc.biopet.core
import
nl.lumc.sasc.biopet.utils.config.
{
Config
,
Configurable
}
import
org.broadinstitute.gatk.queue.function.CommandLineFunction
import
org.scalatest.Matchers
import
org.scalatest.testng.TestNGSuite
import
org.testng.annotations.Test
import
scala.language.reflectiveCalls
/**
* Created by pjvanthof on 17/11/15.
*/
class
CommandLineResourcesTest
extends
TestNGSuite
with
Matchers
{
class
CommandLineFunctionMock
(
c
:
Map
[
String
,
Any
]
=
Map
())
extends
CommandLineFunction
with
Configurable
{
override
def
freezeFieldValues
()
{}
def
commandLine
=
"command"
val
root
=
null
override
def
globalConfig
=
new
Config
(
c
)
}
@Test
def
testDefaults
()
:
Unit
=
{
val
cmd
=
new
CommandLineFunctionMock
with
CommandLineResources
cmd
.
coreMemory
shouldBe
2.0
cmd
.
residentFactor
shouldBe
1.2
cmd
.
vmemFactor
shouldBe
1.4
cmd
.
retry
shouldBe
0
cmd
.
threads
shouldBe
1
cmd
.
setResources
()
cmd
.
memoryLimit
shouldBe
Some
(
cmd
.
coreMemory
*
cmd
.
threads
)
cmd
.
residentLimit
shouldBe
Some
(
cmd
.
coreMemory
*
cmd
.
residentFactor
)
cmd
.
vmem
shouldBe
Some
((
cmd
.
coreMemory
*
cmd
.
vmemFactor
)
+
"G"
)
cmd
.
jobResourceRequests
shouldBe
empty
cmd
.
freezeFieldValues
()
cmd
.
jobResourceRequests
should
contain
(
"h_vmem="
+
cmd
.
vmem
.
get
)
cmd
.
setupRetry
()
cmd
.
retry
shouldBe
1
cmd
.
setupRetry
()
cmd
.
retry
shouldBe
2
cmd
.
setupRetry
()
cmd
.
retry
shouldBe
3
}
@Test
def
testMaxThreads
()
:
Unit
=
{
val
cmd
=
new
CommandLineFunctionMock
(
Map
(
"maxthreads"
->
5
,
"threads"
->
10
))
with
CommandLineResources
cmd
.
threads
shouldBe
5
}
@Test
def
testCombine
()
:
Unit
=
{
val
cmd1
=
new
CommandLineFunctionMock
with
CommandLineResources
val
cmd2
=
new
CommandLineFunctionMock
with
CommandLineResources
val
mainCmd
=
new
CommandLineFunctionMock
with
CommandLineResources
{
def
combine
(
functions
:
List
[
CommandLineResources
])
=
combineResources
(
functions
)
}
mainCmd
.
combine
(
List
(
cmd1
,
cmd2
))
mainCmd
.
coreMemory
shouldBe
2.0
mainCmd
.
residentFactor
shouldBe
1.2
mainCmd
.
vmemFactor
shouldBe
1.4
mainCmd
.
memoryLimit
shouldBe
Some
(
4.0
)
mainCmd
.
retry
shouldBe
0
mainCmd
.
threads
shouldBe
2
}
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment