Merge branch '2.3.x'

Closes gh-22636
pull/22637/head
Andy Wilkinson 4 years ago
commit 7aa093e0ca

@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -149,7 +150,7 @@ class ConfigurationPropertySourcesTests {
@Test // gh-21416 @Test // gh-21416
void descendantOfPropertyAccessWhenMutableWithCacheShouldBePerformant() { void descendantOfPropertyAccessWhenMutableWithCacheShouldBePerformant() {
StandardEnvironment environment = createPerformanceTestEnvironment(true); Function<StandardEnvironment, Long> descendantOfPerformance = (environment) -> {
Iterable<ConfigurationPropertySource> sources = ConfigurationPropertySources.get(environment); Iterable<ConfigurationPropertySource> sources = ConfigurationPropertySources.get(environment);
ConfigurationPropertyName missing = ConfigurationPropertyName.of("missing"); ConfigurationPropertyName missing = ConfigurationPropertyName.of("missing");
long start = System.nanoTime(); long start = System.nanoTime();
@ -158,8 +159,13 @@ class ConfigurationPropertySourcesTests {
assertThat(source.containsDescendantOf(missing)).isEqualTo(ConfigurationPropertyState.ABSENT); assertThat(source.containsDescendantOf(missing)).isEqualTo(ConfigurationPropertyState.ABSENT);
} }
} }
long total = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
assertThat(total).isLessThan(1000); };
StandardEnvironment environment = createPerformanceTestEnvironment(false);
long baseline = descendantOfPerformance.apply(environment);
ConfigurationPropertyCaching.get(environment).enable();
long cached = descendantOfPerformance.apply(environment);
assertThat(cached).isLessThan(baseline / 2);
} }
private long testPropertySourcePerformance(boolean immutable) { private long testPropertySourcePerformance(boolean immutable) {

Loading…
Cancel
Save