Skip to content

Commit 7fe981d

Browse files
author
Ajay Kannan
committed
Minor changes
1 parent 561b04f commit 7fe981d

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalDatastoreHelper.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.common.base.Strings;
2323
import com.google.gcloud.AuthCredentials;
24+
import com.google.gcloud.RetryParams;
2425
import com.google.gcloud.datastore.DatastoreOptions;
2526

2627
import java.io.BufferedInputStream;
@@ -75,7 +76,7 @@ public class LocalDatastoreHelper {
7576
private static final String GCLOUD = "gcloud";
7677
private static final Path INSTALLED_GCD_PATH;
7778
private static final String GCD_VERSION_PREFIX = "gcd-emulator ";
78-
private static final String PROJECT_ID_PREFIX = "test-id-";
79+
private static final String PROJECT_ID_PREFIX = "test-project-";
7980

8081
private final String projectId;
8182
private Path gcdPath;
@@ -541,6 +542,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
541542
}
542543

543544
private LocalDatastoreHelper(double consistency) {
545+
checkArgument(consistency >= 0.0 && consistency <= 1.0, "Consistency must be between 0 and 1");
544546
projectId = PROJECT_ID_PREFIX + UUID.randomUUID().toString();
545547
this.consistency = consistency;
546548
this.port = findAvailablePort();
@@ -563,6 +565,7 @@ public DatastoreOptions options() {
563565
.projectId(projectId)
564566
.host("localhost:" + Integer.toString(port))
565567
.authCredentials(AuthCredentials.noAuth())
568+
.retryParams(RetryParams.noRetries())
566569
.build();
567570
}
568571

@@ -573,13 +576,6 @@ public String projectId() {
573576
return projectId;
574577
}
575578

576-
/**
577-
* Returns the port on localhost to which the local Datastore listens for requests.
578-
*/
579-
public int port() {
580-
return port;
581-
}
582-
583579
/**
584580
* Returns the consistency setting for the local Datastore emulator.
585581
*/
@@ -621,7 +617,6 @@ public static LocalDatastoreHelper create() {
621617
*/
622618
public void start() throws IOException, InterruptedException {
623619
// send a quick request in case we have a hanging process from a previous run
624-
checkArgument(consistency >= 0.0 && consistency <= 1.0, "Consistency must be between 0 and 1");
625620
sendQuitRequest(port);
626621
// Each run is associated with its own folder that is deleted once test completes.
627622
gcdPath = Files.createTempDirectory("gcd");

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
public class DatastoreTest {
6969

7070
private static LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0);
71-
private static final DatastoreOptions options =
72-
helper.options().toBuilder().retryParams(RetryParams.noRetries()).build();
71+
private static final DatastoreOptions options = helper.options();
7372
private static final Datastore datastore = options.service();
7473
private static final String PROJECT_ID = options.projectId();
7574
private static final String KIND1 = "kind1";
@@ -151,9 +150,7 @@ public void setUp() {
151150

152151
@AfterClass
153152
public static void afterClass() throws IOException, InterruptedException {
154-
if (helper != null) {
155-
helper.stop();
156-
}
153+
helper.stop();
157154
}
158155

159156
@Test

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalDatastoreHelperTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.gcloud.datastore;
1818

19-
import static org.junit.Assert.assertEquals;
2019
import static org.junit.Assert.assertSame;
2120
import static org.junit.Assert.assertTrue;
2221

@@ -31,7 +30,7 @@
3130
public class LocalDatastoreHelperTest {
3231

3332
private static final double TOLERANCE = 0.00001;
34-
private static final String PROJECT_ID_PREFIX = "test-id-";
33+
private static final String PROJECT_ID_PREFIX = "test-project-";
3534

3635
@Test
3736
public void testCreate() {
@@ -48,7 +47,7 @@ public void testOptions() {
4847
LocalDatastoreHelper helper = LocalDatastoreHelper.create();
4948
DatastoreOptions options = helper.options();
5049
assertTrue(options.projectId().startsWith(PROJECT_ID_PREFIX));
51-
assertEquals("localhost:" + helper.port(), options.host());
50+
assertTrue(options.host().startsWith("localhost:"));
5251
assertSame(AuthCredentials.noAuth(), options.authCredentials());
5352
}
5453
}

0 commit comments

Comments
 (0)