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

temporalio / sdk-java / #188

25 Sep 2023 04:42PM UTC coverage: 77.369% (-0.3%) from 77.663%
#188

push

github-actions

web-flow
Fix null pointer on trigger immediately (#1865)

4 of 4 new or added lines in 1 file covered. (100.0%)

18670 of 24131 relevant lines covered (77.37%)

0.77 hits per line

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

94.44
/temporal-sdk/src/main/java/io/temporal/internal/sync/QueryDispatcher.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.internal.sync;
22

23
import io.temporal.api.common.v1.Payloads;
24
import io.temporal.common.converter.DataConverter;
25
import io.temporal.common.converter.EncodedValues;
26
import io.temporal.common.interceptors.Header;
27
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
28
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
29
import io.temporal.workflow.DynamicQueryHandler;
30
import java.util.HashMap;
31
import java.util.Map;
32
import java.util.Optional;
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

36
class QueryDispatcher {
37
  private static final Logger log = LoggerFactory.getLogger(QueryDispatcher.class);
1✔
38

39
  private final DataConverter dataConverterWithWorkflowContext;
40
  private final Map<String, WorkflowOutboundCallsInterceptor.RegisterQueryInput> queryCallbacks =
1✔
41
      new HashMap<>();
42

43
  private DynamicQueryHandler dynamicQueryHandler;
44
  private WorkflowInboundCallsInterceptor inboundCallsInterceptor;
45

46
  public QueryDispatcher(DataConverter dataConverterWithWorkflowContext) {
1✔
47
    this.dataConverterWithWorkflowContext = dataConverterWithWorkflowContext;
1✔
48
  }
1✔
49

50
  public void setInboundCallsInterceptor(WorkflowInboundCallsInterceptor inboundCallsInterceptor) {
51
    this.inboundCallsInterceptor = inboundCallsInterceptor;
1✔
52
  }
1✔
53

54
  /** Called from the interceptor tail */
55
  public WorkflowInboundCallsInterceptor.QueryOutput handleInterceptedQuery(
56
      WorkflowInboundCallsInterceptor.QueryInput input) {
57
    String queryName = input.getQueryName();
1✔
58
    Object[] args = input.getArguments();
1✔
59
    WorkflowOutboundCallsInterceptor.RegisterQueryInput handler = queryCallbacks.get(queryName);
1✔
60
    Object result;
61
    if (handler == null) {
1✔
62
      if (dynamicQueryHandler != null) {
1✔
63
        result = dynamicQueryHandler.handle(queryName, (EncodedValues) args[0]);
1✔
64
      } else {
65
        throw new IllegalStateException("Unknown query type: " + queryName);
×
66
      }
67
    } else {
68
      result = handler.getCallback().apply(args);
1✔
69
    }
70
    return new WorkflowInboundCallsInterceptor.QueryOutput(result);
1✔
71
  }
72

73
  public Optional<Payloads> handleQuery(String queryName, Header header, Optional<Payloads> input) {
74
    WorkflowOutboundCallsInterceptor.RegisterQueryInput handler = queryCallbacks.get(queryName);
1✔
75
    Object[] args;
76
    if (handler == null) {
1✔
77
      if (dynamicQueryHandler == null) {
1✔
78
        throw new IllegalArgumentException(
1✔
79
            "Unknown query type: " + queryName + ", knownTypes=" + queryCallbacks.keySet());
1✔
80
      }
81
      args = new Object[] {new EncodedValues(input, dataConverterWithWorkflowContext)};
1✔
82
    } else {
83
      args =
1✔
84
          dataConverterWithWorkflowContext.fromPayloads(
1✔
85
              input, handler.getArgTypes(), handler.getGenericArgTypes());
1✔
86
    }
87
    Object result =
1✔
88
        inboundCallsInterceptor
89
            .handleQuery(new WorkflowInboundCallsInterceptor.QueryInput(queryName, header, args))
1✔
90
            .getResult();
1✔
91
    return dataConverterWithWorkflowContext.toPayloads(result);
1✔
92
  }
93

94
  public void registerQueryHandlers(WorkflowOutboundCallsInterceptor.RegisterQueryInput request) {
95
    String queryType = request.getQueryType();
1✔
96
    if (queryCallbacks.containsKey(queryType)) {
1✔
97
      throw new IllegalStateException("Query \"" + queryType + "\" is already registered");
×
98
    }
99
    queryCallbacks.put(queryType, request);
1✔
100
  }
1✔
101

102
  public void registerDynamicQueryHandler(
103
      WorkflowOutboundCallsInterceptor.RegisterDynamicQueryHandlerInput input) {
104
    dynamicQueryHandler = input.getHandler();
1✔
105
  }
1✔
106
}
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