Skip to content

Commit

Permalink
Test refactoring (#522)
Browse files Browse the repository at this point in the history
* Learnings from trying to integrate R2DBC - test refactoring
Separates the abstract persistor test from the core tests so it can be re-used

* Learnings from trying to integrate R2DBC - test refactoring
Separates the base acceptance test from the core tests so it can be re-used

---------

Co-authored-by: Graham Crockford <badgerwithagun@users.noreply.github.com>
  • Loading branch information
badgerwithagun and badgerwithagun authored Dec 19, 2023
1 parent c238baa commit 0f394cb
Show file tree
Hide file tree
Showing 39 changed files with 432 additions and 227 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<module>transactionoutbox-jackson</module>
<module>transactionoutbox-guice</module>
<module>transactionoutbox-quarkus</module>
<module>transactionoutbox-testing</module>
<module>transactionoutbox-acceptance</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
99 changes: 99 additions & 0 deletions transactionoutbox-acceptance/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>transactionoutbox-parent</artifactId>
<groupId>com.gruelbox</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>Transaction Outbox Acceptance Tests</name>
<packaging>jar</packaging>
<artifactId>transactionoutbox-acceptance</artifactId>
<description>A safe implementation of the transactional outbox pattern for Java (core library)</description>
<dependencies>
<dependency>
<groupId>com.gruelbox</groupId>
<artifactId>transactionoutbox-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.gruelbox</groupId>
<artifactId>transactionoutbox-testing</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<!-- Compile time -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-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>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.DefaultInvocationSerializer;
import com.gruelbox.transactionoutbox.DefaultPersistor;
import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.ExecutorSubmitter;
import com.gruelbox.transactionoutbox.Instantiator;
import com.gruelbox.transactionoutbox.TransactionManager;
import com.gruelbox.transactionoutbox.TransactionOutbox;
import com.gruelbox.transactionoutbox.TransactionOutboxEntry;
import com.gruelbox.transactionoutbox.TransactionOutboxListener;
import com.gruelbox.transactionoutbox.*;
import java.sql.Connection;
import java.time.Duration;
import java.util.Currency;
Expand Down Expand Up @@ -134,9 +126,11 @@ public void blocked(TransactionOutboxEntry entry, Throwable cause) {
}
}

void performRemoteCall(SaleType saleType, Money amount) {}
void performRemoteCall(
@SuppressWarnings({"unused", "SameParameterValue"}) SaleType saleType,
@SuppressWarnings("unused") Money amount) {}

private void writeSomeChanges(Connection connection) {}
private void writeSomeChanges(@SuppressWarnings("unused") Connection connection) {}

private interface ServiceLocator {
<T> T createInstance(Class<T> clazz);
Expand All @@ -156,13 +150,15 @@ private static class OutboxTaskProcessedEvent {
String id;
}

@SuppressWarnings("unused")
private enum SaleType {
SALE,
REFUND
}

private interface Money {
static Money of(int amount, Currency currency) {
static Money of(
@SuppressWarnings("unused") int amount, @SuppressWarnings("unused") Currency currency) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.gruelbox.transactionoutbox.acceptance;

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

import com.gruelbox.transactionoutbox.*;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import com.gruelbox.transactionoutbox.testing.InterfaceProcessor;
import com.gruelbox.transactionoutbox.testing.LatchListener;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -50,7 +52,8 @@ final void wrapInvocations() throws InterruptedException {
new TransactionOutboxListener() {
@Override
public void wrapInvocation(Invocator invocator)
throws IllegalAccessException, IllegalArgumentException,
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
inWrappedInvocation.set(true);
try {
Expand Down Expand Up @@ -94,7 +97,8 @@ final void wrapInvocationsWithMDC() throws InterruptedException {
new TransactionOutboxListener() {
@Override
public void wrapInvocation(Invocator invocator)
throws IllegalAccessException, IllegalArgumentException,
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
MDC.put("BAR", "true");
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.gruelbox.transactionoutbox.acceptance;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.gruelbox.transactionoutbox.Instantiator;
import com.gruelbox.transactionoutbox.StubPersistor;
import com.gruelbox.transactionoutbox.StubThreadLocalTransactionManager;
import com.gruelbox.transactionoutbox.TransactionManager;
import com.gruelbox.transactionoutbox.TransactionOutbox;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.gruelbox.transactionoutbox.*;
import com.gruelbox.transactionoutbox.testing.InterfaceProcessor;
import com.gruelbox.transactionoutbox.testing.LatchListener;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MySQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestMySql5 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
new MySQLContainer<>("mysql:5").withStartupTimeout(Duration.ofHours(1));

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

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MySQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestMySql8 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
new MySQLContainer<>("mysql:8.0.27").withStartupTimeout(Duration.ofMinutes(5));

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

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.OracleContainer;
Expand All @@ -14,8 +15,7 @@ class TestOracle18 extends AbstractAcceptanceTest {
@Container
@SuppressWarnings("rawtypes")
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new OracleContainer("gvenzl/oracle-xe:18-slim").withStartupTimeout(Duration.ofHours(1));
new OracleContainer("gvenzl/oracle-xe:18-slim").withStartupTimeout(Duration.ofHours(1));

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

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.OracleContainer;
Expand All @@ -14,8 +15,7 @@ class TestOracle21 extends AbstractAcceptanceTest {
@Container
@SuppressWarnings("rawtypes")
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new OracleContainer("gvenzl/oracle-xe:21-slim").withStartupTimeout(Duration.ofHours(1));
new OracleContainer("gvenzl/oracle-xe:21-slim").withStartupTimeout(Duration.ofHours(1));

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

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestPostgres11 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new PostgreSQLContainer("postgres:11").withStartupTimeout(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestPostgres12 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new PostgreSQLContainer("postgres:12").withStartupTimeout(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestPostgres13 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new PostgreSQLContainer("postgres:13").withStartupTimeout(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestPostgres14 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new PostgreSQLContainer("postgres:14").withStartupTimeout(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestPostgres15 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new PostgreSQLContainer("postgres:15").withStartupTimeout(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gruelbox.transactionoutbox.acceptance;

import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import java.time.Duration;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -12,7 +13,7 @@
class TestPostgres16 extends AbstractAcceptanceTest {

@Container
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "resource"})
private static final JdbcDatabaseContainer container =
(JdbcDatabaseContainer)
new PostgreSQLContainer("postgres:16").withStartupTimeout(Duration.ofHours(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.gruelbox.transactionoutbox.acceptance;

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

import com.gruelbox.transactionoutbox.DefaultInvocationSerializer;
import com.gruelbox.transactionoutbox.DefaultPersistor;
import com.gruelbox.transactionoutbox.Dialect;
import com.gruelbox.transactionoutbox.TransactionManager;
import com.gruelbox.transactionoutbox.TransactionOutbox;
import com.gruelbox.transactionoutbox.*;
import com.gruelbox.transactionoutbox.testing.AbstractAcceptanceTest;
import com.gruelbox.transactionoutbox.testing.LatchListener;
import com.gruelbox.transactionoutbox.testing.TestUtils;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down
Loading

0 comments on commit 0f394cb

Please sign in to comment.