Skip to content

Commit ee0acab

Browse files
lucasoaressduskis
authored andcommitted
---
yaml --- r: 27567 b: refs/heads/mrschmidt-collectiongroup c: 47884a3 h: refs/heads/master i: 27565: 1f58d5c 27563: 4937ae3 27559: 64a887e 27551: 9ecd0b5
1 parent 402c333 commit ee0acab

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
@@ -173,7 +173,7 @@ refs/heads/autosynth-securitycenter: f2f2feb8f3949c986d37e55cd23cdb0ce774f287
173173
refs/heads/autosynth-talent: 4ca901879f86aab61091cea52e8a9b653639df24
174174
refs/heads/cscc-samples: 620d105e6b574cfeeee04e413a157b7bd34ebc8b
175175
refs/heads/igorbernstein2-patch-1: f62464ee14df1e44a3b173cdc3976563d1b3078b
176-
refs/heads/mrschmidt-collectiongroup: f9ffc7a9a6b1683f3e9b41ff265d58e305576645
176+
refs/heads/mrschmidt-collectiongroup: 47884a3c08d216d4ae7a7a891291af717fb47ef5
177177
refs/heads/release-google-cloud-java-v0.83.0: 4b55ec1b81b3886ede61ae868391a3cdf7eed90e
178178
refs/heads/release-google-cloud-java-v0.83.1-SNAPSHOT: 8d6db7ee534d12b1df38d8cf314871df76f87577
179179
refs/heads/v4support: aa837fd70877f5a0628d8036e88952db035b792c

branches/mrschmidt-collectiongroup/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/mrschmidt-collectiongroup/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)