@ -28,7 +28,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify ;
import static org.mockito.Mockito.when ;
class Lts MigrationServiceTest {
class MigrationServiceTest {
private JdbcTemplate jdbcTemplate ;
private InstallScripts installScripts ;
@ -55,24 +55,24 @@ class LtsMigrationServiceTest {
}
/** Records which apply() hooks fired, in order. */
private Lts Migration migration ( String version , List < String > applied ) {
return new Lts Migration( ) {
private Migration migration ( String version , List < String > applied ) {
return new Migration ( ) {
@Override public String getVersion ( ) { return version ; }
@Override public void apply ( ) { applied . add ( version ) ; }
} ;
}
/** Records apply() and applyAfterCommit() calls (distinctly tagged) into a single shared ordered list. */
private Lts Migration migrationWithAfterCommit ( String version , List < String > sequence ) {
return new Lts Migration( ) {
private Migration migrationWithAfterCommit ( String version , List < String > sequence ) {
return new Migration ( ) {
@Override public String getVersion ( ) { return version ; }
@Override public void apply ( ) { sequence . add ( "apply(" + version + ")" ) ; }
@Override public void applyAfterCommit ( ) { sequence . add ( "applyAfterCommit(" + version + ")" ) ; }
} ;
}
private Lts MigrationService service ( List < Lts Migration> migrations ) {
return new Lts MigrationService( jdbcTemplate , installScripts , schemaSettingsService , txManager , migrations ) ;
private MigrationService service ( List < Migration > migrations ) {
return new MigrationService ( jdbcTemplate , installScripts , schemaSettingsService , txManager , migrations ) ;
}
@Test
@ -81,7 +81,7 @@ class LtsMigrationServiceTest {
writeSql ( "4.2.2.3" , "SELECT 1;" ) ;
writeSql ( "4.2.2.4" , "SELECT 2;" ) ;
// intentionally unsorted input; service must sort ascending
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.2.2.4" , applied ) ,
migration ( "4.2.2.2" , applied ) ,
migration ( "4.2.2.3" , applied ) ) ) ;
@ -100,7 +100,7 @@ class LtsMigrationServiceTest {
List < String > applied = new ArrayList < > ( ) ;
writeSql ( "4.2.2.3" , "SELECT 1;" ) ;
writeSql ( "4.2.2.4" , "SELECT 2;" ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.2.2.3" , applied ) , migration ( "4.2.2.4" , applied ) ) ) ;
List < String > appliedVersions = service . applyMigrations ( "4.2.2.2" , "4.2.2.4" , false , ( ) - > { } ) ;
@ -117,7 +117,7 @@ class LtsMigrationServiceTest {
// A cross-family 4.3 -> 4.4 offline upgrade now runs the real in-range 4.3.1.x beans (the source has
// not passed them) alongside the new 4.4 baseline bean -- each exactly once. No 4.4-family bean
// reproduces the 4.3.1.x work anymore.
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.2.2.3" , applied ) ,
migration ( "4.3.1.2" , applied ) ,
migration ( "4.3.1.3" , applied ) ,
@ -132,7 +132,7 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsRunsAndReturnsEachInRangeVersionOnCrossFamilyUpgrade ( ) {
List < String > applied = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.2.2.3" , applied ) ,
migration ( "4.3.1.2" , applied ) ,
migration ( "4.3.1.3" , applied ) ,
@ -152,7 +152,7 @@ class LtsMigrationServiceTest {
writeSql ( "4.3.1.2" , "SELECT 2;" ) ;
writeSql ( "4.3.1.3" , "SELECT 3;" ) ;
writeSql ( "4.4.0.0" , "SELECT 4;" ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.2.2.3" , applied ) ,
migration ( "4.3.1.2" , applied ) ,
migration ( "4.3.1.3" , applied ) ,
@ -169,46 +169,46 @@ class LtsMigrationServiceTest {
@Test
void isInRangePredicate ( ) {
Lts Version from = Lts Version. parse ( "4.3.1.1" ) ;
Lts Version to = Lts Version. parse ( "4.3.1.3" ) ;
Version from = Version . parse ( "4.3.1.1" ) ;
Version to = Version . parse ( "4.3.1.3" ) ;
// within-family in range
assertTrue ( Lts Version. parse ( "4.3.1.2" ) . isInRange ( from , to ) ) ;
assertTrue ( Version . parse ( "4.3.1.2" ) . isInRange ( from , to ) ) ;
// the target itself (upper boundary, inclusive)
assertTrue ( to . isInRange ( from , to ) ) ;
// at from (lower boundary, exclusive)
assertFalse ( from . isInRange ( from , to ) ) ;
// below from
assertFalse ( Lts Version. parse ( "4.3.1.0" ) . isInRange ( from , to ) ) ;
assertFalse ( Version . parse ( "4.3.1.0" ) . isInRange ( from , to ) ) ;
// above to
assertFalse ( Lts Version. parse ( "4.3.1.4" ) . isInRange ( from , to ) ) ;
assertFalse ( Version . parse ( "4.3.1.4" ) . isInRange ( from , to ) ) ;
// Cross-family: an in-range older-family bean IS now selected (the whole point of the loosened filter),
// as is the target-family baseline; only a bean below `from` stays out of range.
Lts Version crossFrom = Lts Version. parse ( "4.3.0.0" ) ;
Lts Version crossTo = Lts Version. parse ( "4.4.0.0" ) ;
assertTrue ( Lts Version. parse ( "4.3.1.3" ) . isInRange ( crossFrom , crossTo ) ) ;
Version crossFrom = Version . parse ( "4.3.0.0" ) ;
Version crossTo = Version . parse ( "4.4.0.0" ) ;
assertTrue ( Version . parse ( "4.3.1.3" ) . isInRange ( crossFrom , crossTo ) ) ;
assertTrue ( crossTo . isInRange ( crossFrom , crossTo ) ) ;
assertFalse ( Lts Version. parse ( "4.2.2.3" ) . isInRange ( crossFrom , crossTo ) ) ;
assertFalse ( Version . parse ( "4.2.2.3" ) . isInRange ( crossFrom , crossTo ) ) ;
}
@Test
void reproductionDuplicateBeanSitsBelowSupportedSourceFloor ( ) {
// Load-bearing invariant (see Lts MigrationService.select): the only reproduction-duplicate pair is
// Load-bearing invariant (see MigrationService.select): the only reproduction-duplicate pair is
// 4.2.2.3 <-> 4.3.1.3 (both do the solution-template / widget-bundle work). For the loosened (from, to]
// filter to never select both in a single supported upgrade, the duplicate 4.2.2.3 must sit strictly
// below the minimum supported upgrade source. That floor is 4.3.0.0 (SUPPORTED_VERSION S_FOR_UPGRADE).
Lts Version duplicate = Lts Version. parse ( "4.2.2.3" ) ;
Lts Version supportedSourceFloor = Lts Version. parse ( "4.3.0.0" ) ;
// below the minimum supported upgrade source. That floor is 4.3.0.0 (SUPPORTED_FAMILIE S_FOR_UPGRADE).
Version duplicate = Version . parse ( "4.2.2.3" ) ;
Version supportedSourceFloor = Version . parse ( "4.3.0.0" ) ;
assertTrue ( duplicate . compareTo ( supportedSourceFloor ) < 0 ) ;
// So on any supported cross-family upgrade (from >= floor), the duplicate is out of range.
assertFalse ( duplicate . isInRange ( supportedSourceFloor , Lts Version. parse ( "4.4.0.0" ) ) ) ;
assertFalse ( duplicate . isInRange ( supportedSourceFloor , Version . parse ( "4.4.0.0" ) ) ) ;
}
@Test
void reRunAtCurrentVersionIsNoOp ( ) throws Exception {
List < String > applied = new ArrayList < > ( ) ;
writeSql ( "4.2.2.3" , "SELECT 1;" ) ;
Lts MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
List < String > appliedVersions = service . applyMigrations ( "4.2.2.3" , "4.2.2.3" , false , ( ) - > { } ) ;
@ -223,7 +223,7 @@ class LtsMigrationServiceTest {
writeSql ( "4.3.1.3" , "SELECT 1;" ) ;
writeSql ( "4.4.0.0" , "SELECT 2;" ) ;
writeSql ( "4.4.0.1" , "SELECT 3;" ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.3.1.3" , applied ) , migration ( "4.4.0.0" , applied ) , migration ( "4.4.0.1" , applied ) ) ) ;
// SKIP_SCHEMA_VERSION_CHECK on a database already at the package version: the point of the flag is that this
@ -238,7 +238,7 @@ class LtsMigrationServiceTest {
@Test
void forcedRunAtCurrentVersionReRunsThatVersionDataOnly ( ) {
List < String > applied = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.3.1.3" , applied ) , migration ( "4.4.0.0" , applied ) , migration ( "4.4.0.1" , applied ) ) ) ;
service . runDataMigrations ( "4.4.0.0" , "4.4.0.0" , true ) ;
@ -270,7 +270,7 @@ class LtsMigrationServiceTest {
@Test
void forcedApplyMigrationsAtCurrentVersionReRunsAndReturnsThatVersion ( ) {
List < String > applied = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migration ( "4.3.1.3" , applied ) , migration ( "4.4.0.0" , applied ) , migration ( "4.4.0.1" , applied ) ) ) ;
// The no-downtime twin of the above: SKIP_PATCH_VERSION_CHECK got the patch past its version check with the
@ -301,14 +301,14 @@ class LtsMigrationServiceTest {
@Test
void isInClosedRangePredicate ( ) {
Lts Version from = Lts Version. parse ( "4.3.1.1" ) ;
Lts Version to = Lts Version. parse ( "4.3.1.3" ) ;
Version from = Version . parse ( "4.3.1.1" ) ;
Version to = Version . parse ( "4.3.1.3" ) ;
// both boundaries inclusive, unlike isInRange
assertTrue ( from . isInClosedRange ( from , to ) ) ;
assertTrue ( to . isInClosedRange ( from , to ) ) ;
assertTrue ( Lts Version. parse ( "4.3.1.2" ) . isInClosedRange ( from , to ) ) ;
assertFalse ( Lts Version. parse ( "4.3.1.0" ) . isInClosedRange ( from , to ) ) ;
assertFalse ( Lts Version. parse ( "4.3.1.4" ) . isInClosedRange ( from , to ) ) ;
assertTrue ( Version . parse ( "4.3.1.2" ) . isInClosedRange ( from , to ) ) ;
assertFalse ( Version . parse ( "4.3.1.0" ) . isInClosedRange ( from , to ) ) ;
assertFalse ( Version . parse ( "4.3.1.4" ) . isInClosedRange ( from , to ) ) ;
// a single-version range holds exactly that version
assertTrue ( to . isInClosedRange ( to , to ) ) ;
assertFalse ( from . isInClosedRange ( to , to ) ) ;
@ -318,7 +318,7 @@ class LtsMigrationServiceTest {
void runSchemaMigrationsRunsSqlButNeverAppliesOrRecords ( ) throws Exception {
List < String > applied = new ArrayList < > ( ) ;
writeSql ( "4.2.2.3" , "SELECT 1;" ) ;
Lts MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
service . runSchemaMigrations ( "4.2.2.2" , "4.2.2.3" , false ) ;
@ -331,7 +331,7 @@ class LtsMigrationServiceTest {
void runDataMigrationsAppliesButNeverRunsSqlOrRecords ( ) throws Exception {
List < String > applied = new ArrayList < > ( ) ;
writeSql ( "4.2.2.3" , "SELECT 1;" ) ;
Lts MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
service . runDataMigrations ( "4.2.2.2" , "4.2.2.3" , false ) ;
@ -344,7 +344,7 @@ class LtsMigrationServiceTest {
void runDataMigrationsAppliesAndAppliesAfterCommitButNeverRunsSqlOrRecords ( ) throws Exception {
List < String > sequence = new ArrayList < > ( ) ;
writeSql ( "4.2.2.3" , "SELECT 1;" ) ;
Lts MigrationService service = service ( List . of ( migrationWithAfterCommit ( "4.2.2.3" , sequence ) ) ) ;
MigrationService service = service ( List . of ( migrationWithAfterCommit ( "4.2.2.3" , sequence ) ) ) ;
service . runDataMigrations ( "4.2.2.2" , "4.2.2.3" , false ) ;
@ -356,7 +356,7 @@ class LtsMigrationServiceTest {
@Test
void migrationWithoutSqlFileStillAppliesAndReturnsVersion ( ) {
List < String > applied = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
List < String > appliedVersions = service . applyMigrations ( "4.2.2.2" , "4.2.2.3" , false , ( ) - > { } ) ;
@ -368,7 +368,7 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsNeverCallsUpdateSchemaVersionItself ( ) {
List < String > applied = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
MigrationService service = service ( List . of ( migration ( "4.2.2.3" , applied ) ) ) ;
service . applyMigrations ( "4.2.2.2" , "4.2.2.3" , false , ( ) - > { } ) ;
@ -381,7 +381,7 @@ class LtsMigrationServiceTest {
List < String > events = new ArrayList < > ( ) ;
Mockito . doAnswer ( invocation - > events . add ( "record:" + invocation . getArgument ( 0 ) ) )
. when ( schemaSettingsService ) . updateSchemaVersion ( anyString ( ) ) ;
Lts MigrationService service = service ( List . of ( ) ) ;
MigrationService service = service ( List . of ( ) ) ;
service . recordVersions ( List . of ( "4.3.1.2" , "4.3.1.3" ) ) ;
@ -389,8 +389,8 @@ class LtsMigrationServiceTest {
}
// Records apply() and applyAfterCommit() into a shared, ordered event log so their sequence can be asserted.
private Lts Migration recordingMigration ( String version , List < String > events ) {
return new Lts Migration( ) {
private Migration recordingMigration ( String version , List < String > events ) {
return new Migration ( ) {
@Override public String getVersion ( ) { return version ; }
@Override public void apply ( ) { events . add ( "apply:" + version ) ; }
@Override public void applyAfterCommit ( ) { events . add ( "afterCommit:" + version ) ; }
@ -400,7 +400,7 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsRunsApplyThenAfterCommitAndReturnsTheAppliedVersion ( ) {
List < String > events = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of ( recordingMigration ( "4.3.1.3" , events ) ) ) ;
MigrationService service = service ( List . of ( recordingMigration ( "4.3.1.3" , events ) ) ) ;
List < String > appliedVersions = service . applyMigrations ( "4.3.1.2" , "4.3.1.3" , false , ( ) - > { } ) ;
@ -411,7 +411,7 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsPropagatesAnAfterCommitFailureAndStampsNoVersion ( ) {
Lts MigrationService service = service ( List . of ( new Lts Migration( ) {
MigrationService service = service ( List . of ( new Migration ( ) {
@Override public String getVersion ( ) { return "4.3.1.3" ; }
@Override public void applyAfterCommit ( ) { throw new IllegalStateException ( "backfill failed" ) ; }
} ) ) ;
@ -427,7 +427,7 @@ class LtsMigrationServiceTest {
List < String > events = new ArrayList < > ( ) ;
writeSql ( "4.3.1.2" , "SELECT 1;" ) ;
writeSql ( "4.3.1.3" , "SELECT 2;" ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
recordingMigration ( "4.3.1.2" , events ) , recordingMigration ( "4.3.1.3" , events ) ) ) ;
Runnable afterSchemaPhase = ( ) - > events . add ( "replay" ) ;
@ -447,7 +447,7 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsWithReplayNeverRunsBackfillOrReturnsWhenReplayThrows ( ) {
List < String > events = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
recordingMigration ( "4.3.1.2" , events ) , recordingMigration ( "4.3.1.3" , events ) ) ) ;
Runnable afterSchemaPhase = ( ) - > { throw new IllegalStateException ( "replay failed" ) ; } ;
@ -461,12 +461,12 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsReturnsNothingWhenALaterBackfillFailsEvenIfAnEarlierOneSucceeded ( ) {
List < String > events = new ArrayList < > ( ) ;
Lts Migration first = recordingMigration ( "4.3.1.2" , events ) ;
Lts Migration second = new Lts Migration( ) {
Migration first = recordingMigration ( "4.3.1.2" , events ) ;
Migration second = new Migration ( ) {
@Override public String getVersion ( ) { return "4.3.1.3" ; }
@Override public void applyAfterCommit ( ) { throw new IllegalStateException ( "backfill failed" ) ; }
} ;
Lts MigrationService service = service ( List . of ( first , second ) ) ;
MigrationService service = service ( List . of ( first , second ) ) ;
// applyMigrations only returns its applied-versions list on a normal return; the second backfill throws
// before that return, so the caller never learns the first one succeeded either, and recordVersions is
@ -481,7 +481,7 @@ class LtsMigrationServiceTest {
@Test
void runDataMigrationsRunsApplyThenAfterCommit ( ) {
List < String > events = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of ( recordingMigration ( "4.3.1.3" , events ) ) ) ;
MigrationService service = service ( List . of ( recordingMigration ( "4.3.1.3" , events ) ) ) ;
service . runDataMigrations ( "4.3.1.2" , "4.3.1.3" , false ) ;
@ -505,7 +505,7 @@ class LtsMigrationServiceTest {
@Test
void applyMigrationsRunsAllApplyThenAfterSchemaPhaseThenAllApplyAfterCommit ( ) {
List < String > sequence = new ArrayList < > ( ) ;
Lts MigrationService service = service ( List . of (
MigrationService service = service ( List . of (
migrationWithAfterCommit ( "4.2.2.3" , sequence ) ,
migrationWithAfterCommit ( "4.2.2.4" , sequence ) ) ) ;
Runnable afterSchemaPhase = ( ) - > sequence . add ( "afterSchemaPhase" ) ;