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

temporalio / sdk-java / #316

13 Sep 2024 05:01PM UTC coverage: 77.963% (+0.3%) from 77.673%
#316

push

github

web-flow
Test server support for async Nexus operations (#2198)

* Test server support for async Nexus operations

* Refactor cancel states

* tests and fixes

* refactor retry logic

* failure handling

* tests

* task timeout

* tests

* feedback

* license

* typo

325 of 381 new or added lines in 7 files covered. (85.3%)

34 existing lines in 8 files now uncovered.

20689 of 26537 relevant lines covered (77.96%)

0.78 hits per line

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

3.28
/temporal-sdk/src/main/java/io/temporal/common/converter/DataConverterException.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.common.converter;
22

23
import io.temporal.api.common.v1.Payload;
24
import io.temporal.api.common.v1.Payloads;
25
import java.lang.reflect.Type;
26
import java.nio.charset.StandardCharsets;
27
import java.util.Arrays;
28
import java.util.Optional;
29

30
/**
31
 * @author fateev
32
 * @see DataConverter
33
 */
34
public class DataConverterException extends RuntimeException {
35

36
  /** Maximum size of data to be included into the message. Used to avoid very large payloads. */
37
  public static final int MESSAGE_TRUNCATION_SIZE = 255;
38

39
  public DataConverterException(String message) {
40
    super(message);
×
41
  }
×
42

43
  public DataConverterException(Throwable cause) {
44
    super(cause);
1✔
45
  }
1✔
46

47
  public DataConverterException(String message, Throwable cause) {
48
    super(message, cause);
×
49
  }
×
50

51
  public DataConverterException(Payload content, Type[] valueTypes, Throwable cause) {
52
    super(toMessageDeserializing(null, content, valueTypes), cause);
×
53
  }
×
54

55
  public DataConverterException(String message, Payload content, Type[] valueTypes) {
56
    super(toMessageDeserializing(message, content, valueTypes));
×
57
  }
×
58

59
  public DataConverterException(String message, Optional<Payloads> content, Type valueType) {
60
    super(toMessageDeserializing(message, content, valueType));
×
61
  }
×
62

63
  public DataConverterException(String message, Optional<Payloads> content, Type[] valueTypes) {
64
    super(toMessageDeserializing(message, content, valueTypes));
×
65
  }
×
66

67
  public <T> DataConverterException(Payload payload, Class<T> valueClass, Throwable e) {
UNCOV
68
    super(toMessageDeserializing(e.getMessage(), payload, new Type[] {valueClass}), e);
×
UNCOV
69
  }
×
70

71
  private static String toMessageDeserializing(
72
      String message, Optional<Payloads> content, Type[] valueTypes) {
73
    if (content == null && valueTypes == null || valueTypes.length == 0) {
×
74
      return message;
×
75
    }
76
    StringBuilder result = new StringBuilder();
×
77
    if (message != null && message.length() > 0) {
×
78
      result.append(message);
×
79
      result.append(" ");
×
80
    }
81
    result.append("when parsing:\"");
×
82
    result.append(truncateContent(content));
×
83
    result.append("\" into following types: ");
×
84
    result.append(Arrays.toString(valueTypes));
×
85
    return result.toString();
×
86
  }
87

88
  private static String toMessageDeserializing(
89
      String message, Optional<Payloads> content, Type valueType) {
90
    if (!content.isPresent() && valueType == null) {
×
91
      return message;
×
92
    }
93
    StringBuilder result = new StringBuilder();
×
94
    if (message != null && message.length() > 0) {
×
95
      result.append(message);
×
96
      result.append(" ");
×
97
    }
98
    result.append("when parsing:\"");
×
99
    result.append(truncateContent(content));
×
100
    result.append("\" into following types: ");
×
101
    result.append(valueType);
×
102
    return result.toString();
×
103
  }
104

105
  private static String toMessageDeserializing(String message, Payload content, Type[] valueTypes) {
UNCOV
106
    if (content == null && valueTypes == null) {
×
107
      return message;
×
108
    }
UNCOV
109
    StringBuilder result = new StringBuilder();
×
UNCOV
110
    if (message != null && message.length() > 0) {
×
111
      result.append(message);
×
112
      result.append(" ");
×
113
    }
UNCOV
114
    result.append("when parsing:\"");
×
UNCOV
115
    result.append(truncateContent(content));
×
UNCOV
116
    result.append("\" into following types: ");
×
UNCOV
117
    result.append(Arrays.toString(valueTypes));
×
UNCOV
118
    return result.toString();
×
119
  }
120

121
  private static String truncateContent(Optional<Payloads> content) {
122
    if (!content.isPresent()) {
×
123
      return "<EMPTY PAYLOAD>";
×
124
    }
125
    // Limit size of the string.
126
    String data;
127
    if (content.get().getPayloadsCount() == 1) {
×
128
      data = content.get().getPayloads(0).getData().toString(StandardCharsets.UTF_8);
×
129
    } else {
130
      data = String.valueOf(content);
×
131
    }
132
    int maxIndex = Math.min(data.length(), MESSAGE_TRUNCATION_SIZE);
×
133
    return data.substring(0, maxIndex);
×
134
  }
135

136
  private static String truncateContent(Payload content) {
UNCOV
137
    if (content == null) {
×
138
      return "";
×
139
    }
140
    // Limit size of the string.
UNCOV
141
    String data = content.getData().toString(StandardCharsets.UTF_8);
×
UNCOV
142
    int maxIndex = Math.min(data.length(), MESSAGE_TRUNCATION_SIZE);
×
UNCOV
143
    return data.substring(0, maxIndex);
×
144
  }
145
}
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