4444public class SmokeTestInstrumentationExtension extends InstrumentationExtension
4545 implements TelemetryRetrieverProvider {
4646
47- // todo timeout configuration
48- // todo move builder docs to builder methods
49-
5047 private final TestContainerManager containerManager = createContainerManager ();
5148
5249 private TelemetryRetriever telemetryRetriever ;
@@ -70,6 +67,7 @@ public interface GetTargetImage {
7067 private final List <ResourceMapping > extraResources ;
7168 private final TargetWaitStrategy waitStrategy ;
7269 private final List <Integer > extraPorts ;
70+ private final Duration telemetryTimeout ;
7371
7472 private SmokeTestInstrumentationExtension (
7573 GetTargetImage getTargetImage ,
@@ -79,7 +77,8 @@ private SmokeTestInstrumentationExtension(
7977 Map <String , String > extraEnv ,
8078 List <ResourceMapping > extraResources ,
8179 TargetWaitStrategy waitStrategy ,
82- List <Integer > extraPorts ) {
80+ List <Integer > extraPorts ,
81+ Duration telemetryTimeout ) {
8382 super (new SmokeTestRunner ());
8483 this .getTargetImage = getTargetImage ;
8584 this .command = command ;
@@ -89,6 +88,7 @@ private SmokeTestInstrumentationExtension(
8988 this .extraResources = extraResources ;
9089 this .waitStrategy = waitStrategy ;
9190 this .extraPorts = extraPorts ;
91+ this .telemetryTimeout = telemetryTimeout ;
9292 }
9393
9494 public WebClient client () {
@@ -98,7 +98,8 @@ public WebClient client() {
9898 @ Override
9999 public void beforeAll (ExtensionContext context ) throws Exception {
100100 containerManager .startEnvironmentOnce ();
101- telemetryRetriever = new TelemetryRetriever (containerManager .getBackendMappedPort ());
101+ telemetryRetriever =
102+ new TelemetryRetriever (containerManager .getBackendMappedPort (), telemetryTimeout );
102103 super .beforeAll (context );
103104 }
104105
@@ -124,67 +125,26 @@ public SmokeTestOutput start(int jdk) {
124125 }
125126
126127 public SmokeTestOutput start (String jdk , String serverVersion , boolean windows ) {
127- String targetImage = getTargetImage (jdk , serverVersion , windows );
128128 autoCleanup .deferCleanup (() -> containerManager .stopTarget ());
129129
130130 return new SmokeTestOutput (
131131 containerManager .startTarget (
132- targetImage ,
132+ getTargetImage . getTargetImage ( jdk , serverVersion , windows ) ,
133133 agentPath ,
134- getJvmArgsEnvVarName () ,
135- getExtraEnv () ,
136- getSetServiceName () ,
137- getExtraResources () ,
138- getExtraPorts () ,
139- getWaitStrategy () ,
140- getCommand () ));
134+ jvmArgsEnvVarName ,
135+ extraEnv ,
136+ setServiceName ,
137+ extraResources ,
138+ extraPorts ,
139+ waitStrategy ,
140+ command ));
141141 }
142142
143143 @ Override
144144 public TelemetryRetriever getTelemetryRetriever () {
145145 return telemetryRetriever ;
146146 }
147147
148- public String getTargetImage (String jdk , String serverVersion , boolean windows ) {
149- return getTargetImage .getTargetImage (jdk , serverVersion , windows );
150- }
151-
152- public String [] getCommand () {
153- return command ;
154- }
155-
156- /** Subclasses can override this method to pass jvm arguments in another environment variable */
157- public String getJvmArgsEnvVarName () {
158- return jvmArgsEnvVarName ;
159- }
160-
161- /** Subclasses can override this method to customise target application's environment */
162- public Map <String , String > getExtraEnv () {
163- return extraEnv ;
164- }
165-
166- /** Subclasses can override this method to disable setting default service name */
167- public boolean getSetServiceName () {
168- return setServiceName ;
169- }
170-
171- /** Subclasses can override this method to provide additional files to copy to target container */
172- public List <ResourceMapping > getExtraResources () {
173- return extraResources ;
174- }
175-
176- /**
177- * Subclasses can override this method to provide additional ports that should be exposed from the
178- * target container
179- */
180- public List <Integer > getExtraPorts () {
181- return extraPorts ;
182- }
183-
184- public TargetWaitStrategy getWaitStrategy () {
185- return waitStrategy ;
186- }
187-
188148 public static Builder builder (Function <String , String > getTargetImage ) {
189149 return builder ((jdk , serverVersion , windows ) -> getTargetImage .apply (jdk ));
190150 }
@@ -219,53 +179,68 @@ public static class Builder {
219179 private List <ResourceMapping > extraResources = List .of ();
220180 private TargetWaitStrategy waitStrategy ;
221181 private List <Integer > extraPorts = List .of ();
182+ private Duration telemetryTimeout = Duration .ofSeconds (30 );
222183
223184 private Builder (GetTargetImage getTargetImage ) {
224185 this .getTargetImage = getTargetImage ;
225186 }
226187
188+ /** Sets the command to run in the target container. */
227189 @ CanIgnoreReturnValue
228190 public Builder command (String ... command ) {
229191 this .command = command ;
230192 return this ;
231193 }
232194
195+ /** Sets the environment variable name used to pass JVM arguments to the target application. */
233196 @ CanIgnoreReturnValue
234197 public Builder jvmArgsEnvVarName (String jvmArgsEnvVarName ) {
235198 this .jvmArgsEnvVarName = jvmArgsEnvVarName ;
236199 return this ;
237200 }
238201
202+ /** Enables or disables setting the default service name for the target application. */
239203 @ CanIgnoreReturnValue
240204 public Builder setServiceName (boolean setServiceName ) {
241205 this .setServiceName = setServiceName ;
242206 return this ;
243207 }
244208
209+ /** Adds an environment variable to the target application's environment. */
245210 @ CanIgnoreReturnValue
246211 public Builder env (String key , String value ) {
247212 this .extraEnv .put (key , value );
248213 return this ;
249214 }
250215
216+ /** Specifies additional files to copy to the target container. */
251217 @ CanIgnoreReturnValue
252218 public Builder extraResources (ResourceMapping ... resources ) {
253219 this .extraResources = List .of (resources );
254220 return this ;
255221 }
256222
223+ /** Sets the wait strategy for the target container startup. */
257224 @ CanIgnoreReturnValue
258225 public Builder waitStrategy (@ Nullable TargetWaitStrategy waitStrategy ) {
259226 this .waitStrategy = waitStrategy ;
260227 return this ;
261228 }
262229
230+ /** Specifies additional ports to expose from the target container. */
263231 @ CanIgnoreReturnValue
264232 public Builder extraPorts (Integer ... ports ) {
265233 this .extraPorts = List .of (ports );
266234 return this ;
267235 }
268236
237+ /** Sets the timeout duration for retrieving telemetry data. */
238+ @ CanIgnoreReturnValue
239+ public Builder telemetryTimeout (Duration telemetryTimeout ) {
240+ this .telemetryTimeout = telemetryTimeout ;
241+ return this ;
242+ }
243+
269244 public SmokeTestInstrumentationExtension build () {
270245 return new SmokeTestInstrumentationExtension (
271246 getTargetImage ,
@@ -275,7 +250,8 @@ public SmokeTestInstrumentationExtension build() {
275250 extraEnv ,
276251 extraResources ,
277252 waitStrategy ,
278- extraPorts );
253+ extraPorts ,
254+ telemetryTimeout );
279255 }
280256 }
281257}
0 commit comments