Skip to content

Commit 898f091

Browse files
committed
address pr feedback
1 parent 09c4ac8 commit 898f091

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/it/ITLocalSslValidationTest.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import java.sql.Statement;
3939
import java.util.ArrayList;
4040
import java.util.List;
41+
import java.util.concurrent.TimeUnit;
42+
import java.util.concurrent.TimeoutException;
4143
import javax.net.ssl.KeyManagerFactory;
4244
import javax.net.ssl.SSLContext;
4345
import javax.net.ssl.SSLParameters;
@@ -132,10 +134,11 @@ public void configure(HttpsParameters params) {
132134
+ " }\n"
133135
+ "}";
134136
}
137+
byte[] responseBytes = response.getBytes(StandardCharsets.UTF_8);
135138
exchange.getResponseHeaders().set("Content-Type", "application/json");
136-
exchange.sendResponseHeaders(200, response.length());
139+
exchange.sendResponseHeaders(200, responseBytes.length);
137140
try (OutputStream os = exchange.getResponseBody()) {
138-
os.write(response.getBytes());
141+
os.write(responseBytes);
139142
}
140143
});
141144
}
@@ -201,14 +204,24 @@ private ProcessResult runSubprocess(String trustStore, String password) throws E
201204
builder.redirectErrorStream(true);
202205
Process process = builder.start();
203206

204-
String output;
205-
try (InputStreamReader reader =
206-
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
207-
output = CharStreams.toString(reader);
207+
String output = "";
208+
boolean finished = false;
209+
try {
210+
try (InputStreamReader reader =
211+
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
212+
output = CharStreams.toString(reader);
213+
}
214+
finished = process.waitFor(10, TimeUnit.SECONDS);
215+
if (!finished) {
216+
throw new TimeoutException("Subprocess timed out after 10 seconds");
217+
}
218+
int exitCode = process.exitValue();
219+
return new ProcessResult(exitCode, output);
220+
} finally {
221+
if (!finished && process.isAlive()) {
222+
process.destroyForcibly();
223+
}
208224
}
209-
210-
int exitCode = process.waitFor();
211-
return new ProcessResult(exitCode, output);
212225
}
213226

214227
@Test

0 commit comments

Comments
 (0)