From 1f39198ec3b23e2bebc56a9108868bc038e3420d Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Wed, 19 Dec 2018 12:49:23 +0100 Subject: [PATCH] remove duplicated embedded database in our example app Previously, in the tests we had each two embedded postgres instances started up, one as the `embeddedPostgres` bean and one as part of the `dataSource` bean. In `@Configuration` classes calling a different bean class to create your bean will be caught by a proxy and give the existing bean, but our application main class is not a `@Configuration` class. Instead, we can use a method parameter to inject the bean created by the other method. My IDE also removed a superfluous cast in the same class, not sure why it was there. --- .../org/zalando/nakadiproducer/tests/Application.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nakadi-producer-starter-spring-boot-2-test/src/main/java/org/zalando/nakadiproducer/tests/Application.java b/nakadi-producer-starter-spring-boot-2-test/src/main/java/org/zalando/nakadiproducer/tests/Application.java index 30929521..10db90a9 100644 --- a/nakadi-producer-starter-spring-boot-2-test/src/main/java/org/zalando/nakadiproducer/tests/Application.java +++ b/nakadi-producer-starter-spring-boot-2-test/src/main/java/org/zalando/nakadiproducer/tests/Application.java @@ -26,8 +26,8 @@ public static void main(String[] args) throws Exception { @Bean @Primary - public DataSource dataSource() throws IOException { - return embeddedPostgres().getPostgresDatabase(); + public DataSource dataSource(EmbeddedPostgres postgres) throws IOException { + return postgres.getPostgresDatabase(); } @Bean @@ -39,9 +39,9 @@ public EmbeddedPostgres embeddedPostgres() throws IOException { public SnapshotEventGenerator snapshotEventGenerator() { return new SimpleSnapshotEventGenerator("eventtype", (withIdGreaterThan, filter) -> { if (withIdGreaterThan == null) { - return Collections.singletonList(new Snapshot("1", "foo", (Object) filter)); + return Collections.singletonList(new Snapshot("1", "foo", filter)); } else if (withIdGreaterThan.equals("1")) { - return Collections.singletonList(new Snapshot("2", "foo", (Object) filter)); + return Collections.singletonList(new Snapshot("2", "foo", filter)); } else { return new ArrayList<>(); }