Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit 7f4ce8d

Browse files
committed
moving emulator health check to src/test
1 parent 0517cb6 commit 7f4ce8d

3 files changed

Lines changed: 51 additions & 21 deletions

File tree

google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,6 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
9999
.setCredentials(NoCredentials.getInstance())
100100
.setRetrySettings(ServiceOptions.getNoRetrySettings());
101101

102-
String sendGetRequest(String request) throws IOException {
103-
104-
URL url = new URL("http", DEFAULT_HOST, this.getPort(), request);
105-
HttpURLConnection con = (HttpURLConnection) url.openConnection();
106-
con.setRequestMethod("GET");
107-
108-
InputStream in = con.getInputStream();
109-
String response = CharStreams.toString(new InputStreamReader(con.getInputStream()));
110-
in.close();
111-
return response;
112-
}
113-
114-
public String checkHealth() {
115-
try {
116-
return sendGetRequest("/");
117-
} catch (IOException e) {
118-
throw new RuntimeException(e);
119-
}
120-
}
121102

122103
/** A builder for {@code LocalDatastoreHelper} objects. */
123104
public static class Builder {
@@ -344,8 +325,6 @@ public void reset() throws IOException {
344325
*/
345326
@Override
346327
public void stop(Duration timeout) throws IOException, InterruptedException, TimeoutException {
347-
// TODO(gapic_upgrade): Temporarily addressing the flaky connection refused error
348-
checkHealth();
349328
sendPostRequest("/shutdown");
350329
waitForProcess(timeout);
351330
deleteRecursively(gcdPath);

google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ public void setUp() {
192192

193193
@AfterClass
194194
public static void afterClass() throws IOException, InterruptedException, TimeoutException {
195+
// TODO(gapic_upgrade): Temporarily addressing the flaky connection refused error
196+
EmulatorUtils.checkHealth(helper.getPort());
195197
helper.stop(Duration.ofMinutes(1));
196198
}
197199

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.datastore;
17+
18+
import com.google.common.io.CharStreams;
19+
import org.easymock.EasyMock;
20+
import org.easymock.IArgumentMatcher;
21+
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.InputStreamReader;
25+
import java.net.HttpURLConnection;
26+
import java.net.URL;
27+
import java.util.function.Predicate;
28+
29+
public class EmulatorUtils {
30+
static String sendGetRequest(int port, String request) throws IOException {
31+
32+
URL url = new URL("http", "localhost", port, request);
33+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
34+
con.setRequestMethod("GET");
35+
36+
InputStream in = con.getInputStream();
37+
String response = CharStreams.toString(new InputStreamReader(con.getInputStream()));
38+
in.close();
39+
return response;
40+
}
41+
42+
public static String checkHealth(int port) {
43+
try {
44+
return sendGetRequest(port, "/");
45+
} catch (IOException e) {
46+
throw new RuntimeException(e);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)