Jagger
 All Classes Namespaces Files Functions Variables Groups Pages
JLoadProfileRps.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.user.test.configurations.load;
2 
3 import com.griddynamics.jagger.user.test.configurations.load.auxiliary.RequestsPerSecond;
4 
5 import java.util.Objects;
6 
12 public class JLoadProfileRps implements JLoadProfile {
13 
14  private final long requestsPerSecond;
15  private final long maxLoadThreads;
16  private final long warmUpTimeInSeconds;
17  private final int tickInterval;
18 
20  Objects.requireNonNull(builder);
21 
22  this.requestsPerSecond = builder.requestsPerSecond;
23  this.maxLoadThreads = builder.maxLoadThreads;
24  this.warmUpTimeInSeconds = builder.warmUpTimeInSeconds;
25  this.tickInterval = builder.tickInterval;
26  }
27 
34  public static Builder builder(RequestsPerSecond requestsPerSecond) {
35  return new Builder(requestsPerSecond);
36  }
37 
38  public static class Builder {
39  static final int DEFAULT_TICK_INTERVAL = 1000;
40  static final int DEFAULT_MAX_LOAD_THREADS = 4000;
41  static final int DEFAULT_WARM_UP_TIME = -1;
42  private final long requestsPerSecond;
43  private long maxLoadThreads;
44  private long warmUpTimeInSeconds;
45 
46  // Tick interval doesn't have setter, since it's unclear if this field is needed. Check https://issues.griddynamics.net/browse/JFG-1000
47  private int tickInterval;
48 
55  public Builder(RequestsPerSecond requestsPerSecond) {
56  Objects.requireNonNull(requestsPerSecond);
57 
58  this.requestsPerSecond = requestsPerSecond.value();
59  this.maxLoadThreads = DEFAULT_MAX_LOAD_THREADS;
60  this.warmUpTimeInSeconds = DEFAULT_WARM_UP_TIME;
61  this.tickInterval = DEFAULT_TICK_INTERVAL;
62  }
63 
68  return new JLoadProfileRps(this);
69  }
70 
74  public Builder withMaxLoadThreads(long maxLoadThreads) {
75  if (maxLoadThreads <= 0) {
76  throw new IllegalArgumentException(String.format("The maximum number of threads must be > 0. Provided value is %s", maxLoadThreads));
77  }
78  this.maxLoadThreads = maxLoadThreads;
79  return this;
80  }
81 
85  public Builder withWarmUpTimeInSeconds(long warmUpTimeInSeconds) {
86  if (warmUpTimeInSeconds < 0) {
87  throw new IllegalArgumentException(
88  String.format("The warm up time value in seconds. must be >= 0. Provided value is %s", warmUpTimeInSeconds));
89  }
90  this.warmUpTimeInSeconds = warmUpTimeInSeconds;
91  return this;
92  }
93  }
94 
95  public long getRequestsPerSecond() {
96  return requestsPerSecond;
97  }
98 
99  public long getMaxLoadThreads() {
100  return maxLoadThreads;
101  }
102 
103  public long getWarmUpTimeInSeconds() {
104  return warmUpTimeInSeconds;
105  }
106 
107  public int getTickInterval() {
108  return tickInterval;
109  }
110 }