From 3916082d6f7645657af55465a1ca0cc973b60091 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Wed, 27 Jul 2022 13:05:26 +0200 Subject: [PATCH] GH-17 - Polishing. Formatting. Nullability constraints. --- .../spring-modulith-events-jdbc/pom.xml | 7 +++++-- .../jdbc/JdbcEventPublicationRepository.java | 14 ++++++++------ .../DatabaseSchemaInitializerIntegrationTests.java | 1 - .../src/test/resources/application-h2.properties | 4 ++-- .../test/resources/application-hsqldb.properties | 4 ++-- .../test/resources/application-postgres.properties | 4 ++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/spring-modulith-events/spring-modulith-events-jdbc/pom.xml b/spring-modulith-events/spring-modulith-events-jdbc/pom.xml index 078810fe..c5edc4fb 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/pom.xml +++ b/spring-modulith-events/spring-modulith-events-jdbc/pom.xml @@ -60,23 +60,25 @@ test - + + org.testcontainers testcontainers test + org.testcontainers junit-jupiter test + org.testcontainers postgresql test - org.hsqldb @@ -97,4 +99,5 @@ + diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java b/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java index e17d4170..08adbe21 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java @@ -97,9 +97,10 @@ class JdbcEventPublicationRepository implements EventPublicationRepository { (rs, rowNum) -> rs.getObject("ID", UUID.class), serializedEvent, publication.getTargetIdentifier().getValue()); if (!results.isEmpty()) { - operations.update( - SQL_STATEMENT_UPDATE, - publication.getCompletionDate().map(Timestamp::from).orElse(null), + + operations.update( // + SQL_STATEMENT_UPDATE, // + publication.getCompletionDate().map(Timestamp::from).orElse(null), // results.get(0)); } @@ -114,11 +115,12 @@ class JdbcEventPublicationRepository implements EventPublicationRepository { var results = operations.query(SQL_STATEMENT_FIND_BY_EVENT_AND_LISTENER_ID, this::resultSetToPublications, serializeEvent(event), targetIdentifier.getValue()); - return Optional.ofNullable((results == null) || results.isEmpty() ? null : results.get(0)); + return Optional.ofNullable(results == null || results.isEmpty() ? null : results.get(0)); } @Override @Transactional(readOnly = true) + @SuppressWarnings("null") public List findIncompletePublications() { return operations.query(SQL_STATEMENT_FIND_UNCOMPLETED, this::resultSetToPublications); } @@ -195,13 +197,13 @@ class JdbcEventPublicationRepository implements EventPublicationRepository { private static class JdbcEventPublication implements CompletableEventPublication { private final UUID id; - private final @Nullable Instant publicationDate; + private final Instant publicationDate; private final String listenerId; private final String serializedEvent; private final Class eventType; private final EventSerializer serializer; - private Instant completionDate; + private @Nullable Instant completionDate; @Override public Object getEvent() { diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseSchemaInitializerIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseSchemaInitializerIntegrationTests.java index 8acf0a92..3b24d604 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseSchemaInitializerIntegrationTests.java +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/DatabaseSchemaInitializerIntegrationTests.java @@ -46,7 +46,6 @@ class DatabaseSchemaInitializerIntegrationTests { @ImportAutoConfiguration(JdbcEventPublicationAutoConfiguration.class) @ContextConfiguration(classes = TestApplication.class) static class TestBase { - @MockBean EventSerializer serializer; } diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties index fb956a9d..aaed5bb6 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties @@ -1,6 +1,6 @@ spring.datasource.driverClassName=org.h2.Driver spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 -# + spring.test.database.replace=NONE -# + spring.modulith.events.schema-initialization.enabled=true diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-hsqldb.properties b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-hsqldb.properties index f316ebb0..d639b426 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-hsqldb.properties +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-hsqldb.properties @@ -1,6 +1,6 @@ spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver spring.datasource.url=jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1 -# + spring.test.database.replace=NONE -# + spring.modulith.events.schema-initialization.enabled=true diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-postgres.properties b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-postgres.properties index ae9c8add..eda12d26 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-postgres.properties +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-postgres.properties @@ -1,6 +1,6 @@ spring.datasource.url=jdbc:tc:postgresql:13.2:////postgres spring.datasource.driverClassName=org.testcontainers.jdbc.ContainerDatabaseDriver -# + spring.test.database.replace=NONE -# + spring.modulith.events.schema-initialization.enabled=true