Skip to content

Commit

Permalink
Upgrade secondary module tests to use core acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
badgerwithagun committed Dec 19, 2023
1 parent 0f394cb commit fff6d6d
Show file tree
Hide file tree
Showing 35 changed files with 663 additions and 792 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,11 @@ class TestH2 extends AbstractAcceptanceTest {

static final ThreadLocal<Boolean> inWrappedInvocation = ThreadLocal.withInitial(() -> false);

@Override
protected ConnectionDetails connectionDetails() {
return ConnectionDetails.builder()
.dialect(Dialect.H2)
.driverClassName("org.h2.Driver")
.url(
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=60000;LOB_TIMEOUT=2000;MV_STORE=TRUE")
.user("test")
.password("test")
.build();
}

@Test
final void wrapInvocations() throws InterruptedException {

CountDownLatch latch = new CountDownLatch(1);
TransactionManager transactionManager = simpleTxnManager();
TransactionManager transactionManager = txManager();
TransactionOutbox outbox =
TransactionOutbox.builder()
.transactionManager(transactionManager)
Expand Down Expand Up @@ -78,7 +66,7 @@ public void wrapInvocation(Invocator invocator)
final void wrapInvocationsWithMDC() throws InterruptedException {

CountDownLatch latch = new CountDownLatch(1);
TransactionManager transactionManager = simpleTxnManager();
TransactionManager transactionManager = txManager();
TransactionOutbox outbox =
TransactionOutbox.builder()
.transactionManager(transactionManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestMySql8 extends AbstractAcceptanceTest {
@Container
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
new MySQLContainer<>("mysql:8.0.27").withStartupTimeout(Duration.ofMinutes(5));
new MySQLContainer<>("mysql:8").withStartupTimeout(Duration.ofMinutes(5));

@Override
protected ConnectionDetails connectionDetails() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gruelbox.transactionoutbox.acceptance;
package com.gruelbox.transactionoutbox.guice.acceptance;

import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gruelbox.transactionoutbox.acceptance;
package com.gruelbox.transactionoutbox.guice.acceptance;

import com.google.inject.Guice;
import com.google.inject.Inject;
Expand Down
6 changes: 6 additions & 0 deletions transactionoutbox-jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<artifactId>transactionoutbox-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.gruelbox</groupId>
<artifactId>transactionoutbox-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gruelbox.transactionoutbox.acceptance;
package com.gruelbox.transactionoutbox.jackson.acceptance;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -10,51 +10,38 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.gruelbox.transactionoutbox.*;
import com.gruelbox.transactionoutbox.jackson.JacksonInvocationSerializer;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.sql.SQLException;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@Slf4j
class TestJacksonSerializer {
class TestJacksonSerializer extends AbstractAcceptanceTest {

private HikariDataSource dataSource;
private ThreadLocalContextTransactionManager transactionManager;
private DefaultPersistor persistor;
private TransactionOutbox outbox;
private final CountDownLatch latch = new CountDownLatch(1);
private TransactionManager transactionManager;
private TransactionOutbox outbox;

@BeforeEach
void beforeEach() {
dataSource = pooledDataSource();
transactionManager =
TransactionManager.fromConnectionDetails(
"org.h2.Driver",
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=60000;LOB_TIMEOUT=2000;MV_STORE=TRUE",
"test",
"test");
var mapper = new ObjectMapper();
mapper.registerModule(new GuavaModule());
mapper.registerModule(new Jdk8Module());
mapper.registerModule(new JavaTimeModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);

persistor =
DefaultPersistor.builder()
.dialect(Dialect.H2)
.serializer(JacksonInvocationSerializer.builder().mapper(mapper).build())
.build();
transactionManager = txManager();
outbox =
TransactionOutbox.builder()
.transactionManager(transactionManager)
.persistor(persistor)
.persistor(
DefaultPersistor.builder()
.dialect(Dialect.H2)
.serializer(JacksonInvocationSerializer.builder().mapper(mapper).build())
.build())
.instantiator(Instantiator.using(clazz -> TestJacksonSerializer.this))
.listener(
new TransactionOutboxListener() {
Expand All @@ -64,29 +51,6 @@ public void success(TransactionOutboxEntry entry) {
}
})
.build();
transactionManager.inTransaction(
tx -> {
try {
persistor.clear(tx);
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
}

@AfterEach
void afterEach() {
dataSource.close();
}

private HikariDataSource pooledDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DEFAULT_LOCK_TIMEOUT=2000;LOB_TIMEOUT=2000;MV_STORE=TRUE");
config.setUsername("test");
config.setPassword("test");
config.addDataSourceProperty("cachePrepStmts", "true");
return new HikariDataSource(config);
}

void process(List<Object> difficultDataStructure) {
Expand Down
38 changes: 38 additions & 0 deletions transactionoutbox-jooq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<artifactId>transactionoutbox-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.gruelbox</groupId>
<artifactId>transactionoutbox-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
Expand Down Expand Up @@ -59,5 +65,37 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>oracle-xe</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit fff6d6d

Please sign in to comment.