-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: flyway not running for manual data source
I changed to use `event.getBeanDefinition().getBeanName()` instead of ```java event.getBeanDefinition() instanceof NameResolver) { ((NameResolver) event.getBeanDefinition()) .resolveName( ```
- Loading branch information
Showing
14 changed files
with
252 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.flyway-base") | ||
`java-library` | ||
} | ||
|
||
description = "Test suite for Flyway + Manual DataSource Configuration" | ||
|
||
dependencies { | ||
annotationProcessor(mn.micronaut.inject.java) | ||
annotationProcessor(mnData.micronaut.data.processor) | ||
implementation(mnData.micronaut.data.jdbc) | ||
implementation(mn.micronaut.http.server.netty) | ||
implementation(projects.micronautFlyway) | ||
implementation(mnSql.hikaricp) | ||
annotationProcessor(mnSerde.micronaut.serde.processor) | ||
implementation(mnSerde.micronaut.serde.jackson) | ||
runtimeOnly(mnLogging.logback.classic) | ||
runtimeOnly(mnSql.h2) | ||
|
||
testAnnotationProcessor(mn.micronaut.inject.java) | ||
testImplementation(mnTest.micronaut.test.junit5) | ||
testImplementation(mn.micronaut.http.client) | ||
testRuntimeOnly(mnTest.junit.jupiter.engine) | ||
} | ||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} |
16 changes: 16 additions & 0 deletions
16
test-suite-manual-datasource/src/main/java/example/micronaut/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.data.annotation.GeneratedValue; | ||
import io.micronaut.data.annotation.Id; | ||
import io.micronaut.data.annotation.MappedEntity; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
@Serdeable | ||
@MappedEntity | ||
public record Book( | ||
@GeneratedValue | ||
@Id Long id, | ||
String title | ||
) { | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
test-suite-manual-datasource/src/main/java/example/micronaut/BookController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Controller("/books") | ||
class BookController { | ||
private final MicronautBookRepository micronautBookRepository; | ||
private final GrailsBookRepository grailsBookRepository; | ||
|
||
BookController(MicronautBookRepository micronautBookRepository, | ||
GrailsBookRepository grailsBookRepository) { | ||
this.micronautBookRepository = micronautBookRepository; | ||
this.grailsBookRepository = grailsBookRepository; | ||
} | ||
|
||
@Get | ||
List<Book> all() { | ||
List<Book> all = new ArrayList<>(); | ||
all.addAll(micronaut()); | ||
all.addAll(grails()); | ||
return all; | ||
} | ||
|
||
@Get("/micronaut") | ||
List<Book> micronaut() { | ||
return micronautBookRepository.findAll(); | ||
} | ||
|
||
@Get("/grails") | ||
List<Book> grails() { | ||
return grailsBookRepository.findAll(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
test-suite-manual-datasource/src/main/java/example/micronaut/BookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.data.repository.CrudRepository; | ||
|
||
public interface BookRepository extends CrudRepository<Book, Long> { | ||
} |
37 changes: 37 additions & 0 deletions
37
test-suite-manual-datasource/src/main/java/example/micronaut/DatasourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package example.micronaut; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Primary; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
|
||
import javax.sql.DataSource; | ||
|
||
|
||
@Factory | ||
public class DatasourceFactory { | ||
|
||
@Singleton | ||
@Primary | ||
@Named("default") | ||
DataSource dataSource() { | ||
HikariDataSource ds = new HikariDataSource(); | ||
ds.setJdbcUrl("jdbc:h2:mem:micronautDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"); | ||
ds.setUsername("sa"); | ||
ds.setPassword(""); | ||
ds.setDriverClassName("org.h2.Driver"); | ||
return ds; | ||
} | ||
|
||
@Singleton | ||
@Named("grails") | ||
DataSource dataSourceGrails() { | ||
HikariDataSource ds = new HikariDataSource(); | ||
ds.setJdbcUrl("jdbc:h2:mem:grailsDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"); | ||
ds.setUsername("sa"); | ||
ds.setPassword(""); | ||
ds.setDriverClassName("org.h2.Driver"); | ||
return ds; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test-suite-manual-datasource/src/main/java/example/micronaut/GrailsBookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.data.jdbc.annotation.JdbcRepository; | ||
import io.micronaut.data.model.query.builder.sql.Dialect; | ||
|
||
@JdbcRepository(dialect = Dialect.H2, dataSource = "grails") | ||
public interface GrailsBookRepository extends BookRepository { | ||
} |
8 changes: 8 additions & 0 deletions
8
test-suite-manual-datasource/src/main/java/example/micronaut/MicronautBookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.data.jdbc.annotation.JdbcRepository; | ||
import io.micronaut.data.model.query.builder.sql.Dialect; | ||
|
||
@JdbcRepository(dialect = Dialect.H2) | ||
public interface MicronautBookRepository extends BookRepository{ | ||
} |
9 changes: 9 additions & 0 deletions
9
test-suite-manual-datasource/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Micronaut Books DataSource | ||
datasources.default.dialect=H2 | ||
datasources.default.schema-generate=NONE | ||
flyway.datasources.default.enabled=true | ||
|
||
# Grails Books DataSource | ||
datasources.grails.dialect=H2 | ||
datasources.grails.schema-generate=NONE | ||
flyway.datasources.grails.enabled=true |
4 changes: 4 additions & 0 deletions
4
test-suite-manual-datasource/src/main/resources/db/migration/V1__schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
create table book( | ||
id bigint auto_increment primary key, | ||
title varchar(255) not null | ||
); |
14 changes: 14 additions & 0 deletions
14
test-suite-manual-datasource/src/main/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="error"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<!-- | ||
<logger name="io.micronaut.flyway" level="TRACE"/> | ||
<logger name="org.flywaydb.core" level="TRACE"/> | ||
--> | ||
</configuration> |
72 changes: 72 additions & 0 deletions
72
test-suite-manual-datasource/src/test/java/example/micronaut/BookControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package example.micronaut; | ||
|
||
import io.micronaut.core.type.Argument; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.client.BlockingHttpClient; | ||
import io.micronaut.http.client.HttpClient; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@MicronautTest(transactional = false) | ||
class BookControllerTest { | ||
|
||
@Inject | ||
MicronautBookRepository micronautBookRepository; | ||
|
||
@Inject | ||
GrailsBookRepository grailsBookRepository; | ||
|
||
@Inject | ||
@Client("/") | ||
HttpClient httpClient; | ||
|
||
@Test | ||
void books() { | ||
//given: | ||
saveGrailsBooks(); | ||
saveMicronautBooks(); | ||
|
||
BlockingHttpClient client = httpClient.toBlocking(); | ||
Argument<List<Book>> arg = Argument.listOf(Book.class); | ||
|
||
//when: | ||
List<Book> books = client.retrieve(HttpRequest.GET("/books"), arg); | ||
//then: | ||
assertEquals(9, books.size()); | ||
|
||
//when: | ||
books = client.retrieve(HttpRequest.GET("/books/micronaut"), arg); | ||
//then: | ||
assertEquals(2, books.size()); | ||
|
||
//when: | ||
books = client.retrieve(HttpRequest.GET("/books/grails"), arg); | ||
|
||
//then: | ||
assertEquals(7, books.size()); | ||
//cleanup: | ||
grailsBookRepository.deleteAll(); | ||
micronautBookRepository.deleteAll(); | ||
} | ||
|
||
void saveGrailsBooks() { | ||
grailsBookRepository.save(new Book(null, "Grails 3 - Step by Step")); | ||
grailsBookRepository.save(new Book(null, "Grails Goodness Notebook")); | ||
grailsBookRepository.save(new Book(null, "Falando de Grails")); | ||
grailsBookRepository.save(new Book(null, "Grails in Action")); | ||
grailsBookRepository.save(new Book(null, "The Definitive Guide to Grails 2")); | ||
grailsBookRepository.save(new Book(null, "Programming Grails")); | ||
grailsBookRepository.save(new Book(null, "Grails 2: Quick Start Guide")); | ||
} | ||
|
||
void saveMicronautBooks() { | ||
micronautBookRepository.save(new Book(null, "Introducing Micronaut: Build, Test and Deploy Java Microservices on Oracle Cloud")); | ||
micronautBookRepository.save(new Book(null, "Building Microservices wiht Micronaut: A quick-start guide to building high-performance reactive microservices for Java developers")); | ||
} | ||
} |