Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
ExampleJLoadScenarioProvider.java
Go to the documentation of this file.
1 package ${package};
2 
3 import static java.util.Collections.singletonList;
4 
5 import com.griddynamics.jagger.engine.e1.collector.CollectThreadsTestListener;
6 import com.griddynamics.jagger.engine.e1.collector.ExampleResponseValidatorProvider;
7 import com.griddynamics.jagger.engine.e1.collector.NotNullResponseValidator;
8 import com.griddynamics.jagger.engine.e1.collector.DefaultResponseValidatorProvider;
9 import com.griddynamics.jagger.engine.e1.collector.invocation.NotNullInvocationListener;
10 import com.griddynamics.jagger.engine.e1.collector.loadscenario.ExampleLoadScenarioListener;
11 import com.griddynamics.jagger.engine.e1.collector.testgroup.ExampleTestGroupListener;
12 import com.griddynamics.jagger.invoker.RoundRobinLoadBalancer;
13 import com.griddynamics.jagger.user.test.configurations.JLoadScenario;
14 import com.griddynamics.jagger.user.test.configurations.JLoadTest;
15 import com.griddynamics.jagger.user.test.configurations.JParallelTestsGroup;
16 import com.griddynamics.jagger.user.test.configurations.JTestDefinition;
17 import com.griddynamics.jagger.user.test.configurations.auxiliary.Id;
18 import com.griddynamics.jagger.user.test.configurations.limits.JLimit;
19 import com.griddynamics.jagger.user.test.configurations.limits.JLimitVsBaseline;
20 import com.griddynamics.jagger.user.test.configurations.limits.JLimitVsRefValue;
21 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.JMetricName;
22 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.LowErrThresh;
23 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.LowWarnThresh;
24 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.RefValue;
25 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.UpErrThresh;
26 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.UpWarnThresh;
27 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.RefValue;
28 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.UpErrThresh;
29 import com.griddynamics.jagger.user.test.configurations.limits.auxiliary.UpWarnThresh;
30 import com.griddynamics.jagger.user.test.configurations.load.JLoadProfile;
31 import com.griddynamics.jagger.user.test.configurations.load.JLoadProfileRps;
32 import com.griddynamics.jagger.user.test.configurations.load.auxiliary.RequestsPerSecond;
33 import com.griddynamics.jagger.user.test.configurations.termination.JTerminationCriteria;
34 import com.griddynamics.jagger.user.test.configurations.termination.JTerminationCriteriaBackground;
35 import com.griddynamics.jagger.user.test.configurations.termination.JTerminationCriteriaIterations;
36 import com.griddynamics.jagger.user.test.configurations.termination.auxiliary.IterationsNumber;
37 import com.griddynamics.jagger.user.test.configurations.termination.auxiliary.MaxDurationInSeconds;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Configuration;
40 import ${package}.util.JaggerPropertiesProvider;
41 
42 import java.util.Arrays;
43 
44 // begin: following section is used for docu generation - Detailed load test scenario configuration
45 
51 @Configuration
53 
54  @Bean
56 
57  // Example of using JaggerPropertiesProvider
58  String testDefinitionComment = getTestPropertyValue("example.jagger.test.definition.comment");
59 
60  JTestDefinition jTestDefinition = JTestDefinition
61  .builder(Id.of("exampleJaggerTestDefinition"), new ExampleEndpointsProvider())
62  // optional
63  .withComment(testDefinitionComment)
65  .withQueryProvider(new ExampleQueriesProvider())
66  .withLoadBalancer(new RoundRobinLoadBalancer())
67  .addValidator(new ExampleResponseValidatorProvider("we are always good"))
69  .addListener(new NotNullInvocationListener())
70  .build();
71 
72  // Example of using JaggerPropertiesProvider
73  Long iterationsNumber = Long.valueOf(getTestPropertyValue("example.jagger.load.scenario.termination.iterations"));
74  Long maxDurationInSeconds = Long.valueOf(getTestPropertyValue("example.jagger.load.scenario.termination.max.duration.seconds"));
76  .of(IterationsNumber.of(iterationsNumber), MaxDurationInSeconds.of(maxDurationInSeconds));
77 
78  JLoadProfile jLoadProfileRps = JLoadProfileRps
80  .withMaxLoadThreads(10)
82  .build();
83 
84  // For standard metrics use JMetricName.
85  // JLimitVsRefValue is used to compare the results with the referenced value.
87  // the threshold is relative.
88  .withOnlyWarnings(LowWarnThresh.of(0.99), UpWarnThresh.of(1.01))
89  .build();
90 
91  // For standard metrics use JMetricName.
92  // JLimitVsBaseline is used to compare the results with the baseline.
93  // Use 'chassis.engine.e1.reporting.session.comparison.baseline.session.id' to set baseline.
95  // the threshold is relative.
96  .withOnlyErrors(LowErrThresh.of(0.99), UpErrThresh.of(1.00001))
97  .build();
98 
99  // For standard metrics use JMetricName.
100  // JMetricName.PERF_LATENCY_PERCENTILE is used to set limits for latency percentile metrics.
101  JLimit latencyPercentileLimit = JLimitVsRefValue.builder(JMetricName.PERF_LATENCY_PERCENTILE(95D), RefValue.of(0.1D))
102  // the threshold is relative.
103  .withOnlyWarnings(LowWarnThresh.of(0.50), UpWarnThresh.of(1.5))
104  .build();
105 
106 
107  JLoadTest jLoadTest = JLoadTest
108  .builder(Id.of("exampleJaggerLoadTest"), jTestDefinition, jLoadProfileRps, jTerminationCriteria)
109  .addListener(new CollectThreadsTestListener())
110  .withLimits(successRateLimit, throughputLimit, latencyPercentileLimit)
111  .build();
112 
113  JParallelTestsGroup jParallelTestsGroup = JParallelTestsGroup
114  .builder(Id.of("exampleJaggerParallelTestsGroup"), jLoadTest)
115  .addListener(new ExampleTestGroupListener())
116  .build();
117 
118  // For JLoadScenario which is supposed to be executed by Jagger its ID must be set to 'jagger.load.scenario.id.to.execute' property's value
119  return JLoadScenario.builder(Id.of("exampleJaggerLoadScenario"), jParallelTestsGroup)
120  .addListener(new ExampleLoadScenarioListener())
121  .withLatencyPercentiles(Arrays.asList(10D, 25.5D, 42D, 95D))
122  .build();
123  }
124  // end: following section is used for docu generation - Detailed load test scenario configuration
125 
126  @Bean
128  JTestDefinition description = JTestDefinition
129  .builder(Id.of("myFirstJaggerTestDefinition"), new ExampleEndpointsProvider())
130  // optional
131  .withComment("no comments")
132  .withQueryProvider(new ExampleQueriesProvider())
134  .build();
135 
136  JLoadProfile load = JLoadProfileRps.builder(RequestsPerSecond.of(10)).withMaxLoadThreads(10).withWarmUpTimeInMilliseconds(10000).build();
137  JLoadProfile load2 = JLoadProfileRps.builder(RequestsPerSecond.of(20)).withMaxLoadThreads(20).withWarmUpTimeInMilliseconds(20000).build();
138 
141 
142  JLoadTest test1 = JLoadTest.builder(Id.of("my_first_test"), description, load, termination).build();
143  JLoadTest test2 = JLoadTest.builder(Id.of("yet_another_test"), description, load2, terminationBackground).build();
144 
145  JParallelTestsGroup testGroup = JParallelTestsGroup.builder(Id.of("my_first_test_group"), test1, test2).build();
146 
147  return JLoadScenario.builder(Id.of("myFirstJaggerLoadScenario"), testGroup).build();
148  }
149 }