Skip to content

Commit

Permalink
Reduce stack utilization of TestTemplateTestDescriptor::execute (#4024)
Browse files Browse the repository at this point in the history
By getting rid of outer Stream API call.

Resolves #4020.
  • Loading branch information
amaembo authored Sep 25, 2024
1 parent ee104a3 commit 8491772
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import org.apiguardian.api.API;
import org.junit.jupiter.api.extension.ExtensionContext;
Expand Down Expand Up @@ -100,14 +101,14 @@ public JupiterEngineExecutionContext execute(JupiterEngineExecutionContext conte
List<TestTemplateInvocationContextProvider> providers = validateProviders(extensionContext,
context.getExtensionRegistry());
AtomicInteger invocationIndex = new AtomicInteger();
// @formatter:off
providers.stream()
.flatMap(provider -> provider.provideTestTemplateInvocationContexts(extensionContext))
.map(invocationContext -> createInvocationTestDescriptor(invocationContext, invocationIndex.incrementAndGet()))
.filter(Optional::isPresent)
.map(Optional::get)
.forEach(invocationTestDescriptor -> execute(dynamicTestExecutor, invocationTestDescriptor));
// @formatter:on
for (TestTemplateInvocationContextProvider provider : providers) {
try (Stream<TestTemplateInvocationContext> stream = provider.provideTestTemplateInvocationContexts(
extensionContext)) {
stream.forEach(invocationContext -> createInvocationTestDescriptor(invocationContext,
invocationIndex.incrementAndGet()).ifPresent(
invocationTestDescriptor -> execute(dynamicTestExecutor, invocationTestDescriptor)));
}
}
validateWasAtLeastInvokedOnce(invocationIndex.get(), providers);
return context;
}
Expand Down

0 comments on commit 8491772

Please sign in to comment.