-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
19 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
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 |
---|---|---|
|
@@ -16,10 +16,13 @@ | |
import org.jooq.SQLDialect; | ||
import org.jooq.Table; | ||
import org.jooq.impl.DSL; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.postgresql.ds.PGSimpleDataSource; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
|
@@ -28,7 +31,10 @@ | |
import java.sql.Statement; | ||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Function; | ||
|
||
|
@@ -39,13 +45,53 @@ | |
import static org.jooq.impl.DSL.table; | ||
import static org.mockito.Mockito.mock; | ||
|
||
|
||
public abstract class AbstractPostgresEventStoreTest { | ||
|
||
protected Integer port = 5557; | ||
protected String host = "localhost"; | ||
protected String database = "eventsourcing"; | ||
protected String user = "eventsourcing"; | ||
protected String password = "eventsourcing"; | ||
private static final PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>(DockerImageName.parse("postgres:14")) | ||
.withUsername("eventsourcing") | ||
.withPassword("eventsourcing") | ||
.withDatabaseName("eventsourcing"); | ||
|
||
static { | ||
if(!isCi()) { | ||
postgreSQLContainer.start(); | ||
} | ||
} | ||
|
||
@AfterAll | ||
public static void stopDb() { | ||
if(!isCi()) { | ||
postgreSQLContainer.stop(); | ||
} | ||
} | ||
|
||
protected static boolean isCi() { | ||
return "true".equals(System.getenv("CI")); | ||
} | ||
|
||
protected static Integer port() { | ||
if (isCi()) { | ||
return 5557; | ||
} else { | ||
return postgreSQLContainer.getFirstMappedPort(); | ||
} | ||
} | ||
|
||
protected static String host() { | ||
return "localhost"; | ||
} | ||
protected static String database() { | ||
return "eventsourcing"; | ||
} | ||
protected static String user() { | ||
return "eventsourcing"; | ||
} | ||
protected static String password() { | ||
return "eventsourcing"; | ||
} | ||
|
||
|
||
|
||
private ReactivePostgresEventStore<PgAsyncTransaction, VikingEvent, Void, Void> postgresEventStore; | ||
private PgAsyncPool pgAsyncPool; | ||
|
@@ -169,6 +215,18 @@ public void queryingByDate() { | |
assertThat(events).containsExactlyInAnyOrder(event1, event2, event3); | ||
} | ||
|
||
@Test | ||
public void queryingBySeqAndEntityId() { | ||
initDatas(); | ||
List<EventEnvelope<VikingEvent, Void, Void>> events = getFromQuery(EventStore.Query.builder() | ||
.withIdsAndSequences(List.of( | ||
Tuple("[email protected]", 0L), | ||
Tuple("[email protected]", 5L) | ||
)) | ||
.build()); | ||
assertThat(events).containsExactlyInAnyOrder(event1, event2, event3, event6); | ||
} | ||
|
||
|
||
@Test | ||
public void queryingByPublished() { | ||
|
@@ -299,9 +357,9 @@ public void setUp() { | |
this.pgAsyncPool = init(); | ||
|
||
PGSimpleDataSource pgSimpleDataSource = new PGSimpleDataSource(); | ||
pgSimpleDataSource.setUrl("jdbc:postgresql://"+host+":"+port+"/"+database); | ||
pgSimpleDataSource.setUser(user); | ||
pgSimpleDataSource.setPassword(password); | ||
pgSimpleDataSource.setUrl("jdbc:postgresql://"+host()+":"+port()+"/"+database()); | ||
pgSimpleDataSource.setUser(user()); | ||
pgSimpleDataSource.setPassword(password()); | ||
this.dslContext = DSL.using(pgSimpleDataSource, SQLDialect.POSTGRES); | ||
Try.of(() -> { | ||
this.dslContext.deleteFrom(vikings_journal).execute(); | ||
|
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