• 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

69.57
/temporal-sdk/src/main/java/io/temporal/worker/tuning/ResourceBasedSlotOptions.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.time.Duration;
25
import java.util.Objects;
26

27
/** Options resource-based slot suppliers */
28
@Experimental
29
public class ResourceBasedSlotOptions {
30
  private final int minimumSlots;
31
  private final int maximumSlots;
32
  private final Duration rampThrottle;
33

34
  public static Builder newBuilder() {
35
    return new Builder();
1✔
36
  }
37

38
  public static final class Builder {
39
    private int minimumSlots;
40
    private int maximumSlots;
41
    private Duration rampThrottle;
42

43
    private Builder() {}
44

45
    /**
46
     * @param minimumSlots minimum number of slots that will be issued without any resource checks
47
     */
48
    public Builder setMinimumSlots(int minimumSlots) {
49
      this.minimumSlots = minimumSlots;
1✔
50
      return this;
1✔
51
    }
52

53
    /**
54
     * @param maximumSlots maximum number of slots that will ever be issued
55
     */
56
    public Builder setMaximumSlots(int maximumSlots) {
57
      this.maximumSlots = maximumSlots;
1✔
58
      return this;
1✔
59
    }
60

61
    /**
62
     * @param rampThrottle time to wait between slot issuance. This value matters because how many
63
     *     resources a task will use cannot be determined ahead of time, and thus the system should
64
     *     wait to see how much resources are used before issuing more slots.
65
     */
66
    public Builder setRampThrottle(Duration rampThrottle) {
67
      this.rampThrottle = rampThrottle;
1✔
68
      return this;
1✔
69
    }
70

71
    public ResourceBasedSlotOptions build() {
72
      return new ResourceBasedSlotOptions(minimumSlots, maximumSlots, rampThrottle);
1✔
73
    }
74
  }
75

76
  /**
77
   * @param minimumSlots minimum number of slots that will be issued without any resource checks
78
   * @param maximumSlots maximum number of slots that will ever be issued
79
   * @param rampThrottle time to wait between slot issuance. This value matters because how many
80
   *     resources a task will use cannot be determined ahead of time, and thus the system should
81
   *     wait to see how much resources are used before issuing more slots.
82
   */
83
  private ResourceBasedSlotOptions(int minimumSlots, int maximumSlots, Duration rampThrottle) {
1✔
84
    this.minimumSlots = minimumSlots;
1✔
85
    this.maximumSlots = maximumSlots;
1✔
86
    this.rampThrottle = rampThrottle;
1✔
87
  }
1✔
88

89
  public int getMinimumSlots() {
90
    return minimumSlots;
1✔
91
  }
92

93
  public int getMaximumSlots() {
94
    return maximumSlots;
1✔
95
  }
96

97
  public Duration getRampThrottle() {
98
    return rampThrottle;
1✔
99
  }
100

101
  @Override
102
  public boolean equals(Object o) {
NEW
103
    if (this == o) return true;
×
NEW
104
    if (o == null || getClass() != o.getClass()) return false;
×
NEW
105
    ResourceBasedSlotOptions that = (ResourceBasedSlotOptions) o;
×
NEW
106
    return minimumSlots == that.minimumSlots
×
107
        && maximumSlots == that.maximumSlots
NEW
108
        && Objects.equals(rampThrottle, that.rampThrottle);
×
109
  }
110

111
  @Override
112
  public int hashCode() {
NEW
113
    return Objects.hash(minimumSlots, maximumSlots, rampThrottle);
×
114
  }
115

116
  @Override
117
  public String toString() {
NEW
118
    return "ResourceBasedSlotOptions{"
×
119
        + "minimumSlots="
120
        + minimumSlots
121
        + ", maximumSlots="
122
        + maximumSlots
123
        + ", rampThrottle="
124
        + rampThrottle
125
        + '}';
126
  }
127
}
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