|
29 | 29 | import java.util.concurrent.ExecutionException;
|
30 | 30 |
|
31 | 31 | public class PubSub {
|
| 32 | + |
| 33 | + // When run normally, we want to exit nicely even if something goes wrong |
| 34 | + // When run from CI, we want to let an exception escape which in turn causes the |
| 35 | + // exec:java task to return a non-zero exit code |
| 36 | + static String ciPropValue = System.getProperty("aws.crt.ci"); |
| 37 | + static boolean isCI = ciPropValue != null && Boolean.valueOf(ciPropValue); |
| 38 | + |
32 | 39 | static String clientId = "test-" + UUID.randomUUID().toString();
|
33 | 40 | static String rootCaPath;
|
34 | 41 | static String certPath;
|
@@ -139,6 +146,7 @@ static void parseCommandLine(String[] args) {
|
139 | 146 | }
|
140 | 147 | break;
|
141 | 148 | case "-w":
|
| 149 | + case "--websockets": |
142 | 150 | useWebsockets = true;
|
143 | 151 | break;
|
144 | 152 | case "--x509":
|
@@ -200,21 +208,37 @@ static void onRejectedError(RejectedError error) {
|
200 | 208 | System.out.println("Request rejected: " + error.code.toString() + ": " + error.message);
|
201 | 209 | }
|
202 | 210 |
|
| 211 | + /* |
| 212 | + * When called during a CI run, throw an exception that will escape and fail the exec:java task |
| 213 | + * When called otherwise, print what went wrong (if anything) and just continue (return from main) |
| 214 | + */ |
| 215 | + static void onApplicationFailure(Throwable cause) { |
| 216 | + if (isCI) { |
| 217 | + throw new RuntimeException("BasicPubSub execution failure", cause); |
| 218 | + } else if (cause != null) { |
| 219 | + System.out.println("Exception encountered: " + cause.toString()); |
| 220 | + } |
| 221 | + } |
| 222 | + |
203 | 223 | public static void main(String[] args) {
|
| 224 | + |
204 | 225 | parseCommandLine(args);
|
205 | 226 | if (showHelp || endpoint == null) {
|
206 | 227 | printUsage();
|
| 228 | + onApplicationFailure(null); |
207 | 229 | return;
|
208 | 230 | }
|
209 | 231 |
|
210 | 232 | if (!useWebsockets) {
|
211 | 233 | if (certPath == null || keyPath == null) {
|
212 | 234 | printUsage();
|
| 235 | + onApplicationFailure(null); |
213 | 236 | return;
|
214 | 237 | }
|
215 | 238 | } else if (useX509Credentials) {
|
216 | 239 | if (x509RoleAlias == null || x509Endpoint == null || x509Thing == null || x509CertPath == null || x509KeyPath == null) {
|
217 | 240 | printUsage();
|
| 241 | + onApplicationFailure(null); |
218 | 242 | return;
|
219 | 243 | }
|
220 | 244 | }
|
@@ -318,7 +342,7 @@ public void onConnectionResumed(boolean sessionPresent) {
|
318 | 342 | disconnected.get();
|
319 | 343 | }
|
320 | 344 | } catch (CrtRuntimeException | InterruptedException | ExecutionException ex) {
|
321 |
| - System.out.println("Exception encountered: " + ex.toString()); |
| 345 | + onApplicationFailure(ex); |
322 | 346 | }
|
323 | 347 |
|
324 | 348 | CrtResource.waitForNoResources();
|
|
0 commit comments