Skip to content

Commit 93109f1

Browse files
committed
fix: make the client closeable
1 parent 5a2f090 commit 93109f1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/main/java/com/github/tadayosi/tensorflow/serving/client/TensorFlowServingClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.tadayosi.tensorflow.serving.client;
22

3+
import java.io.Closeable;
34
import java.util.Optional;
45

56
import io.grpc.ChannelCredentials;
@@ -14,15 +15,16 @@
1415
import tensorflow.serving.PredictionServiceGrpc;
1516
import tensorflow.serving.RegressionOuterClass;
1617

17-
public class TensorFlowServingClient implements TensorFlowServingApi {
18+
public class TensorFlowServingClient implements TensorFlowServingApi, Closeable {
1819

1920
private static final String DEFAULT_TARGET = "localhost:8500";
2021

22+
private final ManagedChannel channel;
2123
private final ModelServiceGrpc.ModelServiceBlockingStub modelService;
2224
private final PredictionServiceGrpc.PredictionServiceBlockingStub predictionService;
2325

2426
private TensorFlowServingClient(String target, ChannelCredentials credentials) {
25-
ManagedChannel channel = Grpc.newChannelBuilder(target, credentials).build();
27+
this.channel = Grpc.newChannelBuilder(target, credentials).build();
2628
this.modelService = ModelServiceGrpc.newBlockingStub(channel);
2729
this.predictionService = PredictionServiceGrpc.newBlockingStub(channel);
2830
}
@@ -35,6 +37,11 @@ public static Builder builder() {
3537
return new Builder();
3638
}
3739

40+
@Override
41+
public void close() {
42+
channel.shutdown();
43+
}
44+
3845
@Override
3946
public GetModelStatus.GetModelStatusResponse getModelStatus(GetModelStatus.GetModelStatusRequest request) {
4047
return modelService.getModelStatus(request);

src/test/java/com/github/tadayosi/tensorflow/serving/client/ConfigurationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ void testLoad() {
2424
@SuppressWarnings("OptionalGetWithoutIsPresent")
2525
void testSystemProperties() {
2626
System.setProperty("tfsc4j.target", "dns:///test.com:8501");
27-
System.setProperty("tfsc4j.credentials", "aaaaa");
2827

2928
var config = Configuration.load();
3029

3130
assertEquals("dns:///test.com:8501", config.getTarget().get());
32-
assertEquals("aaaaa", config.getCredentials().get());
3331
}
3432
}

src/test/java/com/github/tadayosi/tensorflow/serving/client/TensorFlowServingTestSupport.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.tadayosi.tensorflow.serving.client;
22

3+
import org.junit.jupiter.api.AfterEach;
34
import org.junit.jupiter.api.BeforeEach;
45
import org.testcontainers.containers.GenericContainer;
56
import org.testcontainers.containers.wait.strategy.Wait;
@@ -29,4 +30,9 @@ void setUp() {
2930
.target("localhost:" + tensorflowServing.getMappedPort(8500))
3031
.build();
3132
}
33+
34+
@AfterEach
35+
void tearDown() {
36+
client.close();
37+
}
3238
}

0 commit comments

Comments
 (0)