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