Skip to content

Commit 05293c3

Browse files
lucasoaressduskis
authored andcommitted
---
yaml --- r: 26223 b: refs/heads/pubsub-ordering-keys c: 47884a3 h: refs/heads/master i: 26221: b52ae31 26219: cad6929 26215: 559941a 26207: 6fa229d
1 parent 0f2f78e commit 05293c3

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
@@ -155,7 +155,7 @@ refs/tags/v0.72.0: a7703f2593ba312c0b2dde6fdfd4f5c764bb55ac
155155
refs/tags/v0.73.0: 21241ea8be9439cc5764c4944cdce21d34ce4f9e
156156
refs/tags/v0.74.0: 9d1f733dbbf790de7b494418523b69c4a9a57638
157157
refs/heads/ignoretest: 23c412ae07af3d0ab1caa2d44d5bc5c0ccb8b31d
158-
refs/heads/pubsub-ordering-keys: f9ffc7a9a6b1683f3e9b41ff265d58e305576645
158+
refs/heads/pubsub-ordering-keys: 47884a3c08d216d4ae7a7a891291af717fb47ef5
159159
"refs/heads/update_mvn_badge": ae2d773814db0f71197ccf5a8612ee1d8056f8de
160160
refs/tags/v0.75.0: c3673089ae09a897c1b4cf7dfe167fe4f8ab32fb
161161
refs/tags/v0.76.0: 395b016826d3ddf9cb8b34919636df15a4dbd032

branches/pubsub-ordering-keys/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/pubsub-ordering-keys/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)