|
32 | 32 | import org.junit.jupiter.api.Test;
|
33 | 33 |
|
34 | 34 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 35 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
35 | 36 | import static org.junit.jupiter.api.Assertions.assertNull;
|
36 | 37 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
37 | 38 |
|
@@ -120,6 +121,80 @@ private void testStartStop(boolean reusePort) throws Exception
|
120 | 121 | assertTrue(!monitor.isAlive());
|
121 | 122 | }
|
122 | 123 |
|
| 124 | + @Test |
| 125 | + public void testNoExitSystemProperty() throws Exception |
| 126 | + { |
| 127 | + System.setProperty("STOP.EXIT", "false"); |
| 128 | + ShutdownMonitor monitor = ShutdownMonitor.getInstance(); |
| 129 | + monitor.setPort(0); |
| 130 | + assertFalse(monitor.isExitVm()); |
| 131 | + monitor.start(); |
| 132 | + |
| 133 | + try (CloseableServer server = new CloseableServer()) |
| 134 | + { |
| 135 | + server.setStopAtShutdown(true); |
| 136 | + server.start(); |
| 137 | + |
| 138 | + //shouldn't be registered for shutdown on jvm |
| 139 | + assertTrue(ShutdownThread.isRegistered(server)); |
| 140 | + assertTrue(ShutdownMonitor.isRegistered(server)); |
| 141 | + |
| 142 | + String key = monitor.getKey(); |
| 143 | + int port = monitor.getPort(); |
| 144 | + |
| 145 | + stop("stop", port, key, true); |
| 146 | + monitor.await(); |
| 147 | + |
| 148 | + assertTrue(!monitor.isAlive()); |
| 149 | + assertTrue(server.stopped); |
| 150 | + assertTrue(!server.destroyed); |
| 151 | + assertTrue(!ShutdownThread.isRegistered(server)); |
| 152 | + assertTrue(!ShutdownMonitor.isRegistered(server)); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + /* |
| 157 | + * Disable these config tests because ShutdownMonitor is a |
| 158 | + * static singleton that cannot be unset, and thus would |
| 159 | + * need each of these methods executed it its own jvm - |
| 160 | + * current surefire settings only fork for a single test |
| 161 | + * class. |
| 162 | + * |
| 163 | + * Undisable to test individually as needed. |
| 164 | + */ |
| 165 | + @Disabled |
| 166 | + @Test |
| 167 | + public void testExitVmDefault() throws Exception |
| 168 | + { |
| 169 | + //Test that the default is to exit |
| 170 | + ShutdownMonitor monitor = ShutdownMonitor.getInstance(); |
| 171 | + monitor.setPort(0); |
| 172 | + assertTrue(monitor.isExitVm()); |
| 173 | + } |
| 174 | + |
| 175 | + @Disabled |
| 176 | + @Test |
| 177 | + public void testExitVmTrue() throws Exception |
| 178 | + { |
| 179 | + //Test setting exit true |
| 180 | + System.setProperty("STOP.EXIT", "true"); |
| 181 | + ShutdownMonitor monitor = ShutdownMonitor.getInstance(); |
| 182 | + monitor.setPort(0); |
| 183 | + assertTrue(monitor.isExitVm()); |
| 184 | + } |
| 185 | + |
| 186 | + @Disabled |
| 187 | + @Test |
| 188 | + public void testExitVmFalse() throws Exception |
| 189 | + { |
| 190 | + //Test setting exit false |
| 191 | + System.setProperty("STOP.EXIT", "false"); |
| 192 | + ShutdownMonitor monitor = ShutdownMonitor.getInstance(); |
| 193 | + monitor.setPort(0); |
| 194 | + assertFalse(monitor.isExitVm()); |
| 195 | + } |
| 196 | + |
| 197 | + @Disabled |
123 | 198 | @Test
|
124 | 199 | public void testForceStopCommand() throws Exception
|
125 | 200 | {
|
|
0 commit comments