Commit Graph

24928 Commits

Author SHA1 Message Date
Arjen Poutsma b5b51e73fc Merge branch '5.3.x' 2022-08-30 12:18:51 +02:00
Arjen Poutsma 4c0ece944a Fix race condition in PartGenerator
This commit fixes a race condition in PartGenerator, used by
DefaultPartHttpMessageReader. The condition can occur when a
completion signal comes in, and the state is changed to IdleFileState
at the same time.

Closes gh-28963
2022-08-30 12:11:22 +02:00
Sam Brannen 0ebc86c1af Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java
#	spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java
2022-08-28 18:48:21 +02:00
Sam Brannen 2c75eb8745 Support @Nested tests in MockServerContainerContextCustomizerFactory
Prior to this commit, MockServerContainerContextCustomizerFactory did
not find @WebAppConfiguration on an enclosing class and therefore
failed to create a MockServerContainerContextCustomizer for a @Nested
test class.

This commit addresses this by using TestContextAnnotationUtils to
determine if the test class is "annotated" with @WebAppConfiguration.

Closes gh-29037
2022-08-28 18:41:27 +02:00
Sam Brannen c24e98e51b Avoid reflection for instantiating MockServerContainerContextCustomizer
Since MockServerContainerContextCustomizerFactory already has a
`webSocketPresent` check, there should be no need to instantiate
MockServerContainerContextCustomizer via reflection.

See gh-29028
Closes gh-29035
2022-08-28 18:09:05 +02:00
Sam Brannen 92b582701e Skip ContextCustomizerFactory that cannot be loaded
With this commit, if a ContextCustomizerFactory cannot be loaded due to
a ClassNotFoundException or NoClassDefFoundError, we skip it and log a
DEBUG message.

This aligns with the "skipping" logic already in place for
TestExecutionListeners.

Closes gh-29034
2022-08-28 18:09:05 +02:00
Sam Brannen ab20a189c5 Consistent logging for skipped TestExecutionListeners
With this commit we now log an identical message (without a stack
trace) for a TestExecutionListener skipped due to a
ClassNotFoundException like we already do for a listener skipped due to
a NoClassDefFoundError.
2022-08-28 18:09:05 +02:00
Sam Brannen 7f88f315a4 Introduce logging for ContextCustomizer[Factory] to improve diagnostics
Prior to this commit, we logged which default TestExecutionListeners
were discovered and which listeners were used, but we did not log
anything for ContextCustomizerFactory and ContextCustomizer.

This commit therefore introduces similar logging for
ContextCustomizerFactory and ContextCustomizer to improve diagnostics.

Closes gh-29036
2022-08-28 18:08:12 +02:00
Sam Brannen aa7ef79478 Apply "instanceof pattern matching" in spring-test 2022-08-28 17:51:52 +02:00
Sam Brannen b50415062b Clean up warnings and polish tests
This commit also modifies ResourceWebHandlerTests.getResourceFromFileSystem()
so that it passes in the IDE.
2022-08-26 15:20:16 +02:00
Sam Brannen e53c7ae6f5 Polish Javadoc and internals of the TestContext framework 2022-08-26 13:53:10 +02:00
Sam Brannen c32ff17821 Revise @Nullable declarations in the TestContext framework 2022-08-26 12:21:47 +02:00
Sébastien Deleuze d16fa82888 Remove remaining native build-time class initializations
See oracle/graal#4673 related issue.

Closes gh-29018
2022-08-26 09:29:17 +02:00
Sébastien Deleuze 3e9b57106e Refine TypeHint.Builder#onReachableType Javadoc 2022-08-26 08:35:18 +02:00
Sébastien Deleuze 08f636b691 Introduce TypeHint.Builder#onReachableType(Class<?>)
Closes gh-29017
2022-08-26 08:34:54 +02:00
Sam Brannen 7671d29899 Add missing @Nullable declaration in AotTestMappings 2022-08-25 16:53:54 +02:00
Sam Brannen 593bd064e1 Polishing 2022-08-25 13:23:04 +02:00
Sam Brannen d467db4b9e Make TestClassScanner and TestContextAotGenerator public
This commit makes TestClassScanner and TestContextAotGenerator public so
that the Spring Boot team can take over implementation of the
TestAotProcessor to integrate it into the AOT and native build plugins.
2022-08-25 12:03:11 +02:00
Arjen Poutsma 626739d93f Polishing 2022-08-25 11:31:47 +02:00
Arjen Poutsma 9c33d2707a Introduce support for Netty 5 Buffer
This commit introduces support for Netty 5's Buffer, in the form of
Netty5DataBuffer. Because of the new API offered by Buffer, several
changes have been made to the DataBuffer API:

- CloseableDataBuffer is a simpler alternative to PooledDataBuffer, and
  implemented by Netty5DataBuffer. DataBufferUtils::release can now
  handle CloseableDataBuffer as well as PooledDataBuffer.
- PooledDataBuffer::touch has been moved into a separate interface:
  TouchableDataBuffer, which is implemented by Netty5DataBuffer.
