Updated to files to fit the Standard.
This commit is contained in:
@@ -20,7 +20,6 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
|
||||
@@ -33,4 +33,5 @@ public class CustomTaskConfigurer extends DefaultTaskConfigurer {
|
||||
public CustomTaskConfigurer(@Qualifier("secondDataSource") DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,15 +36,12 @@ public class EmbeddedDataSourceConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.HSQL)
|
||||
.build();
|
||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource secondDataSource() {
|
||||
return new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.build();
|
||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
/**
|
||||
* Creates two data sources that use external databases.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -52,20 +53,19 @@ public class ExternalDataSourceConfiguration {
|
||||
|
||||
@Bean(name = "springDataSource")
|
||||
@Primary
|
||||
public DataSource dataSource(@Qualifier("springDataSourceProperties")DataSourceProperties springDataSourceProperties) {
|
||||
return DataSourceBuilder.create().driverClassName(springDataSourceProperties.getDriverClassName()).
|
||||
url(springDataSourceProperties.getUrl()).
|
||||
password(springDataSourceProperties.getPassword()).
|
||||
username(springDataSourceProperties.getUsername()).
|
||||
build();
|
||||
public DataSource dataSource(
|
||||
@Qualifier("springDataSourceProperties") DataSourceProperties springDataSourceProperties) {
|
||||
return DataSourceBuilder.create().driverClassName(springDataSourceProperties.getDriverClassName())
|
||||
.url(springDataSourceProperties.getUrl()).password(springDataSourceProperties.getPassword())
|
||||
.username(springDataSourceProperties.getUsername()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource secondDataSource(@Qualifier("secondDataSourceProperties") DataSourceProperties secondDataSourceProperties) {
|
||||
return DataSourceBuilder.create().driverClassName(secondDataSourceProperties.getDriverClassName()).
|
||||
url(secondDataSourceProperties.getUrl()).
|
||||
password(secondDataSourceProperties.getPassword()).
|
||||
username(secondDataSourceProperties.getUsername()).
|
||||
build();
|
||||
public DataSource secondDataSource(
|
||||
@Qualifier("secondDataSourceProperties") DataSourceProperties secondDataSourceProperties) {
|
||||
return DataSourceBuilder.create().driverClassName(secondDataSourceProperties.getDriverClassName())
|
||||
.url(secondDataSourceProperties.getUrl()).password(secondDataSourceProperties.getPassword())
|
||||
.username(secondDataSourceProperties.getUsername()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SampleCommandLineRunner implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
System.out.println("There are " + this.dataSources.size() +
|
||||
" DataSources within this application");
|
||||
System.out.println("There are " + this.dataSources.size() + " DataSources within this application");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@@ -40,10 +39,11 @@ public class MultiDataSourcesApplicationTests {
|
||||
String output = capturedOutput.toString();
|
||||
|
||||
assertThat(output.contains("There are 2 DataSources within this application"))
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
assertThat(output.contains("Creating: TaskExecution{"))
|
||||
.as("Unable to find start task message: " + output).isTrue();
|
||||
assertThat(output.contains("Updating: TaskExecution"))
|
||||
.as("Unable to find update task message: " + output).isTrue();
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
assertThat(output.contains("Creating: TaskExecution{")).as("Unable to find start task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains("Updating: TaskExecution")).as("Unable to find update task message: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring;
|
||||
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.h2.tools.Server;
|
||||
@@ -37,9 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith({OutputCaptureExtension.class, SpringExtension.class})
|
||||
@ExtendWith({ OutputCaptureExtension.class, SpringExtension.class })
|
||||
@SpringBootTest(classes = { MultiDataSourcesExternalApplicationTests.TaskLauncherConfiguration.class })
|
||||
public class MultiDataSourcesExternalApplicationTests {
|
||||
|
||||
private final static String DATASOURCE_URL;
|
||||
|
||||
private final static String SECOND_DATASOURCE_URL;
|
||||
@@ -56,35 +56,33 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
|
||||
static {
|
||||
randomPort = TestSocketUtils.findAvailableTcpPort();
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort
|
||||
+ "/mem:dataflow;DB_CLOSE_DELAY=-1;" + "DB_CLOSE_ON_EXIT=FALSE";
|
||||
DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;"
|
||||
+ "DB_CLOSE_ON_EXIT=FALSE";
|
||||
secondRandomPort = TestSocketUtils.findAvailableTcpPort();
|
||||
SECOND_DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort
|
||||
+ "/mem:dataflow;DB_CLOSE_DELAY=-1;" + "DB_CLOSE_ON_EXIT=FALSE";
|
||||
SECOND_DATASOURCE_URL = "jdbc:h2:tcp://localhost:" + randomPort + "/mem:dataflow;DB_CLOSE_DELAY=-1;"
|
||||
+ "DB_CLOSE_ON_EXIT=FALSE";
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTimeStampApp(CapturedOutput capturedOutput) throws Exception {
|
||||
|
||||
SpringApplication.run(MultipleDataSourcesApplication.class, "--spring.profiles.active=external",
|
||||
"--spring.datasource.url=" + DATASOURCE_URL,
|
||||
"--spring.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"--spring.datasource.password=" + DATASOURCE_USER_PASSWORD,
|
||||
"--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME,
|
||||
"--second.datasource.url=" + SECOND_DATASOURCE_URL,
|
||||
"--second.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"--second.datasource.password=" + DATASOURCE_USER_PASSWORD,
|
||||
"--second.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME);
|
||||
"--spring.datasource.url=" + DATASOURCE_URL, "--spring.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"--spring.datasource.password=" + DATASOURCE_USER_PASSWORD,
|
||||
"--spring.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME,
|
||||
"--second.datasource.url=" + SECOND_DATASOURCE_URL,
|
||||
"--second.datasource.username=" + DATASOURCE_USER_NAME,
|
||||
"--second.datasource.password=" + DATASOURCE_USER_PASSWORD,
|
||||
"--second.datasource.driverClassName=" + DATASOURCE_DRIVER_CLASS_NAME);
|
||||
|
||||
String output = capturedOutput.toString();
|
||||
|
||||
assertThat(output.contains("There are 2 DataSources within this application"))
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
assertThat(output.contains("Creating: TaskExecution{"))
|
||||
.as("Unable to find start task message: " + output).isTrue();
|
||||
assertThat(output.contains("Updating: TaskExecution"))
|
||||
.as("Unable to find update task message: " + output).isTrue();
|
||||
.as("Unable to find CommandLineRunner output: " + output).isTrue();
|
||||
assertThat(output.contains("Creating: TaskExecution{")).as("Unable to find start task message: " + output)
|
||||
.isTrue();
|
||||
assertThat(output.contains("Updating: TaskExecution")).as("Unable to find update task message: " + output)
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -99,9 +97,8 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
Server server = null;
|
||||
try {
|
||||
if (defaultServer == null) {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp",
|
||||
"-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort))
|
||||
.start();
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(randomPort)).start();
|
||||
defaultServer = server;
|
||||
}
|
||||
}
|
||||
@@ -116,9 +113,8 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
Server server = null;
|
||||
try {
|
||||
if (secondServer == null) {
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp",
|
||||
"-tcpAllowOthers", "-tcpPort", String.valueOf(secondRandomPort))
|
||||
.start();
|
||||
server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort",
|
||||
String.valueOf(secondRandomPort)).start();
|
||||
secondServer = server;
|
||||
}
|
||||
}
|
||||
@@ -127,5 +123,7 @@ public class MultiDataSourcesExternalApplicationTests {
|
||||
}
|
||||
return secondServer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user