Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JLoadScenario.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.user.test.configurations;
2 
3 import com.griddynamics.jagger.engine.e1.Provider;
4 import com.griddynamics.jagger.engine.e1.collector.loadscenario.ExampleLoadScenarioListener;
5 import com.griddynamics.jagger.engine.e1.collector.loadscenario.LoadScenarioListener;
6 import com.griddynamics.jagger.user.test.configurations.auxiliary.Id;
7 
8 import com.google.common.collect.Lists;
9 
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Objects;
14 import java.util.stream.Collectors;
15 
34 public class JLoadScenario {
35 
36  private final String id;
37  private final List<JParallelTestsGroup> testGroups;
38  private final List<Double> percentileValues;
39  private final List<Provider<LoadScenarioListener>> listeners;
40 
41  private JLoadScenario(Builder builder) {
42  this.id = builder.id.value();
43  this.testGroups = builder.testGroups;
44  this.percentileValues = builder.percentileValues;
45  this.listeners = builder.listeners;
46  }
47 
55  public static Builder builder(Id id, List<JParallelTestsGroup> testGroups) {
56  return new Builder(id, testGroups);
57  }
58 
67  public static Builder builder(Id id, JParallelTestsGroup testGroup, JParallelTestsGroup... testGroups) {
68  List<JParallelTestsGroup> jParallelTestsGroupList = new ArrayList<>();
69  jParallelTestsGroupList.add(testGroup);
70  Collections.addAll(jParallelTestsGroupList, testGroups);
71 
72  return new Builder(id, jParallelTestsGroupList);
73  }
74 
75  public static class Builder {
76  private final Id id;
77  private final List<JParallelTestsGroup> testGroups;
78  private List<Double> percentileValues;
79  private List<Provider<LoadScenarioListener>> listeners = Lists.newArrayList();
80 
81  public Builder(Id id, List<JParallelTestsGroup> testGroups) {
82  this.id = id;
83  this.testGroups = testGroups;
84  }
85 
91  public Builder withLatencyPercentiles(List<Double> percentileValues) {
92  Objects.requireNonNull(percentileValues);
93  percentileValues.stream().filter(percentile -> percentile <= 0.0 || percentile >= 100.0)
94  .findAny()
95  .ifPresent(badPercentile -> {
96  throw new IllegalArgumentException("Percentile value must be > 0 and < 100. Provided value is " + badPercentile);
97  });
98 
99  this.percentileValues = percentileValues;
100  return this;
101  }
102 
112  public Builder addListener(Provider<LoadScenarioListener> listener) {
113  this.listeners.add(listener);
114  return this;
115  }
116 
126  public Builder addListeners(List<Provider<LoadScenarioListener>> listeners) {
127  this.listeners.addAll(listeners);
128  return this;
129  }
130 
136  public JLoadScenario build() {
137 
138  if (testGroups.stream().map(JParallelTestsGroup::getId).collect(Collectors.toSet()).size() < testGroups.size()) {
139  throw new IllegalStateException("JParallelTestsGroup ids inside one JLoadScenario are not all unique");
140  }
141 
142  return new JLoadScenario(this);
143  }
144 
145  }
146 
147  public List<JParallelTestsGroup> getTestGroups() {
148  return testGroups;
149  }
150 
151  public String getId() {
152  return id;
153  }
154 
155  public List<Double> getPercentileValues() {
156  return percentileValues;
157  }
158 
159  public List<Provider<LoadScenarioListener>> getListeners() {
160  return listeners;
161  }
162 }