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

temporalio / sdk-java / #302

15 Aug 2024 04:56PM UTC coverage: 77.456% (-0.3%) from 77.71%
#302

push

github

web-flow
Implement test server support for sync Nexus operation commands (#2176)

* Implement test server support for sync Nexus operations

* Nexus operations command implementations

* test cleanup

* cleanup

* tests

334 of 524 new or added lines in 9 files covered. (63.74%)

9 existing lines in 3 files now uncovered.

20298 of 26206 relevant lines covered (77.46%)

0.77 hits per line

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

82.93
/temporal-test-server/src/main/java/io/temporal/internal/testservice/NexusTaskToken.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.testservice;
22

23
import com.google.protobuf.ByteString;
24
import io.grpc.Status;
25
import io.temporal.api.common.v1.WorkflowExecution;
26
import java.io.*;
27
import java.util.Objects;
28
import javax.annotation.Nonnull;
29

30
class NexusTaskToken {
31

32
  @Nonnull private final ExecutionId executionId;
33
  private final long scheduledEventId;
34
  private final int attempt;
35

36
  NexusTaskToken(
37
      @Nonnull String namespace,
38
      @Nonnull WorkflowExecution execution,
39
      long scheduledEventId,
40
      int attempt) {
41
    this(
1✔
42
        new ExecutionId(Objects.requireNonNull(namespace), Objects.requireNonNull(execution)),
1✔
43
        scheduledEventId,
44
        attempt);
45
  }
1✔
46

47
  NexusTaskToken(
48
      @Nonnull String namespace,
49
      @Nonnull String workflowId,
50
      @Nonnull String runId,
51
      long scheduledEventId,
52
      int attempt) {
53
    this(
1✔
54
        namespace,
55
        WorkflowExecution.newBuilder()
1✔
56
            .setWorkflowId(Objects.requireNonNull(workflowId))
1✔
57
            .setRunId(Objects.requireNonNull(runId))
1✔
58
            .build(),
1✔
59
        scheduledEventId,
60
        attempt);
61
  }
1✔
62

63
  NexusTaskToken(@Nonnull ExecutionId executionId, long scheduledEventId, int attempt) {
1✔
64
    this.executionId = Objects.requireNonNull(executionId);
1✔
65
    this.scheduledEventId = scheduledEventId;
1✔
66
    this.attempt = attempt;
1✔
67
  }
1✔
68

69
  public ExecutionId getExecutionId() {
70
    return executionId;
1✔
71
  }
72

73
  public long getScheduledEventId() {
74
    return scheduledEventId;
1✔
75
  }
76

77
  public long getAttempt() {
78
    return attempt;
1✔
79
  }
80

81
  /** Used for task tokens. */
82
  public ByteString toBytes() {
83
    try (ByteArrayOutputStream bout = new ByteArrayOutputStream();
1✔
84
        DataOutputStream out = new DataOutputStream(bout)) {
1✔
85
      out.writeUTF(executionId.getNamespace());
1✔
86
      WorkflowExecution execution = executionId.getExecution();
1✔
87
      out.writeUTF(execution.getWorkflowId());
1✔
88
      out.writeUTF(execution.getRunId());
1✔
89
      out.writeLong(scheduledEventId);
1✔
90
      out.writeInt(attempt);
1✔
91
      return ByteString.copyFrom(bout.toByteArray());
1✔
NEW
92
    } catch (IOException e) {
×
NEW
93
      throw Status.INTERNAL.withCause(e).withDescription(e.getMessage()).asRuntimeException();
×
94
    }
95
  }
96

97
  static NexusTaskToken fromBytes(ByteString serialized) {
98
    ByteArrayInputStream bin = new ByteArrayInputStream(serialized.toByteArray());
1✔
99
    DataInputStream in = new DataInputStream(bin);
1✔
100
    try {
101
      String namespace = in.readUTF();
1✔
102
      String workflowId = in.readUTF();
1✔
103
      String runId = in.readUTF();
1✔
104
      long scheduledEventId = in.readLong();
1✔
105
      int attempt = in.readInt();
1✔
106
      return new NexusTaskToken(namespace, workflowId, runId, scheduledEventId, attempt);
1✔
NEW
107
    } catch (IOException e) {
×
NEW
108
      throw Status.INVALID_ARGUMENT
×
NEW
109
          .withCause(e)
×
NEW
110
          .withDescription(e.getMessage())
×
NEW
111
          .asRuntimeException();
×
112
    }
113
  }
114
}
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

© 2026 Coveralls, Inc