• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #180

pending completion
#180

push

github-actions

web-flow
Add support for SDK metadata to test server (#1800)

13 of 13 new or added lines in 2 files covered. (100.0%)

18358 of 23713 relevant lines covered (77.42%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.55
/temporal-serviceclient/src/main/java/io/temporal/serviceclient/SystemInfoInterceptor.java
1
/*
2
 * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3
 *
4
 * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
 *
6
 * Modifications copyright (C) 2017 Uber Technologies, Inc.
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this material except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *   http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
package io.temporal.serviceclient;
22

23
import io.grpc.*;
24
import io.temporal.api.workflowservice.v1.GetSystemInfoRequest;
25
import io.temporal.api.workflowservice.v1.GetSystemInfoResponse;
26
import io.temporal.api.workflowservice.v1.WorkflowServiceGrpc;
27
import java.util.concurrent.CompletableFuture;
28
import javax.annotation.Nullable;
29

30
public class SystemInfoInterceptor implements ClientInterceptor {
31

32
  private final CompletableFuture<GetSystemInfoResponse.Capabilities> serverCapabilitiesFuture;
33

34
  public SystemInfoInterceptor(
35
      CompletableFuture<GetSystemInfoResponse.Capabilities> serverCapabilitiesFuture) {
1✔
36
    this.serverCapabilitiesFuture = serverCapabilitiesFuture;
1✔
37
  }
1✔
38

39
  @Override
40
  public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
41
      MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
42
    return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
1✔
43
        next.newCall(method, callOptions)) {
1✔
44

45
      @Override
46
      public void start(Listener<RespT> responseListener, Metadata headers) {
47
        if (!serverCapabilitiesFuture.isDone()) {
1✔
48
          if (method == WorkflowServiceGrpc.getGetSystemInfoMethod()) {
1✔
49
            // It's already a getSystemsInfo call, so we just listen on it and populate the
50
            // capabilities
51
            responseListener =
1✔
52
                new ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT>(
53
                    responseListener) {
1✔
54
                  @Override
55
                  public void onMessage(RespT message) {
56
                    if (message instanceof GetSystemInfoResponse) {
1✔
57
                      GetSystemInfoResponse response = (GetSystemInfoResponse) message;
1✔
58
                      serverCapabilitiesFuture.complete(response.getCapabilities());
1✔
59
                    }
60
                    super.onMessage(message);
1✔
61
                  }
1✔
62

63
                  @Override
64
                  public void onClose(Status status, Metadata trailers) {
65
                    if (Status.UNIMPLEMENTED.getCode().equals(status.getCode())) {
1✔
66
                      serverCapabilitiesFuture.complete(
×
67
                          GetSystemInfoResponse.Capabilities.getDefaultInstance());
×
68
                    }
69
                    super.onClose(status, trailers);
1✔
70
                  }
1✔
71
                };
72
          } else {
73
            // Need to reach system capabilities, so make a getSystemInfo call in a blocking manner.
74
            // We don't try to squash into one and optimize the several getSystemInfo calls that may
75
            // be initiated by several client calls here. Doing so it will require tricky
76
            // implementation to ensure proper deadlines that may be different between calls.
77
            // If a server is able to take the load of the requests, it should be able to serve some
78
            // additional lightweight static getSystemInfo calls that are serialized with the actual
79
            // calls.
80
            serverCapabilitiesFuture.complete(
1✔
81
                getServerCapabilitiesOrThrow(next, callOptions.getDeadline()));
1✔
82
          }
83
        }
84

85
        super.start(responseListener, headers);
1✔
86
      }
1✔
87
    };
88
  }
89

90
  public static GetSystemInfoResponse.Capabilities getServerCapabilitiesOrThrow(
91
      Channel channel, @Nullable Deadline deadline) {
92
    try {
93
      return WorkflowServiceGrpc.newBlockingStub(channel)
1✔
94
          .withDeadline(deadline)
1✔
95
          .getSystemInfo(GetSystemInfoRequest.newBuilder().build())
1✔
96
          .getCapabilities();
1✔
97
    } catch (StatusRuntimeException ex) {
1✔
98
      if (Status.Code.UNIMPLEMENTED.equals(ex.getStatus().getCode())) {
1✔
99
        return GetSystemInfoResponse.Capabilities.getDefaultInstance();
1✔
100
      }
101
      throw ex;
1✔
102
    }
103
  }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc