11package io .quarkus .test .junit ;
22
3- import static io .quarkus .deployment .util .ContainerRuntimeUtil .detectContainerRuntime ;
43import static io .quarkus .runtime .configuration .QuarkusConfigBuilderCustomizer .QUARKUS_PROFILE ;
54import static io .quarkus .test .common .PathTestHelper .getAppClassLocationForTestLocation ;
65import static io .quarkus .test .common .PathTestHelper .getTestClassesLocation ;
2524
2625import jakarta .inject .Inject ;
2726
28- import org .apache .commons .lang3 .RandomStringUtils ;
29- import org .eclipse .microprofile .config .ConfigProvider ;
3027import org .eclipse .microprofile .config .inject .ConfigProperty ;
3128import org .eclipse .microprofile .config .spi .ConfigSource ;
3229import org .jboss .jandex .Index ;
4643import io .quarkus .deployment .builditem .DevServicesLauncherConfigResultBuildItem ;
4744import io .quarkus .deployment .builditem .DevServicesNetworkIdBuildItem ;
4845import io .quarkus .deployment .builditem .DevServicesRegistryBuildItem ;
49- import io .quarkus .deployment .util .ContainerRuntimeUtil ;
5046import io .quarkus .paths .PathList ;
5147import io .quarkus .runtime .LaunchMode ;
5248import io .quarkus .runtime .logging .LoggingSetupRecorder ;
5854import io .quarkus .test .common .http .TestHTTPResourceManager ;
5955import io .quarkus .test .config .ValueRegistryInjector ;
6056import io .quarkus .value .registry .ValueRegistry ;
61- import io .smallrye .common .process .ProcessBuilder ;
6257import io .smallrye .config .SmallRyeConfig ;
6358
6459public final class IntegrationTestUtil {
@@ -235,7 +230,6 @@ public void accept(String configProfile) {
235230
236231 Map <String , String > propertyMap = new HashMap <>();
237232 AugmentAction augmentAction ;
238- String networkId = null ;
239233 if (isDockerAppLaunch ) {
240234 // when the application is going to be launched as a docker container, we need to make containers started by DevServices
241235 // use a shared network that the application container can then use as well
@@ -254,55 +248,8 @@ public void accept(String s, String s2) {
254248 }, DevServicesLauncherConfigResultBuildItem .class .getName (), DevServicesNetworkIdBuildItem .class .getName (),
255249 DevServicesRegistryBuildItem .class .getName (), DevServicesCustomizerBuildItem .class .getName ());
256250
257- networkId = propertyMap .get ("quarkus.test.container.network" );
258- boolean manageNetwork = false ;
259- if (isDockerAppLaunch ) {
260- if (networkId == null ) {
261- // use the network the use has specified or else just generate one if none is configured
262- Optional <String > networkIdOpt = ConfigProvider .getConfig ().getOptionalValue (
263- "quarkus.test.container.network" , String .class );
264- if (networkIdOpt .isPresent ()) {
265- networkId = networkIdOpt .get ();
266- } else {
267- networkId = "quarkus-integration-test-" + RandomStringUtils .insecure ().next (5 , true , false );
268- manageNetwork = true ;
269- }
270- }
271- }
272-
273- DefaultDevServicesLaunchResult result = new DefaultDevServicesLaunchResult (propertyMap , networkId , manageNetwork ,
274- curatedApplication );
275- createNetworkIfNecessary (result );
276- return result ;
277- }
278-
279- // this probably isn't the best place for this method, but we need to create the docker container before
280- // user code is aware of the network
281- private static void createNetworkIfNecessary (
282- final ArtifactLauncher .InitContext .DevServicesLaunchResult devServicesLaunchResult ) {
283- if (devServicesLaunchResult .manageNetwork () && (devServicesLaunchResult .networkId () != null )) {
284- ContainerRuntimeUtil .ContainerRuntime containerRuntime = detectContainerRuntime (true );
285-
286- try {
287- ProcessBuilder .exec (containerRuntime .getExecutableName (), "network" , "create" ,
288- devServicesLaunchResult .networkId ());
289- // do the cleanup in a shutdown hook because there might be more services (launched via QuarkusTestResourceLifecycleManager) connected to the network
290- Runtime .getRuntime ().addShutdownHook (new Thread (new Runnable () {
291- @ Override
292- public void run () {
293- try {
294- ProcessBuilder .exec (containerRuntime .getExecutableName (), "network" , "rm" ,
295- devServicesLaunchResult .networkId ());
296- } catch (Exception e ) {
297- System .out .printf ("Unable to delete container network '%s'" , devServicesLaunchResult .networkId ());
298- }
299- }
300- }));
301- } catch (Exception e ) {
302- throw new RuntimeException ("Creating container network '%s' completed unsuccessfully"
303- .formatted (devServicesLaunchResult .networkId ()), e );
304- }
305- }
251+ String networkId = propertyMap .get ("quarkus.test.container.network" );
252+ return new DefaultDevServicesLaunchResult (propertyMap , networkId , curatedApplication );
306253 }
307254
308255 static void activateLogging () {
@@ -323,14 +270,12 @@ static void activateLogging() {
323270 static class DefaultDevServicesLaunchResult implements ArtifactLauncher .InitContext .DevServicesLaunchResult {
324271 private final Map <String , String > properties ;
325272 private final String networkId ;
326- private final boolean manageNetwork ;
327273 private final CuratedApplication curatedApplication ;
328274
329275 DefaultDevServicesLaunchResult (Map <String , String > properties , String networkId ,
330- boolean manageNetwork , CuratedApplication curatedApplication ) {
276+ CuratedApplication curatedApplication ) {
331277 this .properties = properties ;
332278 this .networkId = networkId ;
333- this .manageNetwork = manageNetwork ;
334279 this .curatedApplication = curatedApplication ;
335280 }
336281
@@ -344,7 +289,7 @@ public String networkId() {
344289
345290 @ Override
346291 public boolean manageNetwork () {
347- return manageNetwork ;
292+ return false ;
348293 }
349294
350295 @ Override
0 commit comments