File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed
main/java/com/github/tadayosi/tensorflow/serving/client
test/java/com/github/tadayosi/tensorflow/serving/client Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 11package com .github .tadayosi .tensorflow .serving .client ;
22
3+ import java .io .Closeable ;
34import java .util .Optional ;
45
56import io .grpc .ChannelCredentials ;
1415import tensorflow .serving .PredictionServiceGrpc ;
1516import 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 );
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11package com .github .tadayosi .tensorflow .serving .client ;
22
3+ import org .junit .jupiter .api .AfterEach ;
34import org .junit .jupiter .api .BeforeEach ;
45import org .testcontainers .containers .GenericContainer ;
56import 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}
You can’t perform that action at this time.
0 commit comments