Class TestBootstrapState
Renovations Phase 2 (multi-context schema-drop bug): Spring's TestContext cache reuses an
ApplicationContext across test classes that share the same @ContextConfiguration,
but builds a new ApplicationContext when the configuration shape differs. Each new
ApplicationContext bootstraps a fresh createDatabaseInitializer → sessionFactory →
dataSourceInitializer chain, which previously meant:
- The test DB was dropped and recreated (wiping tables for every other still-cached EntityManagerFactory).
- Hibernate's
hbm2ddl.auto=createdropped and recreated tables again (further wiping the still-cached EMFs' view of the schema). init-*.sqlre-ran (primary-key collisions or wasted I/O).
This class is the centralised gate: every member is a once-per-JVM toggle. Components consult it to decide whether to run destructive bootstrap work or skip because an earlier context already paid the cost.
The flags survive across Spring ApplicationContext lifecycles because they live on a
classloader-static AtomicBoolean; a fresh JVM (i.e. a fresh Surefire/Failsafe fork)
starts with all flags false, so each forked test JVM still gets a clean DB on first boot.
- Author:
- phase2-bot
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanAtomically claim the right to (drop and) create the test database.static booleanAtomically claim the right to seed initial data.static booleanAtomically claim the right to run the schema-extras populator (ACL seed INSERTs, indices, additional tables defined insql/init-acls.sql+sql/init-entities.sql+sql/<vendor>/init-entities.sql).static booleanAtomically claim the right to let Hibernate materialize the schema (viahbm2ddl=create).static voidReset all flags.
-
Method Details
-
claimDatabaseCreation
public static boolean claimDatabaseCreation()Atomically claim the right to (drop and) create the test database.- Returns:
- true if the caller is the first claimant and should perform the work; false if a prior caller already did it.
-
claimDataSeeding
public static boolean claimDataSeeding()Atomically claim the right to seed initial data.- Returns:
- true if the caller is the first claimant and should run the SQL scripts; false if a prior caller already did it.
-
claimSchemaMaterialization
public static boolean claimSchemaMaterialization()Atomically claim the right to let Hibernate materialize the schema (viahbm2ddl=create).- Returns:
- true if the caller is the first claimant and should keep
hbm2ddl=create; false if a prior caller already materialized the schema and the EMF should downgrade tonone.
-
claimSchemaExtras
public static boolean claimSchemaExtras()Atomically claim the right to run the schema-extras populator (ACL seed INSERTs, indices, additional tables defined insql/init-acls.sql+sql/init-entities.sql+sql/<vendor>/init-entities.sql).- Returns:
- true on the first caller; false thereafter.
-
resetForTesting
public static void resetForTesting()Reset all flags. Intended for tests of the bootstrap chain itself; do not call from production paths.
-