- Notifications
You must be signed in to change notification settings - Fork560
Create a single LauncherSession for invocations of JUnitPlatformProvider#863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
olamy merged 1 commit intoapache:masterfrommarcphilipp:junit-platform-launcher-session-reductionJul 4, 2025
+270 −194
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Create a single LauncherSession for invocations of JUnitPlatformProvider
Prior to this commit, `JUnitPlatformProvider` created multiple`LauncherSessions` for some executions, for example when `forkTestSet`was `null` or when rerunning failed tests. This caused registered`LauncherSessionListeners` registered via `ServiceLoader` on the JUnitPlatform to be called multiple times. As they are intended to set up andtear down resources, this had the potential of unnecessarily slowingdown test execution.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitcdf9d9909ab1d7d23008fb6ae67295a6c7ea0fd0
There are no files selected for viewing
68 changes: 25 additions & 43 deletions...platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions...latform/src/main/java/org/apache/maven/surefire/junitplatform/LauncherSessionAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.surefire.junitplatform; | ||
| import org.junit.platform.launcher.Launcher; | ||
| /** | ||
| * Launcher proxy which delays the most possible the initialization of the real JUnit | ||
| * Launcher in order to avoid stream/stdout corruption due to early logging. | ||
| */ | ||
| interface LauncherSessionAdapter extends AutoCloseable { | ||
| Launcher getLauncher(); | ||
| @Override | ||
| void close(); | ||
| } |
83 changes: 83 additions & 0 deletions...latform/src/main/java/org/apache/maven/surefire/junitplatform/LauncherSessionFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.surefire.junitplatform; | ||
| import org.apache.maven.surefire.api.util.ReflectionUtils; | ||
| import org.apache.maven.surefire.api.util.SurefireReflectionException; | ||
| import org.junit.platform.launcher.Launcher; | ||
| import org.junit.platform.launcher.core.LauncherFactory; | ||
| interface LauncherSessionFactory { | ||
| LauncherSessionFactory DEFAULT = () -> { | ||
| try { | ||
| Class<?> sessionClass = Class.forName("org.junit.platform.launcher.LauncherSession"); | ||
| AutoCloseable launcherSession = ReflectionUtils.invokeGetter(LauncherFactory.class, null, "openSession"); | ||
| return new SupportedLauncherSessionAdapter(sessionClass, launcherSession); | ||
| } catch (ClassNotFoundException e) { | ||
| return new LegacyLauncherSessionAdapter(LauncherFactory.create()); | ||
| } | ||
| }; | ||
| LauncherSessionAdapter openSession(); | ||
| class SupportedLauncherSessionAdapter implements LauncherSessionAdapter { | ||
| private final Class<?> sessionClass; | ||
| private final AutoCloseable launcherSession; | ||
| SupportedLauncherSessionAdapter(Class<?> sessionClass, AutoCloseable launcherSession) { | ||
| this.sessionClass = sessionClass; | ||
| this.launcherSession = launcherSession; | ||
| } | ||
| @Override | ||
| public Launcher getLauncher() { | ||
| return ReflectionUtils.invokeGetter(sessionClass, launcherSession, "getLauncher"); | ||
| } | ||
| @Override | ||
| public void close() { | ||
| try { | ||
| launcherSession.close(); | ||
| } catch (Exception e) { | ||
| throw new SurefireReflectionException(e); | ||
| } | ||
| } | ||
| } | ||
| class LegacyLauncherSessionAdapter implements LauncherSessionAdapter { | ||
| private final Launcher launcher; | ||
| LegacyLauncherSessionAdapter(Launcher launcher) { | ||
| this.launcher = launcher; | ||
| } | ||
| @Override | ||
| public Launcher getLauncher() { | ||
| return launcher; | ||
| } | ||
| @Override | ||
| public void close() { | ||
| // do nothing | ||
| } | ||
| } | ||
| } |
85 changes: 0 additions & 85 deletions...re-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/LazyLauncher.java
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
50 changes: 50 additions & 0 deletions...src/test/java/org/apache/maven/surefire/junitplatform/ConcreteLauncherSessionAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.surefire.junitplatform; | ||
| import org.junit.platform.launcher.Launcher; | ||
| import org.junit.platform.launcher.LauncherSession; | ||
| import org.junit.platform.launcher.TestExecutionListener; | ||
| import org.junit.platform.launcher.core.LauncherConfig; | ||
| import org.junit.platform.launcher.core.LauncherFactory; | ||
| class ConcreteLauncherSessionAdapter implements LauncherSessionAdapter { | ||
| private final LauncherSession launcherSession; | ||
| public static LauncherSessionFactory createLauncherSessionWithListeners(TestExecutionListener... listeners) { | ||
| LauncherConfig launcherConfig = | ||
| LauncherConfig.builder().addTestExecutionListeners(listeners).build(); | ||
| return () -> new ConcreteLauncherSessionAdapter(LauncherFactory.openSession(launcherConfig)); | ||
| } | ||
| ConcreteLauncherSessionAdapter(LauncherSession launcherSession) { | ||
| this.launcherSession = launcherSession; | ||
| } | ||
| @Override | ||
| public Launcher getLauncher() { | ||
| return launcherSession.getLauncher(); | ||
| } | ||
| @Override | ||
| public void close() { | ||
| launcherSession.close(); | ||
| } | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.