Skip to content

Commit ddd2bed

Browse files
Artem LabazinArtem Labazin
authored andcommitted
improve helper
1 parent 59fdf86 commit ddd2bed

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

client/src/test/java/io/appulse/epmd/java/client/LocalEpmdHelper.java

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import java.io.InputStreamReader;
2525

2626
import lombok.SneakyThrows;
27+
import lombok.extern.slf4j.Slf4j;
2728
import lombok.val;
2829

30+
@Slf4j
2931
final class LocalEpmdHelper {
3032

3133
@SneakyThrows
@@ -44,40 +46,47 @@ static boolean exists () {
4446
return process.exitValue() == 0;
4547
}
4648

47-
@SneakyThrows
4849
static void run () {
4950
if (isRunning()) {
5051
kill();
5152
}
5253

5354
val builder = new ProcessBuilder("epmd", "-daemon", "-relaxed_command_check");
54-
val process = builder.start();
55-
if (!process.waitFor(1, MINUTES)) {
56-
process.destroy();
57-
throw new RuntimeException("Local EPMD daemon doesn't respond");
58-
}
59-
if (process.exitValue() != 0) {
60-
process.destroy();
61-
throw new RuntimeException("Local EPMD daemon doesn't run");
55+
try {
56+
val process = builder.start();
57+
if (!process.waitFor(1, MINUTES)) {
58+
process.destroy();
59+
throw new RuntimeException("Local EPMD daemon doesn't respond");
60+
}
61+
if (process.exitValue() != 0) {
62+
process.destroy();
63+
throw new RuntimeException("Local EPMD daemon doesn't run");
64+
}
65+
SECONDS.sleep(1);
66+
} catch (Exception ex) {
67+
log.error("starting EPMD error", ex);
6268
}
63-
SECONDS.sleep(1);
6469
}
6570

66-
@SneakyThrows
6771
static void kill () {
6872
if (!isRunning()) {
6973
return;
7074
}
75+
7176
val pids = getEpmdPids();
72-
val builder = new ProcessBuilder("kill", "-9", pids);
73-
val process = builder.start();
74-
if (!process.waitFor(1, MINUTES)) {
75-
process.destroy();
76-
throw new RuntimeException("Killing local EPMD is too long, pid: " + pids);
77-
}
78-
if (process.exitValue() != 0) {
79-
process.destroy();
80-
throw new RuntimeException("Couldn't kill local EPMD with PID " + pids);
77+
val builder = new ProcessBuilder("kill", "-s 9", pids);
78+
try {
79+
val process = builder.start();
80+
if (!process.waitFor(1, MINUTES)) {
81+
process.destroy();
82+
throw new RuntimeException("Killing local EPMD is too long, pid: " + pids);
83+
}
84+
if (process.exitValue() != 0) {
85+
process.destroy();
86+
throw new RuntimeException("Couldn't kill local EPMD with PID " + pids);
87+
}
88+
} catch (Exception ex) {
89+
log.error("killing EPMD error", ex);
8190
}
8291
}
8392

server/src/main/java/io/appulse/epmd/java/server/SubcommandKill.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright 2020 the original author or authors.
43
*

0 commit comments

Comments
 (0)