Skip to content

Commit 51f1a8b

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 6173 b: refs/heads/tswast-patch-1 c: 22a9e99 h: refs/heads/master i: 6171: cd23c67
1 parent cc49f5c commit 51f1a8b

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 1f617b77fd77d09f327b909d2302f2f4efc6e0a5
60+
refs/heads/tswast-patch-1: 22a9e9915c1ba5fae4e1d194bf0b92686d4ba7d4
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class DatastoreOptionsTest {
3535

3636
private static final String PROJECT_ID = "project_id";
37-
private static final int PORT = LocalGcdHelper.findOpenPort();
37+
private static final int PORT = LocalGcdHelper.findAvailablePort(LocalGcdHelper.DEFAULT_PORT);
3838
private DatastoreRpcFactory datastoreRpcFactory;
3939
private DatastoreRpc datastoreRpc;
4040
private DatastoreOptions.Builder options;

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class DatastoreTest {
101101
private Datastore datastore;
102102

103103
private static LocalGcdHelper gcdHelper;
104-
private static final int PORT = LocalGcdHelper.findOpenPort();
104+
private static final int PORT = LocalGcdHelper.findAvailablePort(LocalGcdHelper.DEFAULT_PORT);
105105

106106
@BeforeClass
107107
public static void beforeClass() throws IOException, InterruptedException {

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class LocalGcdHelper {
7272
private final int port;
7373

7474
public static final String DEFAULT_PROJECT_ID = "projectid1";
75-
private static final int DEFAULT_PORT = 8080;
75+
public static final int DEFAULT_PORT = 8080;
7676
private static final String GCD_VERSION = "v1beta2";
7777
private static final String GCD_BUILD = "rev1-2.1.2b";
7878
private static final String GCD_BASENAME = "gcd-" + GCD_VERSION + "-" + GCD_BUILD;
@@ -96,15 +96,12 @@ public class LocalGcdHelper {
9696
}
9797
}
9898

99-
public static int findOpenPort() {
100-
int port;
101-
try (ServerSocket temp_socket = new ServerSocket(0)) {
102-
port = temp_socket.getLocalPort();
103-
temp_socket.close();
99+
public static int findAvailablePort(int defaultPort) {
100+
try (ServerSocket tempSocket = new ServerSocket(0)) {
101+
return tempSocket.getLocalPort();
104102
} catch (IOException e) {
105-
port = DEFAULT_PORT;
103+
return defaultPort;
106104
}
107-
return port;
108105
}
109106

110107
private static Path installedGcdPath() {
@@ -491,8 +488,8 @@ public static void main(String... args) throws IOException, InterruptedException
491488
if (args.length == 1) {
492489
switch (args[0]) {
493490
case "START":
494-
if (!isActive(DEFAULT_PROJECT_ID, DEFAULT_PORT)) {
495-
LocalGcdHelper helper = start(DEFAULT_PROJECT_ID, DEFAULT_PORT);
491+
if (!isActive(DEFAULT_PROJECT_ID, findAvailablePort(DEFAULT_PORT))) {
492+
LocalGcdHelper helper = start(DEFAULT_PROJECT_ID, findAvailablePort(DEFAULT_PORT));
496493
try (FileWriter writer = new FileWriter(".local_gcd_helper")) {
497494
writer.write(helper.gcdPath.toAbsolutePath().toString());
498495
}

0 commit comments

Comments
 (0)