8321163: [test] OutputAnalyzer.getExitValue() unnecessarily logs even when process has already completed

Reviewed-by: stefank, lmesnik
This commit is contained in:
Jaikiran Pai 2023-12-05 10:58:02 +00:00
parent 30817b7423
commit 672f37324f

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -120,6 +120,7 @@ public interface OutputBuffer {
private final StreamTask outTask; private final StreamTask outTask;
private final StreamTask errTask; private final StreamTask errTask;
private final Process p; private final Process p;
private volatile Integer exitValue; // null implies we don't yet know
private final void logProgress(String state) { private final void logProgress(String state) {
System.out.println("[" + Instant.now().toString() + "] " + state System.out.println("[" + Instant.now().toString() + "] " + state
@ -146,14 +147,17 @@ public interface OutputBuffer {
@Override @Override
public int getExitValue() { public int getExitValue() {
if (exitValue != null) {
return exitValue;
}
try { try {
logProgress("Waiting for completion"); logProgress("Waiting for completion");
boolean aborted = true; boolean aborted = true;
try { try {
int result = p.waitFor(); exitValue = p.waitFor();
logProgress("Waiting for completion finished"); logProgress("Waiting for completion finished");
aborted = false; aborted = false;
return result; return exitValue;
} finally { } finally {
if (aborted) { if (aborted) {
logProgress("Waiting for completion FAILED"); logProgress("Waiting for completion FAILED");