-
Notifications
You must be signed in to change notification settings - Fork 68
/
ExitStatusIntegrationTests.java
103 lines (89 loc) · 4.29 KB
/
ExitStatusIntegrationTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.cli.testing;
import org.junit.jupiter.api.Test;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
class ExitStatusIntegrationTests {
private final String java = Optional.ofNullable(System.getenv(
"JAVA_HOME")).map(v -> v + "/bin/java").orElse("java");
private final static String JARNAME = "target/nbr.jar";
@Test
void testExitStatusOnBadParam() {
ProcessInvoker invoker = new ProcessInvoker();
invoker.setLogDir("logs/test");
ProcessResult result = invoker.run("exitstatus_badparam", 15,
java, "-jar", JARNAME, "--logs-dir", "logs/test/badparam/",
"badparam"
);
assertThat(result.exception).isNull();
String stderr = String.join("\n", result.getStderrData());
assertThat(stderr).contains("Scenario stopped due to error");
assertThat(result.exitStatus).isEqualTo(2);
}
@Test
void testExitStatusOnActivityInitException() {
ProcessInvoker invoker = new ProcessInvoker();
invoker.setLogDir("logs/test");
ProcessResult result = invoker.run("exitstatus_initexception", 15,
java, "-jar", JARNAME, "--logs-dir", "logs/test/initerror", "run",
"driver=diag", "op=initdelay:initdelay=notanumber"
);
assertThat(result.exception).isNull();
String stderr = String.join("\n", result.getStdoutData());
assertThat(stderr).contains("For input string: \"notanumber\"");
assertThat(result.exitStatus).isEqualTo(2);
}
@Test
void testExitStatusOnActivityBasicCommandException() {
ProcessInvoker invoker = new ProcessInvoker();
invoker.setLogDir("logs/test");
// Forcing a thread exception via basic command issue.
ProcessResult result = invoker.run("exitstatus_threadexception", 30,
"java", "-jar", JARNAME, "--logs-dir", "logs/test/threadexcep", "--logs-level", "debug", "run",
"driver=diag", "cyclerate=10", "not_a_thing", "cycles=100", "-vvv"
);
String stdout = String.join("\n", result.getStdoutData());
assertThat(stdout).contains("You requested exactly one instance of a service by name 'not_a_thing'");
assertThat(result.exitStatus).isEqualTo(2);
}
@Test
void testExitStatusOnActivityOpException() {
ProcessInvoker invoker = new ProcessInvoker();
invoker.setLogDir("logs/test");
ProcessResult result = invoker.run("exitstatus_asyncstoprequest", 60,
"java", "-jar", JARNAME, "--logs-dir", "logs/test/asyncstop", "--logs-level", "debug", "run",
"driver=diag", "threads=2", "cyclerate=10", "op=erroroncycle:erroroncycle=10", "cycles=50", "-vvv"
);
assertThat(result.exception).isNull();
String stdout = String.join("\n", result.getStdoutData());
assertThat(stdout).contains("Diag was requested to stop on cycle 10");
assertThat(result.exitStatus).isEqualTo(2);
}
// @Test
// public void testCloseErrorHandlerOnSpace() {
// ProcessInvoker invoker = new ProcessInvoker();
// invoker.setLogDir("logs/test");
// ProcessResult samples = invoker.run("exitstatus_erroronclose", 30,
// java, "-jar", JARNAME, "--logs-dir", "logs/test/error_on_close", "run",
// "driver=diag", "threads=2", "rate=5", "op=noop", "cycles=10", "erroronclose=true", "-vvv"
// );
// String stdout = String.join("\n", samples.getStdoutData());
// String stderr = String.join("\n", samples.getStderrData());
// assertThat(samples.exitStatus).isEqualTo(2);
// assertThat(stderr).contains("diag space was configured to throw");
// }
}