Skip to content

Commit f412083

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 3593 b: refs/heads/pubsub-alpha c: c2f8952 h: refs/heads/master i: 3591: 93f602c
1 parent f77e3d3 commit f412083

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 36a62ef856d199f8efd09501b5ba65c422c01f23
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 7406918e071dd2c5677a638ae2a06e7592b6542c
5-
refs/heads/pubsub-alpha: 65f4f8063273b65b258aaf2be73e0609afb9583a
5+
refs/heads/pubsub-alpha: c2f8952befa41581dcad9a9bd8951837d9c7d39f
66
refs/heads/update-datastore: 47aae517c2cb33f1dccd909adaced73ec9d0f4df
77
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
88
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd

branches/pubsub-alpha/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.gcloud.datastore.testing;
1818

1919
import static com.google.common.base.MoreObjects.firstNonNull;
20+
import static com.google.common.base.Preconditions.checkArgument;
2021
import static java.nio.charset.StandardCharsets.UTF_8;
2122

2223
import com.google.common.base.Strings;
@@ -85,6 +86,7 @@ public class LocalGcdHelper {
8586
private static final String GCLOUD = "gcloud";
8687
private static final Path INSTALLED_GCD_PATH;
8788
private static final String GCD_VERSION_PREFIX = "gcd-emulator ";
89+
private static final double DEFAULT_CONSISTENCY = 0.9;
8890

8991
static {
9092
INSTALLED_GCD_PATH = installedGcdPath();
@@ -398,9 +400,15 @@ public LocalGcdHelper(String projectId, int port) {
398400
* All content is written to a temporary directory that will be deleted when
399401
* {@link #stop()} is called or when the program terminates) to make sure that no left-over
400402
* data from prior runs is used.
403+
*
404+
* @param consistency the fraction of job application attempts that will succeed, with 0.0
405+
* resulting in no attempts succeeding, and 1.0 resulting in all attempts succeeding. Defaults
406+
* to 0.9. Note that setting this to 1.0 may mask incorrect assumptions about the consistency
407+
* of non-ancestor queries; non-ancestor queries are eventually consistent.
401408
*/
402-
public void start() throws IOException, InterruptedException {
409+
public void start(double consistency) throws IOException, InterruptedException {
403410
// send a quick request in case we have a hanging process from a previous run
411+
checkArgument(consistency >= 0.0 && consistency <= 1.0, "Consistency must be between 0 and 1");
404412
sendQuitRequest(port);
405413
// Each run is associated with its own folder that is deleted once test completes.
406414
gcdPath = Files.createTempDirectory("gcd");
@@ -415,7 +423,7 @@ public void start() throws IOException, InterruptedException {
415423
} else {
416424
gcdExecutablePath = INSTALLED_GCD_PATH;
417425
}
418-
startGcd(gcdExecutablePath);
426+
startGcd(gcdExecutablePath, consistency);
419427
}
420428

421429
private void downloadGcd() throws IOException {
@@ -453,7 +461,8 @@ private void downloadGcd() throws IOException {
453461
}
454462
}
455463

456-
private void startGcd(Path executablePath) throws IOException, InterruptedException {
464+
private void startGcd(Path executablePath, double consistency)
465+
throws IOException, InterruptedException {
457466
// cleanup any possible data for the same project
458467
File datasetFolder = new File(gcdPath.toFile(), projectId);
459468
deleteRecurse(datasetFolder.toPath());
@@ -486,7 +495,8 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
486495
startProcess =
487496
CommandWrapper.create()
488497
.command(gcdAbsolutePath.toString(), "start", "--testing", "--allow_remote_shutdown",
489-
"--port=" + Integer.toString(port), projectId)
498+
"--port=" + Integer.toString(port), "--consistency=" + Double.toString(consistency),
499+
projectId)
490500
.directory(gcdPath)
491501
.start();
492502
processReader = ProcessStreamReader.start(startProcess.getInputStream());
@@ -578,10 +588,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
578588
});
579589
}
580590

581-
public static LocalGcdHelper start(String projectId, int port)
591+
public static LocalGcdHelper start(String projectId, int port, double consistency)
582592
throws IOException, InterruptedException {
583593
LocalGcdHelper helper = new LocalGcdHelper(projectId, port);
584-
helper.start();
594+
helper.start(consistency);
585595
return helper;
586596
}
587597

@@ -590,10 +600,13 @@ public static void main(String... args) throws IOException, InterruptedException
590600
String action = parsedArgs.get("action");
591601
int port =
592602
(parsedArgs.get("port") == null) ? DEFAULT_PORT : Integer.parseInt(parsedArgs.get("port"));
603+
double consistency =
604+
parsedArgs.get("consistency") == null
605+
? DEFAULT_CONSISTENCY : Double.parseDouble(parsedArgs.get("consistency"));
593606
switch (action) {
594607
case "START":
595608
if (!isActive(DEFAULT_PROJECT_ID, port)) {
596-
LocalGcdHelper helper = start(DEFAULT_PROJECT_ID, port);
609+
LocalGcdHelper helper = start(DEFAULT_PROJECT_ID, port, consistency);
597610
try (FileWriter writer = new FileWriter(".local_gcd_helper")) {
598611
writer.write(helper.gcdPath.toAbsolutePath().toString() + System.lineSeparator());
599612
writer.write(Integer.toString(port));

branches/pubsub-alpha/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class DatastoreTest {
118118
@BeforeClass
119119
public static void beforeClass() throws IOException, InterruptedException {
120120
if (!LocalGcdHelper.isActive(PROJECT_ID, PORT)) {
121-
gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT);
121+
gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT, 1.0);
122122
}
123123
}
124124

branches/pubsub-alpha/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testFindAvailablePort() {
4949

5050
@Test
5151
public void testSendQuitRequest() throws IOException, InterruptedException {
52-
LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT);
52+
LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT, 0.75);
5353
assertTrue(LocalGcdHelper.sendQuitRequest(PORT));
5454
long timeoutMillis = 30000;
5555
long startTime = System.currentTimeMillis();
@@ -64,7 +64,7 @@ public void testSendQuitRequest() throws IOException, InterruptedException {
6464

6565
@Test
6666
public void testStartStop() throws IOException, InterruptedException {
67-
LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT);
67+
LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT, 0.75);
6868
assertFalse(LocalGcdHelper.isActive("wrong-project-id", PORT));
6969
assertTrue(LocalGcdHelper.isActive(PROJECT_ID, PORT));
7070
gcdHelper.stop();

0 commit comments

Comments
 (0)