4747 * }
4848 * </pre>
4949 */
50- public class SmokeTestInstrumentationExtension extends InstrumentationExtension
50+ public class SmokeTestInstrumentationExtension < T > extends InstrumentationExtension
5151 implements TelemetryRetrieverProvider {
5252
5353 private final TestContainerManager containerManager = createContainerManager ();
@@ -61,12 +61,7 @@ public class SmokeTestInstrumentationExtension extends InstrumentationExtension
6161
6262 private final AutoCleanupExtension autoCleanup = AutoCleanupExtension .create ();
6363
64- @ FunctionalInterface
65- public interface GetTargetImage {
66- String getTargetImage (String jdk , String serverVersion , boolean windows );
67- }
68-
69- private final GetTargetImage getTargetImage ;
64+ private final Function <T , String > getTargetImage ;
7065 private final String [] command ;
7166 private final String jvmArgsEnvVarName ;
7267 private final boolean setServiceName ;
@@ -77,7 +72,7 @@ public interface GetTargetImage {
7772 private final Duration telemetryTimeout ;
7873
7974 private SmokeTestInstrumentationExtension (
80- GetTargetImage getTargetImage ,
75+ Function < T , String > getTargetImage ,
8176 String [] command ,
8277 String jvmArgsEnvVarName ,
8378 boolean setServiceName ,
@@ -146,17 +141,13 @@ public Set<String> getSpanTraceIds() {
146141 return spans ().stream ().map (SpanData ::getTraceId ).collect (Collectors .toSet ());
147142 }
148143
149- public SmokeTestOutput start (int jdk ) {
150- return start (String .valueOf (jdk ), null , false );
151- }
152-
153- public SmokeTestOutput start (String jdk , String serverVersion , boolean windows ) {
144+ public SmokeTestOutput start (T arg ) {
154145 autoCleanup .deferCleanup (() -> containerManager .stopTarget ());
155146
156147 return new SmokeTestOutput (
157148 this ,
158149 containerManager .startTarget (
159- getTargetImage .getTargetImage ( jdk , serverVersion , windows ),
150+ getTargetImage .apply ( arg ),
160151 agentPath ,
161152 jvmArgsEnvVarName ,
162153 extraEnv ,
@@ -172,16 +163,12 @@ public TelemetryRetriever getTelemetryRetriever() {
172163 return telemetryRetriever ;
173164 }
174165
175- public static Builder builder (Function <String , String > getTargetImage ) {
176- return builder ((jdk , serverVersion , windows ) -> getTargetImage .apply (jdk ));
177- }
178-
179- public static Builder builder (GetTargetImage getTargetImage ) {
180- return new Builder (getTargetImage );
166+ public static <T > Builder <T > builder (Function <T , String > getTargetImage ) {
167+ return new Builder <T >(getTargetImage );
181168 }
182169
183- public static Builder springBoot (String imageTag ) {
184- return builder (
170+ public static Builder < Integer > springBoot (String imageTag ) {
171+ return new Builder < Integer > (
185172 jdk ->
186173 String .format (
187174 "ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-spring-boot:jdk%s-%s" ,
@@ -197,8 +184,8 @@ private static TestContainerManager createContainerManager() {
197184 : new LinuxTestContainerManager ();
198185 }
199186
200- public static class Builder {
201- private final GetTargetImage getTargetImage ;
187+ public static class Builder < T > {
188+ private final Function < T , String > getTargetImage ;
202189 private String [] command ;
203190 private String jvmArgsEnvVarName = "JAVA_TOOL_OPTIONS" ;
204191 private boolean setServiceName = true ;
@@ -208,68 +195,68 @@ public static class Builder {
208195 private List <Integer > extraPorts = List .of ();
209196 private Duration telemetryTimeout = Duration .ofSeconds (30 );
210197
211- private Builder (GetTargetImage getTargetImage ) {
198+ private Builder (Function < T , String > getTargetImage ) {
212199 this .getTargetImage = getTargetImage ;
213200 }
214201
215202 /** Sets the command to run in the target container. */
216203 @ CanIgnoreReturnValue
217- public Builder command (String ... command ) {
204+ public Builder < T > command (String ... command ) {
218205 this .command = command ;
219206 return this ;
220207 }
221208
222209 /** Sets the environment variable name used to pass JVM arguments to the target application. */
223210 @ CanIgnoreReturnValue
224- public Builder jvmArgsEnvVarName (String jvmArgsEnvVarName ) {
211+ public Builder < T > jvmArgsEnvVarName (String jvmArgsEnvVarName ) {
225212 this .jvmArgsEnvVarName = jvmArgsEnvVarName ;
226213 return this ;
227214 }
228215
229216 /** Enables or disables setting the default service name for the target application. */
230217 @ CanIgnoreReturnValue
231- public Builder setServiceName (boolean setServiceName ) {
218+ public Builder < T > setServiceName (boolean setServiceName ) {
232219 this .setServiceName = setServiceName ;
233220 return this ;
234221 }
235222
236223 /** Adds an environment variable to the target application's environment. */
237224 @ CanIgnoreReturnValue
238- public Builder env (String key , String value ) {
225+ public Builder < T > env (String key , String value ) {
239226 this .extraEnv .put (key , value );
240227 return this ;
241228 }
242229
243230 /** Specifies additional files to copy to the target container. */
244231 @ CanIgnoreReturnValue
245- public Builder extraResources (ResourceMapping ... resources ) {
232+ public Builder < T > extraResources (ResourceMapping ... resources ) {
246233 this .extraResources = List .of (resources );
247234 return this ;
248235 }
249236
250237 /** Sets the wait strategy for the target container startup. */
251238 @ CanIgnoreReturnValue
252- public Builder waitStrategy (@ Nullable TargetWaitStrategy waitStrategy ) {
239+ public Builder < T > waitStrategy (@ Nullable TargetWaitStrategy waitStrategy ) {
253240 this .waitStrategy = waitStrategy ;
254241 return this ;
255242 }
256243
257244 /** Specifies additional ports to expose from the target container. */
258245 @ CanIgnoreReturnValue
259- public Builder extraPorts (Integer ... ports ) {
246+ public Builder < T > extraPorts (Integer ... ports ) {
260247 this .extraPorts = List .of (ports );
261248 return this ;
262249 }
263250
264251 /** Sets the timeout duration for retrieving telemetry data. */
265252 @ CanIgnoreReturnValue
266- public Builder telemetryTimeout (Duration telemetryTimeout ) {
253+ public Builder < T > telemetryTimeout (Duration telemetryTimeout ) {
267254 this .telemetryTimeout = telemetryTimeout ;
268255 return this ;
269256 }
270257
271- public SmokeTestInstrumentationExtension build () {
272- return new SmokeTestInstrumentationExtension (
258+ public SmokeTestInstrumentationExtension < T > build () {
259+ return new SmokeTestInstrumentationExtension < T > (
273260 getTargetImage ,
274261 command ,
275262 jvmArgsEnvVarName ,
0 commit comments