Skip to content

Commit

Permalink
remove duplicated embedded database in our example app
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ePaul committed Dec 19, 2018
1 parent 543a095 commit 1f39198
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<>();
}
Expand Down

0 comments on commit 1f39198

Please sign in to comment.