Commit Graph

107 Commits

Author SHA1 Message Date
Andy Wilkinson
654016af7f Move Docker-related test support into a separate module
See gh-41228
2024-06-26 19:47:35 +01:00
Andy Wilkinson
6fbf08fa9a Update spring-boot-docker-compose to use docker-test plugin
See gh-41228
2024-06-26 19:46:03 +01:00
Andy Wilkinson
3f1f801461 Update spring-boot-testcontainers to use docker-test plugin
See gh-41228
2024-06-26 19:45:52 +01:00
Phillip Webb
712d935c8e Fix checkstyle violation
See gh-35786
2024-06-25 22:16:03 -07:00
Phillip Webb
eef4c3c2c0 Allow TestcontainersLifecycleBeanPostProcessor to detect scoped beans
Update `TestcontainersLifecycleBeanPostProcessor` so that scoped beans
are included.

Fixes gh-35786
2024-06-25 22:00:34 -07:00
Andy Wilkinson
491f34d25c Improve container test code
Replace `DockerImageNames` with a enum and relocate it from the
`testcontainers` to `container` package. The enum now also
becomes a common location that we can use to apply container
configuration such as timeouts.

Closes gh-41164

Co-authored-by: Phillip Webb <phil.webb@broadcom.com>
2024-06-19 20:10:03 -07:00
Andy Wilkinson
138307c13c Disable test context cache in spring-boot-testcontainers
Closes gh-41124
2024-06-17 11:43:00 +01:00
Ahmed Ashour
207327d97c Use method references when possible in test code
See gh-40974
2024-06-11 12:58:00 -07:00
Phillip Webb
ecc9a2352d Polish "Use constructor rather than Collection.addAll"
See gh-41053
2024-06-11 10:02:27 -07:00
Piyal Ahmed
17adcfc180 Use constructor rather than Collection.addAll
See gh-41053
2024-06-11 09:39:45 -07:00
Andy Wilkinson
35fb54a4d3 Polish deprecation notice 2024-05-22 17:02:29 +01:00
Andy Wilkinson
d340f87c22 Disable test when Docker is not available
See gh-40585
2024-05-22 09:58:23 +01:00
Andy Wilkinson
468e246dbb Make sure container's started before connection details use it
Prior to this commit, a Testcontainer that was managed as a bean
would not have been started in time if it was accessed before
the bean factory's configuration had been frozen. A common way
for this to occur is when using JPA. The entity manager factory
bean is LoadTimeWeaverAware which causes it to be created before
configuration is frozen. Creating this bean requires the DataSource
which in turn requires the JdbcConnectionDetails and its JDBC URL.
Getting the JDBC URL From the connection details requires the
container hosting the SQL database to have been started.

This commit updates ContainerConnectionDetails, the super-class for
all Testcontainer-based ConnectionDetails implementations, to publish
an event when the Container is retrieved from the details. When this
event is published, TestcontainersLifecycleBeanPostProcessor
initializes all containers that are defined as beans.

Closes gh-40585
2024-05-22 09:15:21 +01:00
Andy Wilkinson
f440f2c3ac Merge branch '3.1.x' into 3.2.x
Closes gh-40834
2024-05-20 13:12:03 +01:00
Andy Wilkinson
f5262d89df Add missing Testcontainers service connection tests
Closes gh-35039
2024-05-20 13:02:24 +01:00
Scott Frederick
3e2d151c0e Merge branch '3.1.x' into 3.2.x
Closes gh-40508
2024-04-24 15:08:50 -05:00
Scott Frederick
f210d83062 Don't reuse Testcontainers containers if reuse is globally disabled
Fixes gh-39609
2024-04-24 14:37:59 -05:00
Phillip Webb
12de6aa46a Merge branch '3.1.x' into 3.2.x 2024-02-21 15:27:27 -08:00
Moritz Halbritter
4387b79831 Merge branch '3.1.x' into 3.2.x 2024-02-12 10:18:46 +01:00
Moritz Halbritter
8ffcfc9b77 Harmonize style of igored exceptions across the codebase 2024-02-12 10:14:20 +01:00
Scott Frederick
6b453cedf6 Merge branch '3.1.x' into 3.2.x
Closes gh-39449
2024-02-07 16:49:29 -06:00
Amrit
67ba829d9e Fix typo in TestcontainersPropertySource assertion
See gh-39440
2024-02-07 16:45:39 -06:00
Andy Wilkinson
61ca87f7a4 Polish "Prevent double registration of event publisher registrar"
See gh-39297
2024-01-30 16:02:38 +00:00
tish
50c44e301a Prevent double registration of event publisher registrar
See gh-39297
2024-01-30 15:59:05 +00:00
Phillip Webb
cff8cb98c7 Merge branch '3.1.x' into 3.2.x 2024-01-22 12:20:24 -08:00
Phillip Webb
88a8550609 Make OTEL tstcontainers integration test more resilient
Tweak awaitility assertions to fix timing error that often occurs on
local builds.
2024-01-16 10:49:25 -08:00
Phillip Webb
89874d351a Ensure containers are started before binding datasource properties
Update `TestcontainersLifecycleBeanPostProcessor` so that containers
are now initialized either on the first `postProcessAfterInitialization`
call with a frozen configuration or just before a test container
property is supplied.

Prior to this commit, it was assumed that the first post-process call
after the configuration was frozen was suitably early to initialize
the containers. This turns out to not be no always the case.

