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

temporalio / sdk-java / #333

16 Oct 2024 07:28PM UTC coverage: 78.65% (+0.6%) from 78.085%
#333

push

github

web-flow
Fix code coverage (#2275)

22670 of 28824 relevant lines covered (78.65%)

0.79 hits per line

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

93.48
/temporal-sdk/src/main/java/io/temporal/internal/common/InternalUtils.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.common;
22

23
import com.google.common.base.Defaults;
24
import io.temporal.api.common.v1.Callback;
25
import io.temporal.api.enums.v1.TaskQueueKind;
26
import io.temporal.api.taskqueue.v1.TaskQueue;
27
import io.temporal.client.WorkflowOptions;
28
import io.temporal.client.WorkflowStub;
29
import io.temporal.internal.client.NexusStartWorkflowRequest;
30
import java.util.Arrays;
31
import java.util.stream.Collectors;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

35
/** Utility functions shared by the implementation code. */
36
public final class InternalUtils {
37
  private static final Logger log = LoggerFactory.getLogger(InternalUtils.class);
1✔
38

39
  public static TaskQueue createStickyTaskQueue(
40
      String stickyTaskQueueName, String normalTaskQueueName) {
41
    return TaskQueue.newBuilder()
1✔
42
        .setName(stickyTaskQueueName)
1✔
43
        .setKind(TaskQueueKind.TASK_QUEUE_KIND_STICKY)
1✔
44
        .setNormalName(normalTaskQueueName)
1✔
45
        .build();
1✔
46
  }
47

48
  public static TaskQueue createNormalTaskQueue(String taskQueueName) {
49
    return TaskQueue.newBuilder()
1✔
50
        .setName(taskQueueName)
1✔
51
        .setKind(TaskQueueKind.TASK_QUEUE_KIND_NORMAL)
1✔
52
        .build();
1✔
53
  }
54

55
  public static Object getValueOrDefault(Object value, Class<?> valueClass) {
56
    if (value != null) {
1✔
57
      return value;
1✔
58
    }
59
    return Defaults.defaultValue(valueClass);
1✔
60
  }
61

62
  /**
63
   * Creates a new stub that is bound to the same workflow as the given stub, but with the Nexus
64
   * callback URL and headers set.
65
   *
66
   * @param stub the stub to create a new stub from
67
   * @param request the request containing the Nexus callback URL and headers
68
   * @return a new stub bound to the same workflow as the given stub, but with the Nexus callback
69
   *     URL and headers set
70
   */
71
  public static WorkflowStub createNexusBoundStub(
72
      WorkflowStub stub, NexusStartWorkflowRequest request) {
73
    if (!stub.getOptions().isPresent()) {
1✔
74
      throw new IllegalArgumentException("Options are expected to be set on the stub");
×
75
    }
76
    WorkflowOptions options = stub.getOptions().get();
1✔
77
    WorkflowOptions.Builder nexusWorkflowOptions =
78
        WorkflowOptions.newBuilder()
1✔
79
            .setRequestId(request.getRequestId())
1✔
80
            .setCompletionCallbacks(
1✔
81
                Arrays.asList(
1✔
82
                    Callback.newBuilder()
1✔
83
                        .setNexus(
1✔
84
                            Callback.Nexus.newBuilder()
1✔
85
                                .setUrl(request.getCallbackUrl())
1✔
86
                                .putAllHeader(request.getCallbackHeaders())
1✔
87
                                .build())
1✔
88
                        .build()));
1✔
89
    if (options.getTaskQueue() == null) {
1✔
90
      nexusWorkflowOptions.setTaskQueue(request.getTaskQueue());
1✔
91
    }
92
    if (request.getLinks() != null) {
1✔
93
      nexusWorkflowOptions.setLinks(
1✔
94
          request.getLinks().stream()
1✔
95
              .map(
1✔
96
                  (link) -> {
97
                    if (io.temporal.api.common.v1.Link.WorkflowEvent.getDescriptor()
1✔
98
                        .getFullName()
1✔
99
                        .equals(link.getType())) {
1✔
100
                      io.temporal.api.nexus.v1.Link nexusLink =
101
                          io.temporal.api.nexus.v1.Link.newBuilder()
1✔
102
                              .setType(link.getType())
1✔
103
                              .setUrl(link.getUri().toString())
1✔
104
                              .build();
1✔
105
                      return LinkConverter.nexusLinkToWorkflowEvent(nexusLink);
1✔
106
                    } else {
107
                      log.warn("ignoring unsupported link data type: {}", link.getType());
×
108
                      return null;
×
109
                    }
110
                  })
111
              .filter(link -> link != null)
1✔
112
              .collect(Collectors.toList()));
1✔
113
    }
114
    return stub.newInstance(nexusWorkflowOptions.build());
1✔
115
  }
116

117
  /** Prohibit instantiation */
118
  private InternalUtils() {}
119
}
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