Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JLoadProfileUserGroups.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.user.test.configurations.load;
2 
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6 import java.util.Objects;
7 
8 import static java.util.Collections.singletonList;
9 
31 public class JLoadProfileUserGroups implements JLoadProfile {
32 
33  private final List<JLoadProfileUsers> userGroups;
34  private final int delayBetweenInvocationsInMilliseconds;
35  private final int tickInterval;
36 
38  this.userGroups = builder.userGroups;
39  this.delayBetweenInvocationsInMilliseconds = builder.delayBetweenInvocationsInMilliseconds;
40  this.tickInterval = builder.tickInterval;
41  }
42 
49  public static Builder builder(JLoadProfileUsers userGroup) {
50  return new Builder(userGroup);
51  }
52 
60  public static Builder builder(JLoadProfileUsers userGroup, JLoadProfileUsers... userGroups) {
61  return new Builder(userGroup, userGroups);
62  }
63 
64  public static class Builder {
65  static final int DEFAULT_TICK_INTERVAL = 1000;
66  private final List<JLoadProfileUsers> userGroups;
67  private int delayBetweenInvocationsInMilliseconds;
68 
69  // Tick interval doesn't have setter, since it's unclear if this field is needed. Check https://issues.griddynamics.net/browse/JFG-1000
70  private int tickInterval;
71 
78  private Builder(JLoadProfileUsers userGroup) {
79  Objects.requireNonNull(userGroup);
80  this.userGroups = singletonList(userGroup);
81  this.tickInterval = DEFAULT_TICK_INTERVAL;
82  }
83 
91  public Builder(JLoadProfileUsers userGroup, JLoadProfileUsers... userGroups) {
92  Objects.requireNonNull(userGroup);
93  ArrayList<JLoadProfileUsers> groups = new ArrayList<>();
94  groups.add(userGroup);
95  Collections.addAll(groups, userGroups);
96  this.userGroups = groups;
97  this.tickInterval = DEFAULT_TICK_INTERVAL;
98  }
99 
100 
105  return new JLoadProfileUserGroups(this);
106  }
107 
112  public Builder withDelayBetweenInvocationsInMilliseconds(int delayBetweenInvocationsInMilliseconds) {
113  if (delayBetweenInvocationsInMilliseconds < 0) {
114  throw new IllegalArgumentException(
115  String.format("Delay between invocations must be >= 0. Provided value is %s", delayBetweenInvocationsInMilliseconds));
116  }
117  this.delayBetweenInvocationsInMilliseconds = delayBetweenInvocationsInMilliseconds;
118  return this;
119  }
120  }
121 
122  public List<JLoadProfileUsers> getUserGroups() {
123  return userGroups;
124  }
125 
127  return delayBetweenInvocationsInMilliseconds;
128  }
129 
130  public int getTickInterval() {
131  return tickInterval;
132  }
133 }