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

temporalio / sdk-java / #202

23 Oct 2023 11:07PM UTC coverage: 77.34% (-0.05%) from 77.389%
#202

push

github-actions

web-flow
Release Java SDK v1.22.2 (#1909)

18707 of 24188 relevant lines covered (77.34%)

0.77 hits per line

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

80.0
/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestVisibilityStoreImpl.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.common.collect.ImmutableMap;
24
import io.grpc.Status;
25
import io.temporal.api.common.v1.Payload;
26
import io.temporal.api.common.v1.SearchAttributes;
27
import io.temporal.api.enums.v1.IndexedValueType;
28
import io.temporal.internal.common.ProtoEnumNameUtils;
29
import io.temporal.internal.common.SearchAttributesUtil;
30
import java.util.Collections;
31
import java.util.Map;
32
import java.util.concurrent.ConcurrentHashMap;
33
import javax.annotation.Nonnull;
34

35
class TestVisibilityStoreImpl implements TestVisibilityStore {
1✔
36

37
  private static final String DEFAULT_KEY_STRING = "CustomStringField";
38
  private static final String DEFAULT_KEY_TEXT = "CustomTextField";
39
  private static final String DEFAULT_KEY_KEYWORD = "CustomKeywordField";
40
  private static final String DEFAULT_KEY_INTEGER = "CustomIntField";
41
  private static final String DEFAULT_KEY_DATE_TIME = "CustomDatetimeField";
42
  private static final String DEFAULT_KEY_DOUBLE = "CustomDoubleField";
43
  private static final String DEFAULT_KEY_BOOL = "CustomBoolField";
44
  private static final String TEMPORAL_CHANGE_VERSION = "TemporalChangeVersion";
45

46
  private final Map<String, IndexedValueType> searchAttributes =
1✔
47
      new ConcurrentHashMap<>(
48
          ImmutableMap.<String, IndexedValueType>builder()
1✔
49
              .put(DEFAULT_KEY_STRING, IndexedValueType.INDEXED_VALUE_TYPE_TEXT)
1✔
50
              .put(DEFAULT_KEY_TEXT, IndexedValueType.INDEXED_VALUE_TYPE_TEXT)
1✔
51
              .put(DEFAULT_KEY_KEYWORD, IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD)
1✔
52
              .put(DEFAULT_KEY_INTEGER, IndexedValueType.INDEXED_VALUE_TYPE_INT)
1✔
53
              .put(DEFAULT_KEY_DOUBLE, IndexedValueType.INDEXED_VALUE_TYPE_DOUBLE)
1✔
54
              .put(DEFAULT_KEY_BOOL, IndexedValueType.INDEXED_VALUE_TYPE_BOOL)
1✔
55
              .put(DEFAULT_KEY_DATE_TIME, IndexedValueType.INDEXED_VALUE_TYPE_DATETIME)
1✔
56
              .put(TEMPORAL_CHANGE_VERSION, IndexedValueType.INDEXED_VALUE_TYPE_KEYWORD_LIST)
1✔
57
              .build());
1✔
58

59
  private final Map<ExecutionId, SearchAttributes> executionSearchAttributes =
1✔
60
      new ConcurrentHashMap<>();
61

62
  @Override
63
  public void addSearchAttribute(String name, IndexedValueType type) {
64
    if (type == IndexedValueType.INDEXED_VALUE_TYPE_UNSPECIFIED) {
1✔
65
      throw Status.INVALID_ARGUMENT
×
66
          .withDescription("Unable to read search attribute type: " + type)
×
67
          .asRuntimeException();
×
68
    }
69
    if (searchAttributes.putIfAbsent(name, type) != null) {
1✔
70
      throw Status.ALREADY_EXISTS
×
71
          .withDescription("Search attribute " + name + " already exists.")
×
72
          .asRuntimeException();
×
73
    }
74
  }
1✔
75

76
  @Override
77
  public void removeSearchAttribute(String name) {
78
    if (searchAttributes.remove(name) == null) {
×
79
      throw Status.NOT_FOUND
×
80
          .withDescription("Search attribute " + name + " doesn't exist.")
×
81
          .asRuntimeException();
×
82
    }
83
  }
×
84

85
  @Override
86
  public Map<String, IndexedValueType> getRegisteredSearchAttributes() {
87
    return Collections.unmodifiableMap(searchAttributes);
1✔
88
  }
89

90
  @Override
91
  public SearchAttributes getSearchAttributesForExecution(ExecutionId executionId) {
92
    return executionSearchAttributes.get(executionId);
1✔
93
  }
94

95
  @Override
96
  public SearchAttributes upsertSearchAttributesForExecution(
97
      ExecutionId executionId, @Nonnull SearchAttributes searchAttributes) {
98
    validateSearchAttributes(searchAttributes);
1✔
99
    return executionSearchAttributes.compute(
1✔
100
        executionId,
101
        (key, value) ->
102
            value == null
1✔
103
                ? searchAttributes
1✔
104
                : value.toBuilder()
1✔
105
                    .putAllIndexedFields(searchAttributes.getIndexedFieldsMap())
1✔
106
                    .build());
1✔
107
  }
108

109
  @Override
110
  public void validateSearchAttributes(SearchAttributes searchAttributes) {
111
    Map<String, IndexedValueType> registeredAttributes = getRegisteredSearchAttributes();
1✔
112

113
    for (Map.Entry<String, Payload> searchAttribute :
114
        searchAttributes.getIndexedFieldsMap().entrySet()) {
1✔
115
      String saName = searchAttribute.getKey();
1✔
116
      IndexedValueType indexedValueType = registeredAttributes.get(saName);
1✔
117
      if (indexedValueType == null) {
1✔
118
        throw Status.INVALID_ARGUMENT
1✔
119
            .withDescription("search attribute " + saName + " is not defined")
1✔
120
            .asRuntimeException();
1✔
121
      }
122

123
      try {
124
        SearchAttributesUtil.decodeAsType(searchAttributes, saName, indexedValueType);
1✔
125
      } catch (Exception e) {
1✔
126
        throw Status.INVALID_ARGUMENT
1✔
127
            .withDescription(
1✔
128
                "invalid value for search attribute "
129
                    + saName
130
                    + " of type "
131
                    + ProtoEnumNameUtils.uniqueToSimplifiedName(indexedValueType)
1✔
132
                    + ": "
133
                    + searchAttributes.getIndexedFieldsMap().get(saName).getData().toStringUtf8())
1✔
134
            .asRuntimeException();
1✔
135
      }
1✔
136
    }
1✔
137
  }
1✔
138

139
  @Override
140
  public void close() {}
1✔
141
}
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