|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.testcontainers.lifecycle; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 21 | +import org.testcontainers.containers.PostgreSQLContainer; |
| 22 | +import org.testcontainers.junit.jupiter.Container; |
| 23 | + |
| 24 | +import org.springframework.boot.test.system.CapturedOutput; |
| 25 | +import org.springframework.boot.test.system.OutputCaptureExtension; |
| 26 | +import org.springframework.boot.testcontainers.context.ImportTestcontainers; |
| 27 | +import org.springframework.boot.testcontainers.lifecycle.TestContainersParallelStartupWithImportTestcontainersIntegrationTests.Containers; |
| 28 | +import org.springframework.boot.testsupport.testcontainers.DisabledIfDockerUnavailable; |
| 29 | +import org.springframework.boot.testsupport.testcontainers.DockerImageNames; |
| 30 | +import org.springframework.test.annotation.DirtiesContext; |
| 31 | +import org.springframework.test.context.TestPropertySource; |
| 32 | +import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 33 | + |
| 34 | +import static org.assertj.core.api.Assertions.assertThat; |
| 35 | + |
| 36 | +/** |
| 37 | + * Integration test for parallel startup. |
| 38 | + * |
| 39 | + * @author Phillip Webb |
| 40 | + */ |
| 41 | +@ExtendWith(SpringExtension.class) |
| 42 | +@TestPropertySource(properties = "spring.testcontainers.beans.startup=parallel") |
| 43 | +@DirtiesContext |
| 44 | +@DisabledIfDockerUnavailable |
| 45 | +@ExtendWith(OutputCaptureExtension.class) |
| 46 | +@ImportTestcontainers(Containers.class) |
| 47 | +public class TestContainersParallelStartupWithImportTestcontainersIntegrationTests { |
| 48 | + |
| 49 | + @Test |
| 50 | + void startsInParallel(CapturedOutput out) { |
| 51 | + assertThat(out).contains("-lifecycle-0").contains("-lifecycle-1").contains("-lifecycle-2"); |
| 52 | + } |
| 53 | + |
| 54 | + static class Containers { |
| 55 | + |
| 56 | + @Container |
| 57 | + static PostgreSQLContainer<?> container1 = new PostgreSQLContainer<>(DockerImageNames.postgresql()); |
| 58 | + |
| 59 | + @Container |
| 60 | + static PostgreSQLContainer<?> container2 = new PostgreSQLContainer<>(DockerImageNames.postgresql()); |
| 61 | + |
| 62 | + @Container |
| 63 | + static PostgreSQLContainer<?> container3 = new PostgreSQLContainer<>(DockerImageNames.postgresql()); |
| 64 | + |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments