Jagger
 All Classes Namespaces Files Functions Variables Enumerator 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 
34 public class JLoadProfileRps implements JLoadProfile {
35 
36  private final long requestsPerSecond;
37  private final long maxLoadThreads;
38  private final long warmUpTimeInMilliseconds;
39  private final int tickInterval;
40 
42  Objects.requireNonNull(builder);
43 
44  this.requestsPerSecond = builder.requestsPerSecond;
45  this.maxLoadThreads = builder.maxLoadThreads;
46  this.warmUpTimeInMilliseconds = builder.warmUpTimeInMilliseconds;
47  this.tickInterval = builder.tickInterval;
48  }
49 
56  public static Builder builder(RequestsPerSecond requestsPerSecond) {
57  return new Builder(requestsPerSecond);
58  }
59 
60  public static class Builder {
61  static final int DEFAULT_TICK_INTERVAL = 1000;
62  static final int DEFAULT_MAX_LOAD_THREADS = 500;
63  static final int DEFAULT_WARM_UP_TIME = -1;
64  private final long requestsPerSecond;
65  private long maxLoadThreads;
66  private long warmUpTimeInMilliseconds;
67 
68  // Tick interval doesn't have setter, since it's unclear if this field is needed. Check https://issues.griddynamics.net/browse/JFG-1000
69  private int tickInterval;
70 
77  public Builder(RequestsPerSecond requestsPerSecond) {
78  Objects.requireNonNull(requestsPerSecond);
79 
80  this.requestsPerSecond = requestsPerSecond.value();
81  this.maxLoadThreads = DEFAULT_MAX_LOAD_THREADS;
82  this.warmUpTimeInMilliseconds = DEFAULT_WARM_UP_TIME;
83  this.tickInterval = DEFAULT_TICK_INTERVAL;
84  }
85 
90  return new JLoadProfileRps(this);
91  }
92 
96  public Builder withMaxLoadThreads(long maxLoadThreads) {
97  if (maxLoadThreads <= 0) {
98  throw new IllegalArgumentException(String.format("The maximum number of threads must be > 0. Provided value is %s", maxLoadThreads));
99  }
100  this.maxLoadThreads = maxLoadThreads;
101  return this;
102  }
103 
107  public Builder withWarmUpTimeInMilliseconds(long warmUpTimeInMilliseconds) {
108  if (warmUpTimeInMilliseconds < 0) {
109  throw new IllegalArgumentException(
110  String.format("The warm up time value in milliseconds. must be >= 0. Provided value is %s", warmUpTimeInMilliseconds));
111  }
112  this.warmUpTimeInMilliseconds = warmUpTimeInMilliseconds;
113  return this;
114  }
115  }
116 
117  public long getRequestsPerSecond() {
118  return requestsPerSecond;
119  }
120 
121  public long getMaxLoadThreads() {
122  return maxLoadThreads;
123  }
124 
126  return warmUpTimeInMilliseconds;
127  }
128 
129  public int getTickInterval() {
130  return tickInterval;
131  }
132 }