Jagger
 All Classes Namespaces Files Functions Variables 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 
22 public class JLoadProfileUserGroups implements JLoadProfile {
23 
24  private final List<JLoadProfileUsers> userGroups;
25  private final int delayBetweenInvocationsInSeconds;
26  private final int tickInterval;
27 
29  this.userGroups = builder.userGroups;
30  this.delayBetweenInvocationsInSeconds = builder.delayBetweenInvocationsInSeconds;
31  this.tickInterval = builder.tickInterval;
32  }
33 
40  public static Builder builder(JLoadProfileUsers userGroup) {
41  return new Builder(userGroup);
42  }
43 
51  public static Builder builder(JLoadProfileUsers userGroup, JLoadProfileUsers... userGroups) {
52  return new Builder(userGroup, userGroups);
53  }
54 
55  public static class Builder {
56  static final int DEFAULT_TICK_INTERVAL = 1000;
57  private final List<JLoadProfileUsers> userGroups;
58  private int delayBetweenInvocationsInSeconds;
59 
60  // Tick interval doesn't have setter, since it's unclear if this field is needed. Check https://issues.griddynamics.net/browse/JFG-1000
61  private int tickInterval;
62 
69  private Builder(JLoadProfileUsers userGroup) {
70  Objects.requireNonNull(userGroup);
71  this.userGroups = singletonList(userGroup);
72  this.tickInterval = DEFAULT_TICK_INTERVAL;
73  }
74 
82  public Builder(JLoadProfileUsers userGroup, JLoadProfileUsers... userGroups) {
83  Objects.requireNonNull(userGroup);
84  ArrayList<JLoadProfileUsers> groups = new ArrayList<>();
85  groups.add(userGroup);
86  Collections.addAll(groups, userGroups);
87  this.userGroups = groups;
88  this.tickInterval = DEFAULT_TICK_INTERVAL;
89  }
90 
91 
96  return new JLoadProfileUserGroups(this);
97  }
98 
103  public Builder withDelayBetweenInvocationsInSeconds(int delayBetweenInvocationsInSeconds) {
104  if (delayBetweenInvocationsInSeconds < 0) {
105  throw new IllegalArgumentException(
106  String.format("Delay between invocations must be >= 0. Provided value is %s", delayBetweenInvocationsInSeconds));
107  }
108  this.delayBetweenInvocationsInSeconds = delayBetweenInvocationsInSeconds;
109  return this;
110  }
111  }
112 
113  public List<JLoadProfileUsers> getUserGroups() {
114  return userGroups;
115  }
116 
118  return delayBetweenInvocationsInSeconds;
119  }
120 
121  public int getTickInterval() {
122  return tickInterval;
123  }
124 }