Specifically, in the `finishBeanFactoryInitialization` method of
`AbstractApplicationContext` we see that `LoadTimeWeaverAware` beans
are obtained before the configuration is frozen. One such bean is
`DefaultPersistenceUnitManager` which is likely to need datasource
properties that will require a started container.

To fix the problem, the `TestcontainersPropertySource` now publishes
a `BeforeTestcontainersPropertySuppliedEvent` to the ApplicationContext
just before any value is supplied. By listening for this event, we can
ensure that containers are initialized and started before any dynamic
property is read.

Fixes gh-38913
2024-01-16 10:36:54 -08:00
Andy Wilkinson
7087897507 Merge branch '3.1.x' into 3.2.x
Closes gh-39091
2024-01-11 10:33:57 +00:00
Phillip Webb
5354ad15b3 Merge branch '3.1.x'
Closes gh-38877
2023-12-19 22:51:48 -08:00
Yanming Zhou
d3a51e56b7 Remove unnecessary static modifiers
See gh-38739
2023-12-19 22:38:08 -08:00
Phillip Webb
561c7f749b Don't start containers imported via @ImportTestcontainers
Remove early start of containers imported via `@ImportTestcontainers`
so that parallel startup can happen.

Fixes gh-38831
2023-12-17 15:22:28 -08:00
Phillip Webb
6ae113c18a Fix parallel startup of testcontainers
Update `TestcontainersLifecycleBeanPostProcessor` so that containers
can actually be started in parallel.

Prior to this commit, `initializeStartables` would collect beans
and in the process trigger the `postProcessAfterInitialization` method
on each bean. This would see that  `startablesInitialized` was `true`
and call `startableBean.start` directly. The result of this was that
beans were actually started sequentially and when the `start` method
was finally called it had nothing to do.

The updated code uses an enum rather than a boolean so that the
`postProcessAfterInitialization` method no longer attempts to start
beans unless `initializeStartables` has finished.

Fixes gh-38831
2023-12-16 21:57:16 -08:00
Phillip Webb
6c3dec42e0 Add container support for Oracle Free which replaces Oracle XE
Update Docker Compose and Testcontainers support to work with
`gvenzl/oracle-free` which replaces `gvenzl/oracle-xe`.

Closes gh-38476
2023-11-21 11:51:59 -08:00
Phillip Webb
3a32e4e913 Merge branch '3.1.x'
Closes gh-38405
2023-11-20 16:27:46 -08:00
Phillip Webb
f68df82b30 Support lenient ContainerConnectionDetailsFactory hint registration
Update `ContainerConnectionDetailsFactory` hint registration logic
so that types are optional on the classpath.

See gh-36606
Fixes gh-38392
2023-11-20 16:26:22 -08:00
Phillip Webb
663243e60c Fix open telemetry container lifecycle issues
Mark test as `@DirtiesContext` so that the context is closed before
the container.

Closes gh-38176
2023-11-01 18:16:38 -07:00
Phillip Webb
0c66db7b18 Refine container initialization and parallel startup logic
Update `TestcontainersLifecycleBeanPostProcessor` to restore early
container initialization logic and refine startup logic. Initial bean
access now again triggers the creation all container beans. In addition
the first access of a `Startable` bean now attempts to find and start
all other `Startable` beans.

Fixes gh-37989
2023-10-25 11:58:22 -07:00
Moritz Halbritter
ddf6b3f23b Merge branch '3.1.x'
Closes gh-38014
2023-10-25 10:26:02 +02:00
Moritz Halbritter
73685d1d02 Register required class names for reflection in Testcontainer factory
Closes gh-36606
2023-10-25 10:25:42 +02:00
Phillip Webb
343046d30c Polish 2023-10-19 10:55:26 +01:00
Phillip Webb
fcb75b6a1e Search implemented interfaces on superclass for @ServiceConnection
Refine original fix to also search interfaces on the superclass.

Fixes gh-37671
2023-10-19 10:52:19 +01:00
Moritz Halbritter
55dc2963ef Rename Testcontainers bean startup property
Old name: spring.testcontainers.startup
New name: spring.testcontainers.beans.startup

Closes gh-37073
2023-10-19 09:22:27 +02:00
Phillip Webb
4c3a0f09d7 Support parallel initialization of Testcontainers
Add support for a `spring.testcontainers.startup` property that can
be set to "sequential" or "parallel" to change how containers are
started.

Closes gh-37073
2023-10-14 23:58:25 -07:00
Phillip Webb
efd9aa9b64 Polish 2023-10-14 19:51:42 -07:00
Phillip Webb
e01e4f1912 Search implemented interfaces on superclass for @ServiceConnection
Refine original fix to also search interfaces on the superclass.

Fixes gh-37671
2023-10-14 19:43:41 -07:00
Johnny Lim
446677375e Polish gh-35082
See gh-37831
2023-10-12 14:17:02 +02:00
Scott Frederick
bd6606fa39 Merge branch '3.1.x'
Closes gh-37799
2023-10-09 15:42:32 -05:00
Scott Frederick
86216fb4e9 Search implemented interfaces for @ServiceConnection fields
Fixes gh-37671
2023-10-09 15:37:42 -05:00
Phillip Webb
052757c2d8 Polish 2023-09-27 20:58:09 -07:00
Moritz Halbritter
3dd6372602 Polish "Add service connection from OpenTelemetry Collector"
See gh-35082
2023-09-14 11:10:19 +02:00