|
25 | 25 | import com.google.cloud.testing.BaseEmulatorHelper;
|
26 | 26 | import com.google.common.collect.ImmutableList;
|
27 | 27 | import java.io.IOException;
|
| 28 | +import java.io.InputStream; |
| 29 | +import java.io.InputStreamReader; |
| 30 | +import java.io.OutputStream; |
| 31 | +import java.net.HttpURLConnection; |
28 | 32 | import java.net.MalformedURLException;
|
29 | 33 | import java.net.URL;
|
30 | 34 | import java.nio.file.FileVisitResult;
|
|
38 | 42 | import java.util.UUID;
|
39 | 43 | import java.util.concurrent.TimeoutException;
|
40 | 44 | import java.util.logging.Logger;
|
| 45 | + |
| 46 | +import com.google.common.io.CharStreams; |
41 | 47 | import org.threeten.bp.Duration;
|
42 | 48 |
|
43 | 49 | /**
|
@@ -95,6 +101,24 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
|
95 | 101 | .setCredentials(NoCredentials.getInstance())
|
96 | 102 | .setRetrySettings(ServiceOptions.getNoRetrySettings());
|
97 | 103 |
|
| 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 | + |
98 | 122 | /** A builder for {@code LocalDatastoreHelper} objects. */
|
99 | 123 | public static class Builder {
|
100 | 124 | private double consistency;
|
|
0 commit comments