Skip to content

Commit 94dae17

Browse files
lucasoaressduskis
authored andcommitted
---
yaml --- r: 27627 b: refs/heads/autosynth-datalabeling c: 47884a3 h: refs/heads/master i: 27625: 77b878e 27623: dbb7150
1 parent 716a6b3 commit 94dae17

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ refs/heads/v4support: aa837fd70877f5a0628d8036e88952db035b792c
180180
refs/tags/v0.82.0: 7b9807d5d0a400c757b8905fee768be4c85eba25
181181
refs/tags/v0.83.0: 370ec5a1131a86b36db8efce4f1a943607de8a60
182182
refs/tags/v0.84.0: 71e85198495a39f4524afa2669434b5075c17c3d
183-
refs/heads/autosynth-datalabeling: f9ffc7a9a6b1683f3e9b41ff265d58e305576645
183+
refs/heads/autosynth-datalabeling: 47884a3c08d216d4ae7a7a891291af717fb47ef5
184184
refs/heads/autosynth-webrisk: e006df2927fba3a0af121e0afd18f73da01a8214
185185
"refs/heads/cscc_examples": 2813feef0c9a80293739b67fd53a4b4a2f856b24
186186
refs/heads/marktaskga: 9b161cd985cf38ee44a5e2ab6c53fc00e50a9184

branches/autosynth-datalabeling/google-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper<DatastoreOptions> {
7878
}
7979
}
8080

81-
private LocalDatastoreHelper(double consistency) {
81+
private LocalDatastoreHelper(double consistency, int port) {
8282
super(
8383
"datastore",
84-
BaseEmulatorHelper.findAvailablePort(DEFAULT_PORT),
84+
port > 0 ? port : BaseEmulatorHelper.findAvailablePort(DEFAULT_PORT),
8585
PROJECT_ID_PREFIX + UUID.randomUUID().toString());
8686
Path tmpDirectory = null;
8787
try {
@@ -162,7 +162,32 @@ public double getConsistency() {
162162
* consistency of non-ancestor queries; non-ancestor queries are eventually consistent.
163163
*/
164164
public static LocalDatastoreHelper create(double consistency) {
165-
return new LocalDatastoreHelper(consistency);
165+
return create(consistency, 0);
166+
}
167+
168+
/**
169+
* Creates a local Datastore helper with the specified settings for project ID and consistency.
170+
*
171+
* @param consistency the fraction of Datastore writes that are immediately visible to global
172+
* queries, with 0.0 meaning no writes are immediately visible and 1.0 meaning all writes are
173+
* immediately visible. Note that setting this to 1.0 may mask incorrect assumptions about the
174+
* consistency of non-ancestor queries; non-ancestor queries are eventually consistent.
175+
* @param port the port to be used to start the emulator service. Note that setting this to 0 the
176+
* emulator will search for a free random port.
177+
*/
178+
public static LocalDatastoreHelper create(double consistency, int port) {
179+
return new LocalDatastoreHelper(consistency, port);
180+
}
181+
182+
/**
183+
* Creates a local Datastore helper with a placeholder project ID and the default consistency
184+
* setting of 0.9.
185+
*
186+
* @param port the port to be used to start the emulator service. Note that setting this to 0 the
187+
* emulator will search for a free random port.
188+
*/
189+
public static LocalDatastoreHelper create(int port) {
190+
return new LocalDatastoreHelper(DEFAULT_CONSISTENCY, port);
166191
}
167192

168193
/**

branches/autosynth-datalabeling/google-cloud-clients/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/LocalDatastoreHelperTest.java

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

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertNull;
2223
import static org.junit.Assert.assertSame;
@@ -56,6 +57,23 @@ public void testCreate() {
5657
assertTrue(helper.getProjectId().startsWith(PROJECT_ID_PREFIX));
5758
}
5859

60+
@Test
61+
public void testCreatePort() {
62+
LocalDatastoreHelper helper = LocalDatastoreHelper.create(0.75, 8888);
63+
DatastoreOptions options = helper.getOptions(NAMESPACE);
64+
assertTrue(options.getHost().endsWith("8888"));
65+
assertTrue(Math.abs(0.75 - helper.getConsistency()) < TOLERANCE);
66+
helper = LocalDatastoreHelper.create();
67+
options = helper.getOptions(NAMESPACE);
68+
assertTrue(Math.abs(0.9 - helper.getConsistency()) < TOLERANCE);
69+
assertFalse(options.getHost().endsWith("8888"));
70+
assertFalse(options.getHost().endsWith("8080"));
71+
helper = LocalDatastoreHelper.create(9999);
72+
options = helper.getOptions(NAMESPACE);
73+
assertTrue(Math.abs(0.9 - helper.getConsistency()) < TOLERANCE);
74+
assertTrue(options.getHost().endsWith("9999"));
75+
}
76+
5977
@Test
6078
public void testOptions() {
6179
LocalDatastoreHelper helper = LocalDatastoreHelper.create();

0 commit comments

Comments
 (0)