This is an automated email from the ASF dual-hosted git repository.
mxm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new a8f4e22 [BEAM-7170] Fix exception when retrieving ExpansionServer
port after closing
new 7e1de51 Merge pull request #8424: [BEAM-7170] Fix exception when
retrieving ExpansionServer port after closing
a8f4e22 is described below
commit a8f4e221cd240138df20edb1b58f69e9c37aced1
Author: Maximilian Michels <[email protected]>
AuthorDate: Mon Apr 29 12:36:37 2019 +0200
[BEAM-7170] Fix exception when retrieving ExpansionServer port after closing
The ExpansionServer can throw the following exception after shutdown
because the
port getter retrieves the port dynamically from the underlying service:
```
java.lang.IllegalStateException: Already terminated
at
org.apache.beam.vendor.grpc.v1p13p1.com.google.common.base.Preconditions.checkState(Preconditions.java:444)
at
org.apache.beam.vendor.grpc.v1p13p1.io.grpc.internal.ServerImpl.getPort(ServerImpl.java:174)
at
org.apache.beam.runners.core.construction.expansion.ExpansionServer.getPort(ExpansionServer.java:66)
```
---
.../construction/expansion/ExpansionServer.java | 9 ++--
.../expansion/ExpansionServerTest.java | 48 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 6 deletions(-)
diff --git
a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/expansion/ExpansionServer.java
b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/expansion/ExpansionServer.java
index d152e76..b8ec70c 100644
---
a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/expansion/ExpansionServer.java
+++
b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/expansion/ExpansionServer.java
@@ -38,6 +38,7 @@ public class ExpansionServer implements AutoCloseable {
}
private final String host;
+ private final int port;
private final Server server;
private final ExpansionService service;
@@ -49,11 +50,7 @@ public class ExpansionServer implements AutoCloseable {
.addService(service)
.build()
.start();
- }
-
- /** Get the ExpansionService exposed by this {@link ExpansionServer}. */
- public ExpansionService getService() {
- return service;
+ this.port = server.getPort();
}
/** Get the host that this {@link ExpansionServer} is bound to. */
@@ -63,7 +60,7 @@ public class ExpansionServer implements AutoCloseable {
/** Get the port that this {@link ExpansionServer} is bound to. */
public int getPort() {
- return server.getPort();
+ return port;
}
@Override
diff --git
a/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/expansion/ExpansionServerTest.java
b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/expansion/ExpansionServerTest.java
new file mode 100644
index 0000000..29370d9
--- /dev/null
+++
b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/expansion/ExpansionServerTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.core.construction.expansion;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.core.Is.is;
+
+import org.junit.Test;
+
+/** Tests for {@link ExpansionServer}. */
+public class ExpansionServerTest {
+
+ @Test
+ public void testStartupOnFreePort() throws Exception {
+ try (ExpansionServer expansionServer =
+ ExpansionServer.create(new ExpansionService(), "localhost", 0)) {
+ assertThat(expansionServer.getHost(), is("localhost"));
+ assertThat(expansionServer.getPort(), greaterThan(0));
+ }
+ }
+
+ @Test
+ public void testHostPortAvailableAfterClose() throws Exception {
+ ExpansionServer expansionServer;
+ try (ExpansionServer expServer =
+ ExpansionServer.create(new ExpansionService(), "localhost", 0)) {
+ expansionServer = expServer;
+ }
+ assertThat(expansionServer.getHost(), is("localhost"));
+ assertThat(expansionServer.getPort(), greaterThan(0));
+ }
+}