Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
6e21df42
Commit
6e21df42
authored
Jul 16, 2018
by
Stefan Schuhbaeck
Browse files
testrunner
parent
6fe892dd
Pipeline
#62061
failed with stage
in 1 minute and 4 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/projects/ScenarioRun.java
View file @
6e21df42
...
...
@@ -81,7 +81,7 @@ public class ScenarioRun implements Runnable {
synchronized
(
scenarioStore
)
{
logger
.
info
(
String
.
format
(
"Initializing scenario. Start of scenario '%s'..."
,
scenario
.
getName
()));
scenarioStore
.
getTopography
().
reset
();
System
.
out
.
println
(
"StartIt "
+
scenario
.
getName
());
MainModelBuilder
modelBuilder
=
new
MainModelBuilder
(
scenarioStore
);
modelBuilder
.
createModelAndRandom
();
...
...
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/DataProcessingJsonManager.java
View file @
6e21df42
...
...
@@ -278,4 +278,8 @@ public class DataProcessingJsonManager {
return
maxId
;
}
public
boolean
containsOutputFile
(
String
name
){
return
this
.
outputFiles
.
stream
().
anyMatch
(
f
->
f
.
getFileName
().
equals
(
name
));
}
}
VadereSimulator/tests/org/vadere/simulator/control/ScenarioExecutorService.java
View file @
6e21df42
...
...
@@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
import
org.vadere.simulator.projects.Scenario
;
import
org.vadere.simulator.projects.ScenarioRun
;
import
java.util.HashMap
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.LinkedBlockingQueue
;
...
...
@@ -17,6 +18,7 @@ import java.util.concurrent.TimeUnit;
public
class
ScenarioExecutorService
extends
ThreadPoolExecutor
{
private
static
Logger
log
=
LogManager
.
getLogger
(
ScenarioExecutorService
.
class
);
// private HashMap<String, Throwable> output
public
static
ExecutorService
newFixedThreadPool
(
int
nThreads
,
ThreadFactory
threadFactory
)
{
return
new
ScenarioExecutorService
(
nThreads
,
nThreads
,
...
...
VadereSimulator/tests/org/vadere/simulator/projects/migration/StdOutRedirecter.java
0 → 100644
View file @
6e21df42
package
org.vadere.simulator.projects.migration
;
import
org.apache.log4j.LogManager
;
import
org.apache.log4j.Logger
;
import
java.io.PrintStream
;
public
class
StdOutRedirecter
{
private
Logger
logger
=
LogManager
.
getLogger
(
StdOutRedirecter
.
class
);
private
PrintStream
defaultOut
;
private
PrintStream
defaultErr
;
public
StdOutRedirecter
(){
// this.logger = logger;
}
public
void
redirect
(){
defaultOut
=
System
.
out
;
defaultErr
=
System
.
err
;
System
.
setOut
(
useLogger
(
System
.
out
));
System
.
setErr
(
useLogger
(
System
.
err
));
}
private
PrintStream
useLogger
(
final
PrintStream
realPrintStream
){
return
new
PrintStream
(
realPrintStream
){
@Override
public
void
print
(
final
String
string
){
logger
.
warn
(
string
);
}
@Override
public
void
println
(
final
String
string
){
logger
.
warn
(
string
);
}
};
}
public
void
reset
(){
System
.
setOut
(
defaultOut
);
System
.
setErr
(
defaultErr
);
}
}
VadereSimulator/tests/org/vadere/simulator/projects/migration/TestSimulationRunner.java
View file @
6e21df42
...
...
@@ -7,6 +7,7 @@ import org.vadere.simulator.control.ScenarioExecutorService;
import
org.vadere.simulator.entrypoints.ScenarioFactory
;
import
org.vadere.simulator.projects.Scenario
;
import
org.vadere.simulator.projects.ScenarioRun
;
import
org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager
;
import
java.io.File
;
import
java.io.IOException
;
...
...
@@ -29,10 +30,16 @@ public class TestSimulationRunner {
private
static
Logger
logger
=
LogManager
.
getLogger
(
TestSimulationRunner
.
class
);
private
final
String
outputPath
=
"target/TestRuns/output"
;
private
ThreadFactory
threadFactory
=
r
->
{
final
Thread
thread
=
new
Thread
(
r
);
thread
.
setUncaughtExceptionHandler
(
(
t
,
e
)
->
{
System
.
out
.
println
(
t
.
getName
());
@Test
public
void
RunAllSimulations
()
{
// remove/clean dir from target folder and create new empty tree (used for output)
});
return
thread
;
};
private
void
initOutputDir
(){
try
{
if
(
Paths
.
get
(
outputPath
).
toFile
().
exists
())
{
Files
.
walk
(
Paths
.
get
(
outputPath
).
getParent
())
...
...
@@ -44,20 +51,25 @@ public class TestSimulationRunner {
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
ThreadFactory
threadFactory
=
r
->
{
final
Thread
thread
=
new
Thread
(
r
);
return
thread
;
}
;
@Test
public
void
RunAllSimulations
()
{
// remove/clean dir from target folder and create new empty tree (used for output)
initOutputDir
()
;
ExecutorService
threadPool
=
ScenarioExecutorService
.
newFixedThreadPool
(
4
,
threadFactory
);
ExecutorService
threadPool
=
ScenarioExecutorService
.
newFixedThreadPool
(
1
,
threadFactory
);
ScenarioAppender
scenarioAppender
=
new
ScenarioAppender
(
Paths
.
get
(
outputPath
));
LogManager
.
getRootLogger
().
addAppender
(
scenarioAppender
);
List
<
Path
>
scenarios
=
getScenarioFiles
(
Paths
.
get
(
"../VadereModelTests/TestOSM"
));
// StdOutRedirecter redirecter = new StdOutRedirecter();
// redirecter.redirect();
List
<
Path
>
scenarios
=
getScenarioFiles
(
Paths
.
get
(
"../VadereModelTests"
));
// List<Path> scenarios = getScenarioFiles(Paths.get("../VadereModelTests/TestOSM"));
List
<
Path
>
chicken
=
scenarios
.
stream
().
filter
(
f
->
f
.
getFileName
().
endsWith
(
"basic_1_chicken_osm1.scenario"
)).
collect
(
Collectors
.
toList
());
List
<
Path
>
subset
=
scenarios
.
subList
(
0
,
3
);
List
<
Path
>
subset
=
scenarios
.
subList
(
0
,
5
);
subset
.
addAll
(
chicken
);
System
.
out
.
println
(
subset
.
size
());
for
(
Path
scenarioPath
:
subset
)
{
...
...
@@ -69,23 +81,84 @@ public class TestSimulationRunner {
}
logger
.
info
(
"#####Start scenario: "
+
scenarioPath
.
getFileName
());
s
.
getAttributesSimulation
().
setWriteSimulationData
(
true
);
threadPool
.
submit
(
new
ScenarioRun
(
s
,
outputPath
,
(
listener
)
->
System
.
out
.
println
(
"done"
)));
}
threadPool
.
shutdown
();
if
(!
threadPool
.
isTerminated
())
{
try
{
logger
.
info
(
"waiting
6
0
sec
...."
);
threadPool
.
awaitTermination
(
6
0
,
TimeUnit
.
SECOND
S
);
logger
.
info
(
"waiting
1
0
min
...."
);
threadPool
.
awaitTermination
(
1
0
,
TimeUnit
.
MINUTE
S
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
threadPool
.
shutdownNow
();
}
finally
{
LogManager
.
getRootLogger
().
removeAppender
(
scenarioAppender
);
System
.
out
.
println
(
"before reset"
);
// redirecter.reset();
System
.
out
.
println
(
"after reset"
);
}
}
}
private
void
addTrajectoriesOutputfile
(
final
Scenario
scenario
){
DataProcessingJsonManager
m
=
scenario
.
getDataProcessingJsonManager
();
}
@Test
public
void
TestProjects
(){
List
<
Path
>
projects
=
getProjectDirs
(
Paths
.
get
(
"../VadereModelTests/"
));
for
(
Path
projectPath
:
projects
)
{
//
}
}
@Test
public
void
getProjectDirsTest
(){
getProjectDirs
(
Paths
.
get
(
"../VadereModelTests/"
)).
forEach
(
p
->
System
.
out
.
println
(
p
.
toString
()));
}
private
List
<
Path
>
getProjectDirs
(
Path
vadereModelTest
){
LinkedList
<
Path
>
projectPath
=
new
LinkedList
<>();
FileVisitor
<
Path
>
visitor
=
new
FileVisitor
<
Path
>()
{
@Override
public
FileVisitResult
preVisitDirectory
(
Path
dir
,
BasicFileAttributes
attrs
)
throws
IOException
{
if
(
Files
.
exists
(
dir
.
resolve
(
"vadere.project"
))){
projectPath
.
add
(
dir
);
return
FileVisitResult
.
SKIP_SUBTREE
;
}
return
FileVisitResult
.
CONTINUE
;
}
@Override
public
FileVisitResult
visitFile
(
Path
file
,
BasicFileAttributes
attrs
)
throws
IOException
{
return
FileVisitResult
.
CONTINUE
;
}
@Override
public
FileVisitResult
visitFileFailed
(
Path
file
,
IOException
exc
)
throws
IOException
{
return
FileVisitResult
.
CONTINUE
;
}
@Override
public
FileVisitResult
postVisitDirectory
(
Path
dir
,
IOException
exc
)
throws
IOException
{
return
FileVisitResult
.
CONTINUE
;
}
};
try
{
Files
.
walkFileTree
(
vadereModelTest
,
visitor
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
projectPath
;
}
private
List
<
Path
>
getScenarioFiles
(
Path
vadereModelTest
)
{
...
...
VadereState/src/org/vadere/state/attributes/AttributesSimulation.java
View file @
6e21df42
...
...
@@ -61,6 +61,56 @@ public class AttributesSimulation extends Attributes {
return
randomSeed
;
}
public
void
setFinishTime
(
double
finishTime
)
{
checkSealed
();
this
.
finishTime
=
finishTime
;
}
public
void
setSimTimeStepLength
(
double
simTimeStepLength
)
{
checkSealed
();
this
.
simTimeStepLength
=
simTimeStepLength
;
}
public
void
setRealTimeSimTimeRatio
(
double
realTimeSimTimeRatio
)
{
checkSealed
();
this
.
realTimeSimTimeRatio
=
realTimeSimTimeRatio
;
}
public
void
setWriteSimulationData
(
boolean
writeSimulationData
)
{
checkSealed
();
this
.
writeSimulationData
=
writeSimulationData
;
}
public
void
setVisualizationEnabled
(
boolean
visualizationEnabled
)
{
checkSealed
();
this
.
visualizationEnabled
=
visualizationEnabled
;
}
public
void
setPrintFPS
(
boolean
printFPS
)
{
checkSealed
();
this
.
printFPS
=
printFPS
;
}
public
void
setNeedsBoundary
(
boolean
needsBoundary
)
{
checkSealed
();
this
.
needsBoundary
=
needsBoundary
;
}
public
void
setDigitsPerCoordinate
(
int
digitsPerCoordinate
)
{
checkSealed
();
this
.
digitsPerCoordinate
=
digitsPerCoordinate
;
}
public
void
setUseRandomSeed
(
boolean
useRandomSeed
)
{
checkSealed
();
this
.
useRandomSeed
=
useRandomSeed
;
}
public
void
setRandomSeed
(
long
randomSeed
)
{
checkSealed
();
this
.
randomSeed
=
randomSeed
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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