Spring Framework 7.1.0-SNAPSHOT ๊ธฐ์ค
spring-core-test๋ ๋ฉ์ธ ์ฐ์ถ๋ฌผ์ด ์๋๋ผ ํ
์คํธ๋ฅผ ๋๋ ๋ชจ๋์ด๋ค. AOT(Ahead-Of-Time)๋ก ์์ฑ๋ ์๋ฐ ์์ค๋ฅผ ๋ฉ๋ชจ๋ฆฌ ์์์ ์ฆ์ ์ปดํ์ผยท๋ก๋ฉํ๊ณ , ๋ฆฌํ๋ ์
/๋ฆฌ์์ค ํธ์ถ์ ๋ฐ์ดํธ์ฝ๋ ์์ค์์ ๊ฐ๋ก์ฑ RuntimeHints ์ค์ ์ด ์ค์ ๋์์ ๋น ์ง์์ด ๋ฎ๋์ง ๊ฒ์ฆํ๋ ๋๊ตฌ ๋ชจ์์ด๋ค.
Spring 6๋ถํฐ ๋์ ๋ AOT ์ฒ๋ฆฌ๋ ๋น๋ ์์ ์ ๋น ์ ์ยทํ๋ก์ยท๋ฆฌํ๋ ์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ์๋ฐ ์์ค ์ฝ๋๋ก ์์ฑํ๋ค. ์ด ์์ฑ๋ ์ฝ๋๊ฐ ์ ๋ง ์ปดํ์ผ๋๊ณ ์๋๋๋ก ๋์ํ๋์ง ๋จ์ ํ ์คํธ์์ ํ์ธํ๋ ค๋ฉด ๋ ๊ฐ์ง๊ฐ ํ์ํ๋ค.
- ์์ฑ๋ ์์ค๋ฅผ ์ค์ ๋ก ์ปดํ์ผํด ํด๋์ค๋ก ๋์ฐ๋ ์๋จ โ ๋์คํฌ์ ํ์ผ์ ์ฐ์ง ์๊ณ , ํ
์คํธ ํด๋์คํจ์ค๋ฅผ ์ค์ผ์ํค์ง ์์ผ๋ฉด์. โ
org.springframework.core.test.tools(TestCompiler). - GraalVM ๋ค์ดํฐ๋ธ ์ด๋ฏธ์ง์์ ํ์ํ
RuntimeHints๊ฐ ๋๋ฝ๋์ง ์์๋์ง ํ์ธํ๋ ์๋จ โ ์ฝ๋๊ฐ ์คํ ์ค ์ค์ ๋ก ์ด๋ค ๋ฆฌํ๋ ์ /๋ฆฌ์์ค/ํ๋ก์๋ฅผ ์ฐ๋์ง ๊ธฐ๋กํ๊ณ , ์ค์ ๋ ํํธ์ ๋์กฐ. โorg.springframework.aot.agent(Java Agent, 7.0์์ deprecated).
์ด ๋ชจ๋์ ์ ๋ ์ถ์ ์ค์ฌ์ผ๋ก, AOT ์์ฑ ๊ฒฐ๊ณผ๋ฅผ ์ปดํ์ผ๋ฌ์ ๋๊ธฐ๋ ์ด๋ํฐ(TestGenerationContext, CompilerFiles)์ SpringFactoriesLoader ๋ชฉ ๊ตฌํ(MockSpringFactoriesLoader)์ ํจ๊ป ์ ๊ณตํ๋ค.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ spring-core-test โ
โ (Premain-Class: RuntimeHintsAgent) โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ api
โผ
โโโโโโโโโโโโโ
โspring-coreโ โ aot.hint / aot.generate / io.support / asm
โโโโโโโโโโโโโ
optional / ์ปดํ์ผ ์ ์ฉ:
assertj-core (AssertJ ๋จ์ธ โ *Assert ํด๋์ค)
junit-jupiter-api (@CompileWithForkedClassLoader, @EnabledIfRuntimeHintsAgent)
junit-platform-launcher (ํฌํฌ๋ ํด๋์ค๋ก๋๋ก ํ
์คํธ ์ฌ์คํ)
qdox (์์ค์์ ํด๋์ค๋ช
ํ์ฑ)
- ์์กดํ๋ ๋ชจ๋:
spring-coreํ๋๋ฟ(api). ๋ด๋ถ์ ์ผ๋กspring-core์org.springframework.asm(ASM ์ฌํจํค์ง),aot.hint,aot.generateํจํค์ง๋ฅผ ์ง์ ์ฌ์ฉํ๋ค. - ์์กด๋ฐ๋ ๋ชจ๋: ํ๋ ์์ํฌ ์ ๋ฐ์ ํ
์คํธ ์ฝ๋. ํนํ
spring-context/spring-beans์ AOT ํ ์คํธ,spring-core์ RuntimeHints ๊ฒ์ฆ ํ ์คํธ.
- 01-๋ชจ๋-์งํ๋.md โ ๋ค ๊ฐ ํจํค์ง๊ฐ ๊ฐ๊ฐ ๋ฌด์์ ์ฑ ์์ง๋๊ฐ, ๋ ๊ฐ์ ํฐ ์ถ
- 02-TestCompiler-๋์ -์ปดํ์ผ.md โ ๋ฉ๋ชจ๋ฆฌ ์์์ ์๋ฐ ์์ค๋ฅผ ์ปดํ์ผยท๋ก๋ฉํ๋ ์์ง
- 03-ํฌํฌ๋-ํด๋์ค๋ก๋-๊ฒฉ๋ฆฌ.md โ
@CompileWithForkedClassLoader๋ก ํด๋์คํจ์ค๋ฅผ ๊ฒฉ๋ฆฌํ๋ ๋ฉ์ปค๋์ฆ - 04-AOT-์์ฑ-ํ
์คํธ-๋ธ๋ฆฌ์ง.md โ
TestGenerationContextยทCompilerFilesยทMockSpringFactoriesLoader - 05-RuntimeHints-Agent.md โ ๋ฐ์ดํธ์ฝ๋ ๊ณ์ธก์ผ๋ก ๋ฆฌํ๋ ์ ํธ์ถ์ ๊ธฐ๋กยท๊ฒ์ฆํ๋ Java Agent
spring-core-test/src/main/java
โ
โโโ org/springframework/core/test/tools/ โ [์ถ 1] ๋์ ์ปดํ์ผ ์์ง
โ โโโ TestCompiler ์ปดํ์ผ ์ง์
์ (๋ถ๋ณ, with* ๋น๋)
โ โโโ Compiled ์ปดํ์ผ ๊ฒฐ๊ณผ + ํด๋์ค ๋ก๋ฉ/์ธ์คํด์คํ
โ โโโ DynamicFile (sealed) โโ SourceFile (.java + ํด๋์ค๋ช
ํ์ฑ)
โ โ โโ ResourceFile (์์ ๋ฆฌ์์ค)
โ โโโ SourceFiles / ResourceFiles / ClassFiles ๋ถ๋ณ ์ปฌ๋ ์
๋ํผ
โ โโโ ClassFile in-memory ๋ฐ์ดํธ์ฝ๋
โ โโโ DynamicJavaFileManager ์ปดํ์ผ ์ฐ์ถ๋ฌผ์ ๋ฉ๋ชจ๋ฆฌ์ ๋ณด๊ด
โ โโโ DynamicClassLoader ์์ฑ๋ ํด๋์ค/๋ฆฌ์์ค๋ฅผ ๋
ธ์ถ
โ โโโ DynamicJavaFileObject / DynamicClassFileObject / DynamicResourceFileObject
โ โโโ *Assert (Source/Resource/DynamicFile) AssertJ ์ง์
โ โโโ CompileWithForkedClassLoader โ [์ถ 1-b] ํด๋์คํจ์ค ๊ฒฉ๋ฆฌ ์ ๋ํ
์ด์
โ โ + ...Extension + ...ClassLoader JUnit ํ์ฅ + ํฌํฌ ํด๋์ค๋ก๋
โ โโโ CompilationException / WritableContent
โ
โโโ org/springframework/aot/test/generate/ โ [์ถ 1-c] AOTโ์ปดํ์ผ๋ฌ ์ด๋ํฐ
โ โโโ TestGenerationContext InMemoryGeneratedFiles ๊ธฐ๋ฐ GenerationContext
โ โโโ CompilerFiles GeneratedFiles โ TestCompiler ๋ณํ
โ
โโโ org/springframework/core/test/io/support/ โ ๊ธฐํ ์ฝ์ด ํ
์คํธ ๋ณด์กฐ
โ โโโ MockSpringFactoriesLoader spring.factories ๋ชฉ ๊ตฌํ
โ
โโโ org/springframework/aot/agent/ โ [์ถ 2] Java Agent (deprecated 7.0)
โ โโโ RuntimeHintsAgent premain ์ง์
์
โ โโโ InvocationsRecorderClassTransformer / ...Visitor ASM ๋ฐ์ดํธ์ฝ๋ ์ฌ์์ฑ
โ โโโ InstrumentedBridgeMethods ๊ณ์ธก๋ JDK ๋ฉ์๋ ๋์ฒด ๊ตฌํ
โ โโโ InstrumentedMethod (enum) ๊ณ์ธก ๋์ + ํํธ ๋งค์ฒ
โ โโโ RecordedInvocation ๊ธฐ๋ก๋ 1ํ ํธ์ถ
โ โโโ RecordedInvocationsPublisher / ...Listener ๋ฆฌ์ค๋ ๋ฐํ
โ โโโ HintType / MethodReference
โ
โโโ org/springframework/aot/test/agent/ โ [์ถ 2-b] Agent ํ
์คํธ API
โโโ RuntimeHintsRecorder record(Runnable) โ ํธ์ถ ์์ง
โโโ RuntimeHintsInvocations + ...Assert AssertJ๋ก ํํธ ๋์กฐ
โโโ EnabledIfRuntimeHintsAgent Agent ๋ฏธ์ ์ฌ ์ ํ
์คํธ ๋นํ์ฑํ