From 68a0eede586620b88ab45ae82f338db8fdd6b368 Mon Sep 17 00:00:00 2001 From: Daniel Garnier-Moiroux Date: Thu, 5 Jun 2025 14:10:08 +0200 Subject: [PATCH] Make integration tests faster by making the @Configuration lazy --- .../cloudfoundry/IntegrationTestConfiguration.java | 14 ++++++++++++++ .../org/cloudfoundry/client/v2/BlobstoresTest.java | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java index 1aff721143..12571face1 100644 --- a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java +++ b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java @@ -82,12 +82,14 @@ import org.cloudfoundry.util.ResourceUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Lazy; import org.springframework.core.io.ClassPathResource; import org.springframework.util.StringUtils; import reactor.core.publisher.Flux; @@ -95,6 +97,15 @@ import reactor.util.function.Tuple2; import reactor.util.function.Tuples; +/** + * Default configuration class for ALL integration tests. + *

+ * Some beans are annotated as {@link Lazy}, meaning that they will only be initialized + * if a test class actually uses them through {@link Autowired} injection. This allows us + * to declare some CF applications as beans, but only push them when they are actually + * used by the class under tests. This makes our tests faster, as pushing an app can take + * several minutes. + */ @Configuration @EnableAutoConfiguration public class IntegrationTestConfiguration { @@ -460,6 +471,7 @@ Version serverVersion(@Qualifier("admin") CloudFoundryClient cloudFoundryClient) .block(); } + @Lazy @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") Mono serviceBrokerId( @@ -572,6 +584,7 @@ Mono stackName(CloudFoundryClient cloudFoundryClient) { .cache(); } + @Lazy @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") Mono testLogCacheApp( @@ -608,6 +621,7 @@ String testLogCacheAppName(NameFactory nameFactory) { return nameFactory.getApplicationName(); } + @Lazy @Bean TestLogCacheEndpoints testLogCacheEndpoints( ConnectionContext connectionContext, diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java index ea0855e004..f9368a0730 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java @@ -18,17 +18,24 @@ import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; +import org.cloudfoundry.ApplicationUtils; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.blobstores.DeleteBlobstoreBuildpackCachesRequest; import org.cloudfoundry.util.JobUtils; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Mono; import reactor.test.StepVerifier; public final class BlobstoresTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; + // The buildpacks cache needs to be non-empty for the DELETE call to succeed. + // We pull the "testLogCacheApp" bean, which ensures the bean will be initialized, + // the app will be pushed, and it will add some data to the cache. + @Autowired private Mono testLogCacheApp; + @Test public void delete() { this.cloudFoundryClient