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

temporalio / sdk-java / #272

21 Jun 2024 08:17PM UTC coverage: 77.548% (+0.04%) from 77.506%
#272

push

github

web-flow
Resource based tuner (#2110)

275 of 338 new or added lines in 11 files covered. (81.36%)

12 existing lines in 5 files now uncovered.

19522 of 25174 relevant lines covered (77.55%)

0.78 hits per line

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

84.21
/temporal-sdk/src/main/java/io/temporal/worker/tuning/CompositeTuner.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.worker.tuning;
22

23
import io.temporal.common.Experimental;
24
import java.util.Objects;
25
import javax.annotation.Nonnull;
26

27
/**
28
 * Can be used to create a {@link WorkerTuner} which uses specific {@link SlotSupplier}s for each
29
 * type of slot.
30
 */
31
@Experimental
32
public class CompositeTuner implements WorkerTuner {
33
  private final @Nonnull SlotSupplier<WorkflowSlotInfo> workflowTaskSlotSupplier;
34
  private final @Nonnull SlotSupplier<ActivitySlotInfo> activityTaskSlotSupplier;
35
  private final @Nonnull SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier;
36

37
  public CompositeTuner(
38
      @Nonnull SlotSupplier<WorkflowSlotInfo> workflowTaskSlotSupplier,
39
      @Nonnull SlotSupplier<ActivitySlotInfo> activityTaskSlotSupplier,
40
      @Nonnull SlotSupplier<LocalActivitySlotInfo> localActivitySlotSupplier) {
1✔
41
    this.workflowTaskSlotSupplier = Objects.requireNonNull(workflowTaskSlotSupplier);
1✔
42
    this.activityTaskSlotSupplier = Objects.requireNonNull(activityTaskSlotSupplier);
1✔
43
    this.localActivitySlotSupplier = Objects.requireNonNull(localActivitySlotSupplier);
1✔
44

45
    // All resource-based slot suppliers must use the same controller
46
    validateResourceController(workflowTaskSlotSupplier, activityTaskSlotSupplier);
1✔
47
    validateResourceController(workflowTaskSlotSupplier, localActivitySlotSupplier);
1✔
48
    validateResourceController(activityTaskSlotSupplier, localActivitySlotSupplier);
1✔
49
  }
1✔
50

51
  @Nonnull
52
  @Override
53
  public SlotSupplier<WorkflowSlotInfo> getWorkflowTaskSlotSupplier() {
NEW
54
    return workflowTaskSlotSupplier;
×
55
  }
56

57
  @Nonnull
58
  @Override
59
  public SlotSupplier<ActivitySlotInfo> getActivityTaskSlotSupplier() {
NEW
60
    return activityTaskSlotSupplier;
×
61
  }
62

63
  @Nonnull
64
  @Override
65
  public SlotSupplier<LocalActivitySlotInfo> getLocalActivitySlotSupplier() {
NEW
66
    return localActivitySlotSupplier;
×
67
  }
68

69
  private <T extends SlotInfo, U extends SlotInfo> void validateResourceController(
70
      @Nonnull SlotSupplier<T> supplier1, @Nonnull SlotSupplier<U> supplier2) {
71
    if (supplier1 instanceof ResourceBasedSlotSupplier
1✔
72
        && supplier2 instanceof ResourceBasedSlotSupplier) {
73
      ResourceBasedController controller1 =
1✔
74
          ((ResourceBasedSlotSupplier<?>) supplier1).getResourceController();
1✔
75
      ResourceBasedController controller2 =
1✔
76
          ((ResourceBasedSlotSupplier<?>) supplier2).getResourceController();
1✔
77
      if (controller1 != controller2) {
1✔
78
        throw new IllegalArgumentException(
1✔
79
            "All resource-based slot suppliers must use the same ResourceController");
80
      }
81
    }
82
  }
1✔
83
}
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