- The capacity of DataBuffers can no longer be reduced, they can only
  grow larger. As a consequence, DataBuffer::capacity(int) has been
  deprecated, but ensureWritable (formally ensureCapacity) still exists.
- DataBuffer::slice and retainedSlice have been deprecated in favor of
  split, a new method that ensures that memory regions do not overlap.
- DataBuffer::asByteBuffer has been deprecated in favor of toByteBuffer,
  a new method that returns a copy, instead of shared data.
- DataBufferFactory::allocateBuffer has been deprecated in favor of
  allocateBuffer(int).

Closes gh-28874
2022-08-25 11:00:22 +02:00
Stephane Nicoll 8a61866ee2 Harmonize registration of reflection hints
Closes gh-29011
2022-08-24 19:34:12 +02:00
Stephane Nicoll 7ca57b7e80 Use consistent registration API in TypeHint.Builder
This commit adapts the registration of fields, constructors, and methods
to provide the same convenience than the reflection-based one available
in ReflectionHints.

See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll 5aa8583159 Add shortcut to register an executable with a mode
See gh-29011
2022-08-24 19:32:02 +02:00
Stephane Nicoll c164b918c0 Apply consistent RuntimeHints defaults
This commit harmonizes the registration of an executable so that
the default method and the method that takes an empty customizer
produces the same hint. The same applies to the readable flag of
a field hint.

Rather than returning a list of executable modes, the "highest" mode
is retained.

See gh-29011
2022-08-24 19:32:01 +02:00
Sam Brannen 019785a72e Introduce CLI for triggering AOT test context processing
This commit introduces TestAotProcessor which replaces
ProcessTestsAheadOfTimeCommand, removes the dependency on picocli, and
aligns with the implementation of the AotProcessor in Spring Boot.

TestAotProcessor is a command-line application (CLI) that scans the
provided classpath roots for Spring integration test classes and then
generates AOT artifacts for those test classes in the provided output
directories.

This CLI is only intended to be used by build tools.

Closes gh-28825
2022-08-24 17:12:34 +02:00
Sam Brannen 5115deb5e3 Introduce CLI for triggering AOT test context processing
This commit introduces ProcessTestsAheadOfTimeCommand, a command-line
application (CLI) that scans the provided classpath roots for Spring
integration test classes and then generates AOT artifacts for those
test classes in the provided output directories.

This CLI is only intended to be used by build tools.

Closes gh-28825
2022-08-23 16:39:59 +02:00
Sam Brannen feb2a30910 Improve precondition checks in TestClassScanner 2022-08-23 16:03:06 +02:00
Stephane Nicoll 41e8683781 Polish 2022-08-23 14:41:32 +02:00
Stephane Nicoll 560f53dbf7 Polish 2022-08-23 14:34:20 +02:00
Stephane Nicoll c6bcf79c0e Add hint for use of Qualifier in meta-annotations
Closes gh-29000
2022-08-23 14:31:09 +02:00
Sébastien Deleuze 2f920e8fb3 Polish JacksonModulesRuntimeHints
Closes gh-29001
2022-08-23 13:49:53 +02:00
Sam Brannen 8a6c1ba198 Introduce AOT run-time support in the TestContext framework
This commit introduces initial AOT run-time support in the Spring
TestContext Framework.

- DefaultCacheAwareContextLoaderDelegate: when running in AOT mode, now
  loads a test's ApplicationContext via the AotContextLoader SPI
  instead of via the standard SmartContextLoader and ContextLoader SPIs.

- DependencyInjectionTestExecutionListener: when running in AOT mode,
  now injects dependencies into a test instance using a local instance
  of AutowiredAnnotationBeanPostProcessor instead of relying on
  AutowireCapableBeanFactory support.

Closes gh-28205
2022-08-23 13:41:24 +02:00
Sam Brannen ada0880f3c Introduce AotTestMappings and AotTestMappingsCodeGenerator
TestContextAotGenerator now uses AotTestMappingsCodeGenerator to
generate a AotTestMappings__Generated.java class which is loaded in
AotTestMappings via reflection in order to retrieve access to
ApplicationContextIntializers generated during AOT processing.

Furthermore, the processAheadOfTimeAndGenerateAotTestMappings() method
in TestContextAotGeneratorTests now performs a rather extensive test
including:

- emulating TestClassScanner to find test classes
- processing all test classes and generating ApplicationContextIntializers
- generating mappings for AotTestMappings
- compiling all generated code
- loading AotTestMappings
- using AotTestMappings to instantiate the generated ApplicationContextIntializer
- using the AotContextLoader API to load the AOT-optimized ApplicationContext
- asserting the behavior of the loaded ApplicationContext

See gh-28205
Closes gh-28204
2022-08-23 13:41:16 +02:00
Sam Brannen b0d65709ac Test XML, Web, & @TestPropertySource AOT support
See gh-28204, gh-28205
2022-08-23 13:41:07 +02:00
Sam Brannen 84c377965c Introduce AotContextLoader SPI in the TestContext framework
This commit introduces a dedicated AotContextLoader extension of
SmartContextLoader and reverts the recent changes to the existing
contract for SmartContextLoader. This allows existing
SmartContextLoader implementations to continue working unaffected by
AOT support unless they opt into AOT support by explicitly implementing
the new AotContextLoader contract.

