Skip to content

Commit 3d09d90

Browse files
lucasoaressduskis
authored andcommitted
---
yaml --- r: 30671 b: refs/heads/autosynth-bigquerydatatransfer c: 47884a3 h: refs/heads/master i: 30669: 6e46f2b 30667: 862bdc5 30663: 2394f13 30655: 768abac
1 parent b6c2b06 commit 3d09d90

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
@@ -122,7 +122,7 @@ refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b
122122
refs/tags/v0.69.0: 78f67a29e8b9c46ba01de566a2eae0fd1c03edea
123123
refs/heads/autosynth-asset: bdb45634a0fe8f7a510692b56b31f5312e25f453
124124
refs/heads/autosynth-automl: 22f9dd5b6f5df8dbfa7da0126864d565229519b2
125-
refs/heads/autosynth-bigquerydatatransfer: f9ffc7a9a6b1683f3e9b41ff265d58e305576645
125+
refs/heads/autosynth-bigquerydatatransfer: 47884a3c08d216d4ae7a7a891291af717fb47ef5
126126
refs/heads/autosynth-bigquerystorage: d2c53da3b012e38c662e4df0738042435f19365f
127127
refs/heads/autosynth-bigtable: 9e5429f45cf9face9fed585d0233534993e36b58
128128
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca

branches/autosynth-bigquerydatatransfer/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-bigquerydatatransfer/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)