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
6fe892dd
Commit
6fe892dd
authored
Jul 13, 2018
by
Stefan Schuhbaeck
Browse files
add ScenarioAppender to testSimulationRunner
parent
483aaa41
Changes
2
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/tests/org/vadere/simulator/control/ScenarioExecutorService.java
View file @
6fe892dd
package
org.vadere.simulator.control
;
import
org.apache.log4j.LogManager
;
import
org.apache.log4j.Logger
;
import
org.vadere.simulator.projects.Scenario
;
import
org.vadere.simulator.projects.ScenarioRun
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.LinkedBlockingQueue
;
...
...
@@ -8,8 +13,11 @@ import java.util.concurrent.ThreadFactory;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
public
class
ScenarioExecutorService
extends
ThreadPoolExecutor
{
private
static
Logger
log
=
LogManager
.
getLogger
(
ScenarioExecutorService
.
class
);
public
static
ExecutorService
newFixedThreadPool
(
int
nThreads
,
ThreadFactory
threadFactory
)
{
return
new
ScenarioExecutorService
(
nThreads
,
nThreads
,
0L
,
TimeUnit
.
MILLISECONDS
,
...
...
@@ -38,10 +46,10 @@ public class ScenarioExecutorService extends ThreadPoolExecutor {
protected
void
afterExecute
(
Runnable
r
,
Throwable
t
)
{
if
(
t
!=
null
)
{
// todo Throwable von scenario run abolen
System
.
out
.
println
(
"Error in execution found..."
);
log
.
info
(
"Error in execution found..."
);
t
.
printStackTrace
();
}
else
{
System
.
out
.
println
(
"Execution worked"
);
log
.
info
(
"Execution worked"
);
}
super
.
afterExecute
(
r
,
t
);
}
...
...
VadereSimulator/tests/org/vadere/simulator/projects/migration/TestSimulationRunner.java
View file @
6fe892dd
package
org.vadere.simulator.projects.migration
;
import
org.apache.log4j.LogManager
;
import
org.apache.log4j.Logger
;
import
org.junit.Test
;
import
org.vadere.simulator.control.ScenarioExecutorService
;
import
org.vadere.simulator.entrypoints.ScenarioFactory
;
...
...
@@ -18,12 +20,13 @@ import java.util.Comparator;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
public
class
TestSimulationRunner
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
TestSimulationRunner
.
class
);
private
final
String
outputPath
=
"target/TestRuns/output"
;
...
...
@@ -31,31 +34,31 @@ public class TestSimulationRunner {
public
void
RunAllSimulations
()
{
// remove/clean dir from target folder and create new empty tree (used for output)
try
{
Files
.
walk
(
Paths
.
get
(
outputPath
).
getParent
())
.
sorted
(
Comparator
.
reverseOrder
())
.
map
(
Path:
:
toFile
)
.
forEach
(
File:
:
deleteOnExit
);
if
(
Paths
.
get
(
outputPath
).
toFile
().
exists
())
{
Files
.
walk
(
Paths
.
get
(
outputPath
).
getParent
())
.
sorted
(
Comparator
.
reverseOrder
())
.
map
(
Path:
:
toFile
)
.
forEach
(
File:
:
delete
);
}
Files
.
createDirectories
(
Paths
.
get
(
outputPath
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
ThreadFactory
threadFactory
=
new
ThreadFactory
()
{
@Override
public
Thread
newThread
(
Runnable
r
)
{
// System.out.println("creating pooled thread");
final
Thread
thread
=
new
Thread
(
r
);
//todo LogManager neuer Appender
// thread.setUncaughtExceptionHandler(exceptionHandler);
return
thread
;
}
ThreadFactory
threadFactory
=
r
->
{
final
Thread
thread
=
new
Thread
(
r
);
return
thread
;
};
ExecutorService
threadPool
=
ScenarioExecutorService
.
newFixedThreadPool
(
4
,
threadFactory
);
ScenarioAppender
scenarioAppender
=
new
ScenarioAppender
(
Paths
.
get
(
outputPath
));
LogManager
.
getRootLogger
().
addAppender
(
scenarioAppender
);
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
);
subset
.
addAll
(
chicken
);
System
.
out
.
println
(
subset
.
size
());
for
(
Path
scenarioPath
:
subset
)
{
Scenario
s
=
null
;
...
...
@@ -65,18 +68,20 @@ public class TestSimulationRunner {
e
.
printStackTrace
();
}
System
.
out
.
println
(
"#####Start scenario: "
+
scenarioPath
.
getFileName
());
logger
.
info
(
"#####Start scenario: "
+
scenarioPath
.
getFileName
());
threadPool
.
submit
(
new
ScenarioRun
(
s
,
outputPath
,
(
listener
)
->
System
.
out
.
println
(
"done"
)));
}
threadPool
.
shutdown
();
if
(!
threadPool
.
isTerminated
())
{
try
{
System
.
out
.
println
(
"waiting 60 sec...."
);
logger
.
info
(
"waiting 60 sec...."
);
threadPool
.
awaitTermination
(
60
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
threadPool
.
shutdownNow
();
}
finally
{
LogManager
.
getRootLogger
().
removeAppender
(
scenarioAppender
);
}
}
...
...
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