Skip to content

Commit 450afff

Browse files
committed
Make integration tests faster by making the @configuration lazy
1 parent 407330d commit 450afff

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,30 @@
8282
import org.cloudfoundry.util.ResourceUtils;
8383
import org.slf4j.Logger;
8484
import org.slf4j.LoggerFactory;
85+
import org.springframework.beans.factory.annotation.Autowired;
8586
import org.springframework.beans.factory.annotation.Qualifier;
8687
import org.springframework.beans.factory.annotation.Value;
8788
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8889
import org.springframework.context.annotation.Bean;
8990
import org.springframework.context.annotation.Configuration;
9091
import org.springframework.context.annotation.DependsOn;
92+
import org.springframework.context.annotation.Lazy;
9193
import org.springframework.core.io.ClassPathResource;
9294
import org.springframework.util.StringUtils;
9395
import reactor.core.publisher.Flux;
9496
import reactor.core.publisher.Mono;
9597
import reactor.util.function.Tuple2;
9698
import reactor.util.function.Tuples;
9799

100+
/**
101+
* Default configuration class for ALL integration tests.
102+
* <p>
103+
* Some beans are annotated as {@link Lazy}, meaning that they will only be initialized
104+
* if a test class actually uses them through {@link Autowired} injection. This allows us
105+
* to declare some CF applications as beans, but only push them when they are actually
106+
* used by the class under tests. This makes our tests faster, as pushing an app can take
107+
* several minutes.
108+
*/
98109
@Configuration
99110
@EnableAutoConfiguration
100111
public class IntegrationTestConfiguration {
@@ -460,6 +471,7 @@ Version serverVersion(@Qualifier("admin") CloudFoundryClient cloudFoundryClient)
460471
.block();
461472
}
462473

474+
@Lazy
463475
@Bean(initMethod = "block")
464476
@DependsOn("cloudFoundryCleaner")
465477
Mono<String> serviceBrokerId(
@@ -572,6 +584,7 @@ Mono<String> stackName(CloudFoundryClient cloudFoundryClient) {
572584
.cache();
573585
}
574586

587+
@Lazy
575588
@Bean(initMethod = "block")
576589
@DependsOn("cloudFoundryCleaner")
577590
Mono<ApplicationUtils.ApplicationMetadata> testLogCacheApp(
@@ -608,6 +621,7 @@ String testLogCacheAppName(NameFactory nameFactory) {
608621
return nameFactory.getApplicationName();
609622
}
610623

624+
@Lazy
611625
@Bean
612626
TestLogCacheEndpoints testLogCacheEndpoints(
613627
ConnectionContext connectionContext,

integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818

1919
import java.time.Duration;
2020
import org.cloudfoundry.AbstractIntegrationTest;
21+
import org.cloudfoundry.ApplicationUtils;
2122
import org.cloudfoundry.client.CloudFoundryClient;
2223
import org.cloudfoundry.client.v2.blobstores.DeleteBlobstoreBuildpackCachesRequest;
2324
import org.cloudfoundry.util.JobUtils;
2425
import org.junit.jupiter.api.Test;
2526
import org.springframework.beans.factory.annotation.Autowired;
27+
import reactor.core.publisher.Mono;
2628
import reactor.test.StepVerifier;
2729

2830
public final class BlobstoresTest extends AbstractIntegrationTest {
2931

3032
@Autowired private CloudFoundryClient cloudFoundryClient;
3133

34+
// The buildpacks cache needs to be non-empty for the DELETE call to succeed.
35+
// We pull the "testLogCacheApp" bean, which ensures the bean will be initialized,
36+
// the app will be pushed, and it will add some data to the cache.
37+
@Autowired private Mono<ApplicationUtils.ApplicationMetadata> testLogCacheApp;
38+
3239
@Test
3340
public void delete() {
3441
this.cloudFoundryClient

0 commit comments

Comments
 (0)