Skip to content

Commit 60ee45d

Browse files
committed
pinging emulator after each test for debugging
1 parent acfbaef commit 60ee45d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import com.google.cloud.testing.BaseEmulatorHelper;
2626
import com.google.common.collect.ImmutableList;
2727
import java.io.IOException;
28+
import java.io.InputStream;
29+
import java.io.InputStreamReader;
30+
import java.io.OutputStream;
31+
import java.net.HttpURLConnection;
2832
import java.net.MalformedURLException;
2933
import java.net.URL;
3034
import java.nio.file.FileVisitResult;
@@ -38,6 +42,8 @@
3842
import java.util.UUID;
3943
import java.util.concurrent.TimeoutException;
4044
import java.util.logging.Logger;
45+
46+
import com.google.common.io.CharStreams;
4147
import org.threeten.bp.Duration;
4248

4349
/**
@@ -95,6 +101,24 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
95101
.setCredentials(NoCredentials.getInstance())
96102
.setRetrySettings(ServiceOptions.getNoRetrySettings());
97103

104+
String sendGetRequest(String request) throws IOException {
105+
URL url = new URL("http", DEFAULT_HOST, this.getPort(), request);
106+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
107+
con.setRequestMethod("GET");
108+
109+
InputStream in = con.getInputStream();
110+
String response = CharStreams.toString(new InputStreamReader(con.getInputStream()));
111+
in.close();
112+
return response;
113+
}
114+
public String checkHealth() {
115+
try {
116+
return sendGetRequest("/");
117+
} catch (IOException e) {
118+
throw new RuntimeException(e);
119+
}
120+
}
121+
98122
/** A builder for {@code LocalDatastoreHelper} objects. */
99123
public static class Builder {
100124
private double consistency;

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

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public static void beforeClass() throws IOException, InterruptedException {
175175

176176
@Before
177177
public void setUp() {
178+
System.out.println(helper.checkHealth());;
178179
rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
179180
rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
180181
rpcMockOptions =

0 commit comments

Comments
 (0)