Skip to content

Commit 0ff99e3

Browse files
committed
Make it easier to embed
1 parent 2bce106 commit 0ff99e3

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

chaos-runner/src/main/java/io/synadia/chaos/ChaosArguments.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,26 @@ public ChaosArguments js(boolean js) {
4343
}
4444

4545
public ChaosArguments workDirectory(String workDirectory) {
46+
if (workDirectory == null || workDirectory.trim().isEmpty()) {
47+
this.workDirectory = null;
48+
return this;
49+
}
4650
return workDirectory(Paths.get(workDirectory));
4751
}
4852

4953
public ChaosArguments workDirectory(File workDirectory) {
54+
if (workDirectory == null) {
55+
this.workDirectory = null;
56+
return this;
57+
}
5058
return workDirectory(workDirectory.getPath());
5159
}
5260

5361
public ChaosArguments workDirectory(Path workDirectory) {
62+
if (workDirectory == null) {
63+
this.workDirectory = null;
64+
return this;
65+
}
5466
this.workDirectory = workDirectory;
5567
return this;
5668
}
@@ -151,4 +163,52 @@ public void error(String errMsg) {
151163
System.err.println("ERROR: " + errMsg);
152164
System.exit(-1);
153165
}
166+
167+
public int getServers() {
168+
return servers;
169+
}
170+
171+
public String getClusterName() {
172+
return clusterName;
173+
}
174+
175+
public String getServerNamePrefix() {
176+
return serverNamePrefix;
177+
}
178+
179+
public boolean isJs() {
180+
return js;
181+
}
182+
183+
public Path getWorkDirectory() {
184+
return workDirectory;
185+
}
186+
187+
public long getInitialDelay() {
188+
return initialDelay;
189+
}
190+
191+
public long getDelay() {
192+
return delay;
193+
}
194+
195+
public long getDownTime() {
196+
return downTime;
197+
}
198+
199+
public boolean isRandom() {
200+
return random;
201+
}
202+
203+
public int getPort() {
204+
return port;
205+
}
206+
207+
public int getListen() {
208+
return listen;
209+
}
210+
211+
public int getMonitor() {
212+
return monitor;
213+
}
154214
}

chaos-runner/src/main/java/io/synadia/chaos/ChaosRunner.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ public static void main(String[] args) {
257257
}
258258

259259
public static ChaosRunner start(ChaosArguments a) {
260+
return start(a, true);
261+
}
262+
263+
public static ChaosRunner start(ChaosArguments a, boolean print) {
260264
NatsServerRunner.setDefaultOutputLevel(Level.SEVERE);
261265
try {
262266
INSTANCE = new ChaosRunner(a);
@@ -265,7 +269,9 @@ public static ChaosRunner start(ChaosArguments a) {
265269
System.out.println("Failed to start ChaosRunner: " + e.getMessage());
266270
System.exit(-1);
267271
}
268-
System.out.println(ChaosUtils.toString(INSTANCE, System.lineSeparator(), "[" + System.currentTimeMillis() + "] ", " ", ""));
272+
if (print) {
273+
System.out.println(ChaosUtils.toString(INSTANCE, System.lineSeparator(), "[" + System.currentTimeMillis() + "] ", " ", ""));
274+
}
269275

270276
Runtime.getRuntime().addShutdownHook(
271277
new Thread("app-shutdown-hook") {

0 commit comments

Comments
 (0)