Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
JLoadScenarioProvider.java
Go to the documentation of this file.
1 package ${package}.simple.examples;
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.loadbalancer.JLoadBalancer;
34 import com.griddynamics.jagger.user.test.configurations.termination.JTerminationCriteria;
35 import com.griddynamics.jagger.user.test.configurations.termination.JTerminationCriteriaBackground;
36 import com.griddynamics.jagger.user.test.configurations.termination.JTerminationCriteriaIterations;
37 import com.griddynamics.jagger.user.test.configurations.termination.auxiliary.IterationsNumber;
38 import com.griddynamics.jagger.user.test.configurations.termination.auxiliary.MaxDurationInSeconds;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.Configuration;
41 import ${package}.util.JaggerPropertiesProvider;
42 
43 import static com.griddynamics.jagger.user.test.configurations.loadbalancer.JLoadBalancer.DefaultLoadBalancer.ROUND_ROBIN;
44 
45 import java.util.Arrays;
46 
47 // begin: following section is used for docu generation - Detailed load test scenario configuration
48 
54 @Configuration
56 
57  @Bean
59 
60  // Example of using JaggerPropertiesProvider
61  String testDefinitionComment = getTestPropertyValue("example.jagger.test.definition.comment");
62 
63  JTestDefinition jTestDefinition = JTestDefinition
64  .builder(Id.of("exampleJaggerTestDefinition"), new EndpointsProvider())
65  // optional
66  .withComment(testDefinitionComment)
68  .withQueryProvider(new QueriesProvider())
69  .withLoadBalancer(JLoadBalancer.builder(ROUND_ROBIN).withRandomSeed(42).build())
70  .addValidator(new ExampleResponseValidatorProvider("we are always good"))
72  .addListener(new NotNullInvocationListener())
73  .build();
74 
75  // Example of using JaggerPropertiesProvider
76  Long iterationsNumber = Long.valueOf(getTestPropertyValue("example.jagger.load.scenario.termination.iterations"));
77  Long maxDurationInSeconds = Long.valueOf(getTestPropertyValue("example.jagger.load.scenario.termination.max.duration.seconds"));
79  .of(IterationsNumber.of(iterationsNumber), MaxDurationInSeconds.of(maxDurationInSeconds));
80 
81  JLoadProfile jLoadProfileRps = JLoadProfileRps
83  .withMaxLoadThreads(10)
85  .build();
86 
87  // For standard metrics use JMetricName.
88  // JLimitVsRefValue is used to compare the results with the referenced value.
90  // the threshold is relative.
91  .withOnlyWarnings(LowWarnThresh.of(0.99), UpWarnThresh.of(1.01))
92  .build();
93 
94  // For standard metrics use JMetricName.
95  // JLimitVsBaseline is used to compare the results with the baseline.
96  // Use 'chassis.engine.e1.reporting.session.comparison.baseline.session.id' to set baseline.
98  // the threshold is relative.
99  .withOnlyErrors(LowErrThresh.of(0.99), UpErrThresh.of(1.00001))
100  .build();
101 
102  // For standard metrics use JMetricName.
103  // JMetricName.PERF_LATENCY_PERCENTILE is used to set limits for latency percentile metrics.
104  JLimit latencyPercentileLimit = JLimitVsRefValue.builder(JMetricName.PERF_LATENCY_PERCENTILE(95D), RefValue.of(0.1D))
105  // the threshold is relative.
106  .withOnlyWarnings(LowWarnThresh.of(0.50), UpWarnThresh.of(1.5))
107  .build();
108 
109 
110  JLoadTest jLoadTest = JLoadTest
111  .builder(Id.of("exampleJaggerLoadTest"), jTestDefinition, jLoadProfileRps, jTerminationCriteria)
112  .addListener(new CollectThreadsTestListener())
113  .withLimits(successRateLimit, throughputLimit, latencyPercentileLimit)
114  .build();
115 
116  JParallelTestsGroup jParallelTestsGroup = JParallelTestsGroup
117  .builder(Id.of("exampleJaggerParallelTestsGroup"), jLoadTest)
118  .addListener(new ExampleTestGroupListener())
119  .build();
120 
121  // 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
122  return JLoadScenario.builder(Id.of("exampleJaggerLoadScenario"), jParallelTestsGroup)
123  .addListener(new ExampleLoadScenarioListener())
124  .withLatencyPercentiles(Arrays.asList(10D, 25.5D, 42D, 95D))
125  .build();
126  }
127  // end: following section is used for docu generation - Detailed load test scenario configuration
128 
129  @Bean
131  JTestDefinition description = JTestDefinition
132  .builder(Id.of("myFirstJaggerTestDefinition"), new EndpointsProvider())
133  // optional
134  .withComment("no comments")
135  .withQueryProvider(new QueriesProvider())
137  .build();
138 
139  JLoadProfile load = JLoadProfileRps.builder(RequestsPerSecond.of(10)).withMaxLoadThreads(10).withWarmUpTimeInMilliseconds(10000).build();
140  JLoadProfile load2 = JLoadProfileRps.builder(RequestsPerSecond.of(20)).withMaxLoadThreads(20).withWarmUpTimeInMilliseconds(20000).build();
141 
144 
145  JLoadTest test1 = JLoadTest.builder(Id.of("my_first_test"), description, load, termination).build();
146  JLoadTest test2 = JLoadTest.builder(Id.of("yet_another_test"), description, load2, terminationBackground).build();
147 
148  JParallelTestsGroup testGroup = JParallelTestsGroup.builder(Id.of("my_first_test_group"), test1, test2).build();
149 
150  return JLoadScenario.builder(Id.of("myFirstJaggerLoadScenario"), testGroup).build();
151  }
152 }