Skip to content

Commit afa77ea

Browse files
committed
---
yaml --- r: 6129 b: refs/heads/tswast-patch-1 c: b0a88f5 h: refs/heads/master i: 6127: 8ec499c
1 parent d66ff16 commit afa77ea

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 1c52730edfb6e169ea9ce8af32713f4879f07590
60+
refs/heads/tswast-patch-1: b0a88f5d512908159d5c7316f363d4a1afb97658
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@
5555
import java.util.zip.ZipEntry;
5656
import java.util.zip.ZipInputStream;
5757

58+
import java.util.logging.Level;
59+
import java.util.logging.Logger;
60+
5861
/**
5962
* Utility to start and stop local Google Cloud Datastore process.
6063
*/
6164
public class LocalGcdHelper {
6265

66+
private static final Logger log = Logger.getLogger(LocalGcdHelper.class.getName());
67+
6368
private final String projectId;
6469
private Path gcdPath;
6570
private ProcessStreamReader processReader;
@@ -99,14 +104,27 @@ private static Path installedGcdPath() {
99104
Path gcloudPath = executablePath(gcloudExecutableName);
100105
gcloudPath = (gcloudPath == null) ? null : gcloudPath.getParent();
101106
if (gcloudPath == null) {
107+
if (log.isLoggable(Level.FINE)) {
108+
log.fine("SDK not found");
109+
}
102110
return null;
103111
}
112+
if (log.isLoggable(Level.FINE)) {
113+
log.fine("SDK found, looking for datastore emulator");
114+
}
104115
Path installedGcdPath = gcloudPath.resolve("platform").resolve("gcd");
105116
if (Files.exists(installedGcdPath)) {
106117
try {
107118
String installedVersion = installedGcdVersion();
108119
if (installedVersion != null && installedVersion.startsWith(GCD_VERSION)) {
120+
if (log.isLoggable(Level.FINE)) {
121+
log.fine("SDK datastore emulator found");
122+
}
109123
return installedGcdPath;
124+
} else {
125+
if (log.isLoggable(Level.FINE)) {
126+
log.fine("SDK datastore emulator found but version mismatch");
127+
}
110128
}
111129
} catch (IOException | InterruptedException ignore) {
112130
// ignore
@@ -308,14 +326,23 @@ private void downloadGcd() throws IOException {
308326
// check if we already have a local copy of the gcd utility and download it if not.
309327
File gcdZipFile = new File(System.getProperty("java.io.tmpdir"), GCD_FILENAME);
310328
if (!gcdZipFile.exists() || !MD5_CHECKSUM.equals(md5(gcdZipFile))) {
329+
if (log.isLoggable(Level.FINE)) {
330+
log.fine("Fetching datastore emulator");
331+
}
311332
ReadableByteChannel rbc = Channels.newChannel(GCD_URL.openStream());
312333
try (FileOutputStream fos = new FileOutputStream(gcdZipFile)) {
313334
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
314335
}
336+
} else {
337+
if (log.isLoggable(Level.FINE)) {
338+
log.fine("Using cached datastore emulator");
339+
}
315340
}
316-
317341
// unzip the gcd
318342
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(gcdZipFile))) {
343+
if (log.isLoggable(Level.FINE)) {
344+
log.fine("Unzipping datastore emulator");
345+
}
319346
ZipEntry entry = zipIn.getNextEntry();
320347
while (entry != null) {
321348
File filePath = new File(gcdPath.toFile(), entry.getName());
@@ -350,6 +377,9 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
350377
}
351378

352379
// create the datastore for the project
380+
if (log.isLoggable(Level.FINE)) {
381+
log.log(Level.FINE, "Creating datastore for the project: {0}", projectId);
382+
}
353383
Process temp = gcdCreateCommand.command(gcdAbsolutePath.toString(), "create", "-p", projectId,
354384
projectId)
355385
.redirectErrorInherit()
@@ -359,6 +389,9 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
359389
temp.waitFor();
360390

361391
// start the datastore for the project
392+
if (log.isLoggable(Level.FINE)) {
393+
log.log(Level.FINE, "Starting datastore emulator for the project: {0}", projectId);
394+
}
362395
temp = gcdStartCommand.command(gcdAbsolutePath.toString(), "start", "--testing",
363396
"--allow_remote_shutdown", projectId)
364397
.directory(gcdPath)

0 commit comments

Comments
 (0)