Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JLoadProfileTps.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.TransactionsPerSecond;
4 
5 import java.util.Objects;
6 
22 public class JLoadProfileTps implements JLoadProfile {
23 
24  private final long transactionsPerSecond;
25  private final long maxLoadThreads;
26  private final long warmUpTimeInMilliseconds;
27  private final int tickInterval;
28 
30  Objects.requireNonNull(builder);
31 
32  this.transactionsPerSecond = builder.transactionsPerSecond;
33  this.maxLoadThreads = builder.maxLoadThreads;
34  this.warmUpTimeInMilliseconds = builder.warmUpTimeInMilliseconds;
35  this.tickInterval = builder.tickInterval;
36  }
37 
44  public static Builder builder(TransactionsPerSecond transactionsPerSecond) {
45  return new Builder(transactionsPerSecond);
46  }
47 
48  public static class Builder {
49  static final int DEFAULT_TICK_INTERVAL = 1000;
50  static final int DEFAULT_MAX_LOAD_THREADS = 500;
51  static final int DEFAULT_WARM_UP_TIME = -1;
52  private final long transactionsPerSecond;
53  private long maxLoadThreads;
54  private long warmUpTimeInMilliseconds;
55 
56  // Tick interval doesn't have setter, since it's unclear if this field is needed. Check https://issues.griddynamics.net/browse/JFG-1000
57  private int tickInterval;
58 
65  public Builder(TransactionsPerSecond transactionsPerSecond) {
66  Objects.requireNonNull(transactionsPerSecond);
67 
68  this.transactionsPerSecond = transactionsPerSecond.value();
69  this.maxLoadThreads = DEFAULT_MAX_LOAD_THREADS;
70  this.warmUpTimeInMilliseconds = DEFAULT_WARM_UP_TIME;
71  this.tickInterval = DEFAULT_TICK_INTERVAL;
72  }
73 
78  return new JLoadProfileTps(this);
79  }
80 
84  public Builder withMaxLoadThreads(long maxLoadThreads) {
85  if (maxLoadThreads <= 0) {
86  throw new IllegalArgumentException(String.format("The maximum number of threads must be > 0. Provided value is %s", maxLoadThreads));
87  }
88  this.maxLoadThreads = maxLoadThreads;
89  return this;
90  }
91 
95  public Builder withWarmUpTimeInSeconds(long warmUpTimeInMilliseconds) {
96  if (warmUpTimeInMilliseconds < 0) {
97  throw new IllegalArgumentException(
98  String.format("The warm up time value in milliseconds. must be >= 0. Provided value is %s", warmUpTimeInMilliseconds));
99  }
100  this.warmUpTimeInMilliseconds = warmUpTimeInMilliseconds;
101  return this;
102  }
103  }
104 
105  public long getTransactionsPerSecond() {
106  return transactionsPerSecond;
107  }
108 
109  public long getMaxLoadThreads() {
110  return maxLoadThreads;
111  }
112 
114  return warmUpTimeInMilliseconds;
115  }
116 
117  public int getTickInterval() {
118  return tickInterval;
119  }
120 }