GH-587 - Avoid repeated lookup of ApplicationModules in ApplicationModulesRuntime.

This commit is contained in:
Oliver Drotbohm
2024-05-21 00:57:08 +02:00
parent 21bd2cef75
commit e29853fcc7
2 changed files with 36 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import different.moduleB.ModuleBType;
import example.SampleApplication;
import example.moduleA.ModuleAType;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
@@ -49,4 +50,37 @@ public class ApplicationModulesRuntimeIntegrationTests {
Stream.of(ModuleAType.class, ModuleBType.class)
.forEach(it -> assertThat(runtime.isApplicationClass(it)).isTrue());
}
@Test // GH-587
void onlyLooksUpApplicationModulesOnce() {
var context = SpringApplication.run(SampleApplication.class);
var applicationRuntime = new TestSpringBootApplicationRuntime(context);
var supplier = new CountingSupplier<>(() -> modules);
var runtime = new ApplicationModulesRuntime(supplier, applicationRuntime);
runtime.get();
runtime.get();
assertThat(supplier.counter).isEqualTo(1);
}
static class CountingSupplier<T> implements Supplier<T> {
private final Supplier<T> delegate;
private int counter = 0;
CountingSupplier(Supplier<T> delegate) {
this.delegate = delegate;
}
@Override
public T get() {
counter++;
return delegate.get();
}
}
}