Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
e8eace2d
Commit
e8eace2d
authored
Nov 29, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Fix Liquibase endpoint's output with multiple datasources"
See gh-19171
parent
5302d919
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
36 deletions
+33
-36
LiquibaseEndpoint.java
...ngframework/boot/actuate/liquibase/LiquibaseEndpoint.java
+4
-7
LiquibaseEndpointTests.java
...mework/boot/actuate/liquibase/LiquibaseEndpointTests.java
+29
-29
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpoint.java
View file @
e8eace2d
...
@@ -25,7 +25,6 @@ import java.util.stream.Collectors;
...
@@ -25,7 +25,6 @@ import java.util.stream.Collectors;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
liquibase.changelog.ChangeLogHistoryService
;
import
liquibase.changelog.ChangeSet.ExecType
;
import
liquibase.changelog.ChangeSet.ExecType
;
import
liquibase.changelog.RanChangeSet
;
import
liquibase.changelog.RanChangeSet
;
import
liquibase.changelog.StandardChangeLogHistoryService
;
import
liquibase.changelog.StandardChangeLogHistoryService
;
...
@@ -63,10 +62,8 @@ public class LiquibaseEndpoint {
...
@@ -63,10 +62,8 @@ public class LiquibaseEndpoint {
while
(
target
!=
null
)
{
while
(
target
!=
null
)
{
Map
<
String
,
LiquibaseBean
>
liquibaseBeans
=
new
HashMap
<>();
Map
<
String
,
LiquibaseBean
>
liquibaseBeans
=
new
HashMap
<>();
DatabaseFactory
factory
=
DatabaseFactory
.
getInstance
();
DatabaseFactory
factory
=
DatabaseFactory
.
getInstance
();
this
.
context
.
getBeansOfType
(
SpringLiquibase
.
class
).
forEach
((
name
,
liquibase
)
->
{
this
.
context
.
getBeansOfType
(
SpringLiquibase
.
class
)
StandardChangeLogHistoryService
service
=
new
StandardChangeLogHistoryService
();
.
forEach
((
name
,
liquibase
)
->
liquibaseBeans
.
put
(
name
,
createReport
(
liquibase
,
factory
)));
liquibaseBeans
.
put
(
name
,
createReport
(
liquibase
,
service
,
factory
));
});
ApplicationContext
parent
=
target
.
getParent
();
ApplicationContext
parent
=
target
.
getParent
();
contextBeans
.
put
(
target
.
getId
(),
contextBeans
.
put
(
target
.
getId
(),
new
ContextLiquibaseBeans
(
liquibaseBeans
,
(
parent
!=
null
)
?
parent
.
getId
()
:
null
));
new
ContextLiquibaseBeans
(
liquibaseBeans
,
(
parent
!=
null
)
?
parent
.
getId
()
:
null
));
...
@@ -75,8 +72,7 @@ public class LiquibaseEndpoint {
...
@@ -75,8 +72,7 @@ public class LiquibaseEndpoint {
return
new
ApplicationLiquibaseBeans
(
contextBeans
);
return
new
ApplicationLiquibaseBeans
(
contextBeans
);
}
}
private
LiquibaseBean
createReport
(
SpringLiquibase
liquibase
,
ChangeLogHistoryService
service
,
private
LiquibaseBean
createReport
(
SpringLiquibase
liquibase
,
DatabaseFactory
factory
)
{
DatabaseFactory
factory
)
{
try
{
try
{
DataSource
dataSource
=
liquibase
.
getDataSource
();
DataSource
dataSource
=
liquibase
.
getDataSource
();
JdbcConnection
connection
=
new
JdbcConnection
(
dataSource
.
getConnection
());
JdbcConnection
connection
=
new
JdbcConnection
(
dataSource
.
getConnection
());
...
@@ -89,6 +85,7 @@ public class LiquibaseEndpoint {
...
@@ -89,6 +85,7 @@ public class LiquibaseEndpoint {
}
}
database
.
setDatabaseChangeLogTableName
(
liquibase
.
getDatabaseChangeLogTable
());
database
.
setDatabaseChangeLogTableName
(
liquibase
.
getDatabaseChangeLogTable
());
database
.
setDatabaseChangeLogLockTableName
(
liquibase
.
getDatabaseChangeLogLockTable
());
database
.
setDatabaseChangeLogLockTableName
(
liquibase
.
getDatabaseChangeLogLockTable
());
StandardChangeLogHistoryService
service
=
new
StandardChangeLogHistoryService
();
service
.
setDatabase
(
database
);
service
.
setDatabase
(
database
);
return
new
LiquibaseBean
(
return
new
LiquibaseBean
(
service
.
getRanChangeSets
().
stream
().
map
(
ChangeSet:
:
new
).
collect
(
Collectors
.
toList
()));
service
.
getRanChangeSets
().
stream
().
map
(
ChangeSet:
:
new
).
collect
(
Collectors
.
toList
()));
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/liquibase/LiquibaseEndpointTests.java
View file @
e8eace2d
...
@@ -22,8 +22,6 @@ import java.util.Map;
...
@@ -22,8 +22,6 @@ import java.util.Map;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
com.zaxxer.hikari.HikariConfig
;
import
com.zaxxer.hikari.HikariDataSource
;
import
liquibase.integration.spring.SpringLiquibase
;
import
liquibase.integration.spring.SpringLiquibase
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -31,10 +29,12 @@ import org.springframework.boot.actuate.liquibase.LiquibaseEndpoint.LiquibaseBea
...
@@ -31,10 +29,12 @@ import org.springframework.boot.actuate.liquibase.LiquibaseEndpoint.LiquibaseBea
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
;
import
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
;
import
org.springframework.boot.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -97,17 +97,18 @@ public class LiquibaseEndpointTests {
...
@@ -97,17 +97,18 @@ public class LiquibaseEndpointTests {
}
}
@Test
@Test
public
void
multipleLiquibaseReportIsReturned
()
{
public
void
whenMultipleLiquibaseBeansArePresentChangeSetsAreCorrectlyReportedForEachBean
()
{
this
.
contextRunner
.
withUserConfiguration
(
Config
.
class
,
LiquibaseConfiguration
.
class
).
run
((
context
)
->
{
this
.
contextRunner
.
withUserConfiguration
(
Config
.
class
,
MultipleDataSourceLiquibaseConfiguration
.
class
)
Map
<
String
,
LiquibaseBean
>
liquibaseBeans
=
context
.
getBean
(
LiquibaseEndpoint
.
class
).
liquibaseBeans
()
.
run
((
context
)
->
{
.
getContexts
().
get
(
context
.
getId
()).
getLiquibaseBeans
();
Map
<
String
,
LiquibaseBean
>
liquibaseBeans
=
context
.
getBean
(
LiquibaseEndpoint
.
class
)
assertThat
(
liquibaseBeans
.
get
(
"liquibase"
).
getChangeSets
()).
hasSize
(
1
);
.
liquibaseBeans
().
getContexts
().
get
(
context
.
getId
()).
getLiquibaseBeans
();
assertThat
(
liquibaseBeans
.
get
(
"liquibase"
).
getChangeSets
().
get
(
0
).
getChangeLog
())
assertThat
(
liquibaseBeans
.
get
(
"liquibase"
).
getChangeSets
()).
hasSize
(
1
);
.
isEqualTo
(
"classpath:/db/changelog/db.changelog-master.yaml"
);
assertThat
(
liquibaseBeans
.
get
(
"liquibase"
).
getChangeSets
().
get
(
0
).
getChangeLog
())
assertThat
(
liquibaseBeans
.
get
(
"liquibaseBackup"
).
getChangeSets
()).
hasSize
(
1
);
.
isEqualTo
(
"classpath:/db/changelog/db.changelog-master.yaml"
);
assertThat
(
liquibaseBeans
.
get
(
"liquibaseBackup"
).
getChangeSets
().
get
(
0
).
getChangeLog
())
assertThat
(
liquibaseBeans
.
get
(
"liquibaseBackup"
).
getChangeSets
()).
hasSize
(
1
);
.
isEqualTo
(
"classpath:/db/changelog/db.changelog-master-backup.yaml"
);
assertThat
(
liquibaseBeans
.
get
(
"liquibaseBackup"
).
getChangeSets
().
get
(
0
).
getChangeLog
())
});
.
isEqualTo
(
"classpath:/db/changelog/db.changelog-master-backup.yaml"
);
});
}
}
private
boolean
getAutoCommit
(
DataSource
dataSource
)
throws
SQLException
{
private
boolean
getAutoCommit
(
DataSource
dataSource
)
throws
SQLException
{
...
@@ -127,39 +128,38 @@ public class LiquibaseEndpointTests {
...
@@ -127,39 +128,38 @@ public class LiquibaseEndpointTests {
}
}
@Configuration
@Configuration
static
class
LiquibaseConfiguration
{
static
class
MultipleDataSource
LiquibaseConfiguration
{
@Bean
@Bean
DataSource
dataSource
()
{
DataSource
dataSource
()
{
HikariConfig
config
=
new
HikariConfig
();
return
createEmbeddedDatabase
();
config
.
setJdbcUrl
(
"jdbc:hsqldb:mem:test"
);
config
.
setUsername
(
"sa"
);
return
new
HikariDataSource
(
config
);
}
}
@Bean
@Bean
DataSource
dataSourceBackup
()
{
DataSource
dataSourceBackup
()
{
HikariConfig
config
=
new
HikariConfig
();
return
createEmbeddedDatabase
();
config
.
setJdbcUrl
(
"jdbc:hsqldb:mem:testBackup"
);
config
.
setUsername
(
"sa"
);
return
new
HikariDataSource
(
config
);
}
}
@Bean
@Bean
SpringLiquibase
liquibase
(
DataSource
dataSource
)
{
SpringLiquibase
liquibase
(
DataSource
dataSource
)
{
SpringLiquibase
liquibase
=
new
SpringLiquibase
();
return
createSpringLiquibase
(
"db.changelog-master.yaml"
,
dataSource
);
liquibase
.
setChangeLog
(
"classpath:/db/changelog/db.changelog-master.yaml"
);
liquibase
.
setShouldRun
(
true
);
liquibase
.
setDataSource
(
dataSource
);
return
liquibase
;
}
}
@Bean
@Bean
SpringLiquibase
liquibaseBackup
(
DataSource
dataSourceBackup
)
{
SpringLiquibase
liquibaseBackup
(
DataSource
dataSourceBackup
)
{
return
createSpringLiquibase
(
"db.changelog-master-backup.yaml"
,
dataSourceBackup
);
}
private
DataSource
createEmbeddedDatabase
()
{
return
new
EmbeddedDatabaseBuilder
().
generateUniqueName
(
true
)
.
setType
(
EmbeddedDatabaseConnection
.
HSQL
.
getType
()).
build
();
}
private
SpringLiquibase
createSpringLiquibase
(
String
changeLog
,
DataSource
dataSource
)
{
SpringLiquibase
liquibase
=
new
SpringLiquibase
();
SpringLiquibase
liquibase
=
new
SpringLiquibase
();
liquibase
.
setChangeLog
(
"classpath:/db/changelog/
db.changelog-master-backup.yaml"
);
liquibase
.
setChangeLog
(
"classpath:/db/changelog/
"
+
changeLog
);
liquibase
.
setShouldRun
(
true
);
liquibase
.
setShouldRun
(
true
);
liquibase
.
setDataSource
(
dataSource
Backup
);
liquibase
.
setDataSource
(
dataSource
);
return
liquibase
;
return
liquibase
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment