Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Apr 8, 2016
1 parent 561b04f commit 7fe981d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.base.Strings;
import com.google.gcloud.AuthCredentials;
import com.google.gcloud.RetryParams;
import com.google.gcloud.datastore.DatastoreOptions;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -75,7 +76,7 @@ public class LocalDatastoreHelper {
private static final String GCLOUD = "gcloud";
private static final Path INSTALLED_GCD_PATH;
private static final String GCD_VERSION_PREFIX = "gcd-emulator ";
private static final String PROJECT_ID_PREFIX = "test-id-";
private static final String PROJECT_ID_PREFIX = "test-project-";

private final String projectId;
private Path gcdPath;
Expand Down Expand Up @@ -541,6 +542,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
}

private LocalDatastoreHelper(double consistency) {
checkArgument(consistency >= 0.0 && consistency <= 1.0, "Consistency must be between 0 and 1");
projectId = PROJECT_ID_PREFIX + UUID.randomUUID().toString();
this.consistency = consistency;
this.port = findAvailablePort();
Expand All @@ -563,6 +565,7 @@ public DatastoreOptions options() {
.projectId(projectId)
.host("localhost:" + Integer.toString(port))
.authCredentials(AuthCredentials.noAuth())
.retryParams(RetryParams.noRetries())
.build();
}

Expand All @@ -573,13 +576,6 @@ public String projectId() {
return projectId;
}

/**
* Returns the port on localhost to which the local Datastore listens for requests.
*/
public int port() {
return port;
}

/**
* Returns the consistency setting for the local Datastore emulator.
*/
Expand Down Expand Up @@ -621,7 +617,6 @@ public static LocalDatastoreHelper create() {
*/
public void start() throws IOException, InterruptedException {
// send a quick request in case we have a hanging process from a previous run
checkArgument(consistency >= 0.0 && consistency <= 1.0, "Consistency must be between 0 and 1");
sendQuitRequest(port);
// Each run is associated with its own folder that is deleted once test completes.
gcdPath = Files.createTempDirectory("gcd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
public class DatastoreTest {

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

@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (helper != null) {
helper.stop();
}
helper.stop();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.gcloud.datastore;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

Expand All @@ -31,7 +30,7 @@
public class LocalDatastoreHelperTest {

private static final double TOLERANCE = 0.00001;
private static final String PROJECT_ID_PREFIX = "test-id-";
private static final String PROJECT_ID_PREFIX = "test-project-";

@Test
public void testCreate() {
Expand All @@ -48,7 +47,7 @@ public void testOptions() {
LocalDatastoreHelper helper = LocalDatastoreHelper.create();
DatastoreOptions options = helper.options();
assertTrue(options.projectId().startsWith(PROJECT_ID_PREFIX));
assertEquals("localhost:" + helper.port(), options.host());
assertTrue(options.host().startsWith("localhost:"));
assertSame(AuthCredentials.noAuth(), options.authCredentials());
}
}

0 comments on commit 7fe981d

Please sign in to comment.