In addition, existing SmartContextLoader implementations in the
spring-test module have been modified to implement AotContextLoader
instead of SmartContextLoader. This allows the core framework to
provide built-in AOT support in the TestContext framework, and it also
allows third-party extensions to built-in SmartContextLoaders to
participate in AOT processing and run-time support transparently (or at
least as transparent as possible).

Closes gh-28906
2022-08-23 13:40:58 +02:00
Sam Brannen c1a6bfc701 Introduce initial support for processing test contexts ahead-of-time
This commit introduces TestContextAotGenerator for processing Spring
integration test classes and generating AOT artifacts. Specifically,
this class performs the following.

- bootstraps the TCF for a given test class
- builds the MergedContextConfiguration for each test class and tracks
  all test classes that share the same MergedContextConfiguration
- loads each test ApplicationContext without refreshing it
- passes the test ApplicationContext to ApplicationContextAotGenerator
  to generate the AOT optimized ApplicationContextInitializer
  - The GenerationContext passed to ApplicationContextAotGenerator uses
    a feature name of the form "TestContext###_", where "###" is a
    3-digit sequence ID left padded with zeros.

This commit also includes tests using the TestCompiler to verify that
each generated ApplicationContextInitializer can be used to populate a
GenericApplicationContext as expected.

See gh-28204
2022-08-23 13:40:48 +02:00
Sébastien Deleuze 0973348bde Add classpath checks to JacksonModulesRuntimeHints
Closes gh-29001
2022-08-23 12:55:26 +02:00
Sébastien Deleuze 5525b17f19 Add missing condition in JacksonModulesRuntimeHints
Closes gh-29001
2022-08-23 12:11:42 +02:00
Stephane Nicoll 56551032e3 Merge pull request #28355 from ben-enfuse-io
* pr/28355:
  Treat MariaDB as an independent database type

Closes gh-28355
2022-08-23 07:46:28 +02:00
ben-enfuse-io 21577c4777 Treat MariaDB as an independent database type
See gh-28355
2022-08-23 07:44:02 +02:00
Stephane Nicoll 455715899d Infer proxy on `@Lazy`-annotated injection points
This commit makes use of the new `getLazyResolutionProxyClass` on
`AutowireCandidateResolver` to detect if a injection point requires
a proxy.

Closes gh-28980
2022-08-22 20:48:02 +02:00
Sam Brannen e5f9bb76b1 Declare covariant return type in DefaultGenerationContext.withName()
Prior to this commit, if infrastructure code working directly with an
instance of DefaultGenerationContext invoked withName() on that
instance, the new GenerationContext had to be cast from
GenerationContext to DefaultGenerationContext in order for the
infrastructure to continue working with the DefaultGenerationContext
API -- for example, the writeGeneratedContent() method which is not
defined in the GenerationContext API.

This commit makes use of a covariant return type by declaring that
DefaultGenerationContext.withName() returns a DefaultGenerationContext.
2022-08-22 16:41:20 +02:00
Sam Brannen 9ab046bdbb Introduce complete DefaultGenerationContext constructor
Prior to this commit, it was possible to create a DefaultGenerationContext
based on a ClassNameGenerator and GeneratedFiles; however, there was no way
to create a DefaultGenerationContext that reused an existing RuntimeHints
instance which is necessary in certain use cases -- for example, in the
TestContext framework where multiple GenerationContexts are created
based on shared instances of GeneratedFiles and RuntimeHints.

This commit addresses this by introducing a public
DefaultGenerationContext(ClassNameGenerator,GeneratedFiles,RuntimeHints)
constructor.
2022-08-22 16:41:11 +02:00
Stephane Nicoll 40de029bf8 Polish 2022-08-22 16:32:53 +02:00
Juergen Hoeller 4eb84a0537 Introduce getLazyResolutionProxyClass mechanism in AutowireCandidateResolver SPI
See gh-28980
2022-08-22 16:24:37 +02:00
Stephane Nicoll 8a51e31069 Make sure that AnnotationAwareOrderComparator is configured with AOT
Closes gh-28988
2022-08-22 14:18:42 +02:00
Juergen Hoeller 9b2a40a3bc Lazy Validator resolution in MethodValidationPostProcessor
Closes gh-28990
2022-08-22 14:07:42 +02:00
Sébastien Deleuze daf2d940e4 Remove specific JDK dynamic proxy configuration
Further refinements will be required for
MethodValidationPostProcessor since @Lazy
used by Spring Boot is not supported yet
for that use case.

See gh-28980
2022-08-22 10:53:12 +02:00
Sébastien Deleuze ebf6de8f5d Infer JDK dynamic proxies for Spring beans
See gh-28980
2022-08-22 07:58:15 +02:00
Sam Brannen a9466437c8 Merge branch '5.3.x'
# Conflicts:
#	spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java
2022-08-21 15:23:33 +02:00