Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/run-s3-rustfs-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run S3-RustFS integration tests

on:
workflow_dispatch:
push:
branches: [ develop ]
paths:
- 'src/s3-rustfs/**'
pull_request:
branches: [ develop ]
paths:
- 'src/s3-rustfs/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
s3-rustfs:
uses: ./.github/workflows/run-module-integration-tests.yml
with:
module: s3-rustfs
secrets: inherit
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* The last states/errors of strategies are now stored
* If a strategy times out the last state is collected and attached to the corresponding timeout
* Renamed and moved `JDBCWaitStrategy` → `JDBCAbortableWaitStrategy`
* Added `s3-rustfs` module #762
* Update dependencies

# 4.8.1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Modules for XDEV's Testcontainer Infrastructure Framework
* Predefined implementation for [Mockserver](https://github.com/xdev-software/mockserver-neolight)
* [oidc-server-mock](./src/oidc-server-mock/)
* Predefined implementation for [OIDC Server Mock](https://github.com/xdev-software/oidc-server-mock)
* [s3-rustfs](./src/s3-rustfs/)
* Predefined implementation for using S3 with [RustFS](https://github.com/rustfs/rustfs)
* [selenium](./src/selenium/)
* Predefined implementation for [Selenium](https://github.com/SeleniumHQ/selenium)
* Includes improvements from [xdev-software/testcontainers-selenium](https://github.com/xdev-software/testcontainers-selenium/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public String getActuatorPassword()

public String getInternalHTTPEndpoint()
{
// noinspection HttpUrlsUsage
return "http://" + this.getNetworkAlias() + ":" + WebAppContainer.DEFAULT_HTTP_PORT;
}

public String getExternalHTTPEndpoint()
{
// noinspection HttpUrlsUsage
return "http://" + this.getContainer().getHost()
+ ":" + this.getContainer().getMappedPort(WebAppContainer.DEFAULT_HTTP_PORT);
}
Expand Down
51 changes: 51 additions & 0 deletions src/base/src/main/java/software/xdev/tci/TCI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
*/
package software.xdev.tci;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;

import software.xdev.tci.concurrent.LazyConstantSuppliers;
import software.xdev.tci.safestart.SafeNamedContainerStarter;


Expand All @@ -37,6 +44,10 @@
@SuppressWarnings("java:S119")
public class TCI<C extends GenericContainer<?>>
{
protected static final Map<Class<?>, Logger> LOGGER_CACHE = new ConcurrentHashMap<>();

private final Supplier<Logger> loggerSupplier;

private C container;
private String networkAlias;
private Runnable onStopped;
Expand All @@ -45,6 +56,12 @@ protected TCI(final C container, final String networkAlias)
{
this.container = Objects.requireNonNull(container);
this.networkAlias = networkAlias;
this.loggerSupplier = LazyConstantSuppliers.of(this::createLogger);
}

protected Logger createLogger()
{
return LOGGER_CACHE.computeIfAbsent(this.getClass(), LoggerFactory::getLogger);
}

public void setOnStopped(final Runnable onStopped)
Expand Down Expand Up @@ -104,4 +121,38 @@ public String getNetworkAlias()
{
return this.networkAlias;
}

protected Logger logger()
{
return this.loggerSupplier.get();
}

protected void closeAndFree(@Nullable final AutoCloseable closeable, final String name, final Runnable freeUp)
{
if(closeable != null)
{
this.closeNonNull(closeable, name);
freeUp.run();
}
}

protected void close(@Nullable final AutoCloseable closeable, final String name)
{
if(closeable != null)
{
this.closeNonNull(closeable, name);
}
}

protected void closeNonNull(@NonNull final AutoCloseable closeable, final String name)
{
try
{
closeable.close();
}
catch(final Exception ex)
{
this.logger().warn("Failed to close {}", name, ex);
}
}
}
35 changes: 5 additions & 30 deletions src/db-jdbc/src/main/java/software/xdev/tci/db/BaseDBTCI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import java.sql.Driver;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand All @@ -27,8 +25,6 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.JdbcDatabaseContainer;

import software.xdev.tci.TCI;
Expand All @@ -38,16 +34,13 @@

public abstract class BaseDBTCI<C extends JdbcDatabaseContainer<?>> extends TCI<C>
{
protected static final Map<Class<?>, Logger> LOGGER_CACHE = new ConcurrentHashMap<>();

public static final String DEFAULT_DATABASE = "testdb";
public static final String DEFAULT_USERNAME = "testuser";
@SuppressWarnings("java:S2068") // This is only for tests
public static final String DEFAULT_PASSWORD = "testpw";

protected final boolean migrateAndInitializeEMC;
protected final Supplier<EntityManagerControllerFactory<?, ?>> emcFactorySupplier;
protected final Logger logger;

protected String database = DEFAULT_DATABASE;
protected String username = DEFAULT_USERNAME;
Expand All @@ -65,8 +58,6 @@ protected BaseDBTCI(
super(container, networkAlias);
this.migrateAndInitializeEMC = migrateAndInitializeEMC;
this.emcFactorySupplier = emcFactorySupplier;

this.logger = LOGGER_CACHE.computeIfAbsent(this.getClass(), LoggerFactory::getLogger);
}

@Override
Expand All @@ -76,32 +67,21 @@ public void start(final String containerName)
if(this.migrateAndInitializeEMC)
{
// Do basic migrations async
this.log().debug("Running migration to basic structure");
this.logger().debug("Running migration to basic structure");
this.execInitialDatabaseMigration();
this.log().info("Migration executed");
this.logger().info("Migration executed");

// Create EMC in background to improve performance (~5s)
this.log().debug("Initializing EntityManagerController...");
this.logger().debug("Initializing EntityManagerController...");
this.getEMC();
this.log().info("Initialized EntityManagerController");
this.logger().info("Initialized EntityManagerController");
}
}

@Override
public void stop()
{
if(this.emc != null)
{
try
{
this.emc.close();
}
catch(final Exception ex)
{
this.log().warn("Failed to close EntityManagerController", ex);
}
this.emc = null;
}
this.closeAndFree(this.emc, "EntityManagerController", () -> this.emc = null);
super.stop();
}

Expand Down Expand Up @@ -180,11 +160,6 @@ public void migrateDatabase(final Collection<String> locations)

public abstract void migrateDatabase(final String... locations);

protected Logger log()
{
return this.logger;
}

// region Configure

public BaseDBTCI<C> withDatabase(final String database)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.LoggerFactory;

import software.xdev.mailpit.client.ApiClient;
import software.xdev.tci.TCI;
Expand All @@ -39,6 +38,7 @@ public MailpitTCI(final MailpitContainer container, final String networkAlias)

public String getExternalHTTPEndpoint()
{
// noinspection HttpUrlsUsage
return "http://"
+ this.getContainer().getHost()
+ ":"
Expand All @@ -54,16 +54,15 @@ public ApiClient apiClient()

final Duration defaultTimeout = Duration.ofSeconds(30);

this.apiClient = new ApiClient();
this.apiClient.setHttpClient(HttpClientBuilder.create()
this.apiClient = new ApiClient(HttpClientBuilder.create()
.setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
.setDefaultConnectionConfig(ConnectionConfig.custom()
.setConnectTimeout(Timeout.of(defaultTimeout))
.setSocketTimeout(Timeout.of(defaultTimeout))
.build())
.build())
.build());
this.apiClient.setBasePath(this.getExternalHTTPEndpoint());
.build())
.setBasePath(this.getExternalHTTPEndpoint());

return this.apiClient;
}
Expand All @@ -73,14 +72,7 @@ public void stop()
{
if(this.apiClient != null)
{
try
{
this.apiClient.getHttpClient().close();
}
catch(final Exception e)
{
LoggerFactory.getLogger(this.getClass()).warn("Failed to close API client", e);
}
this.closeNonNull(this.apiClient.getHttpClient(), "API client");
}
super.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public class MailpitContainer extends GenericContainer<MailpitContainer>

public MailpitContainer()
{
super(DEFAULT_IMAGE);
this(DEFAULT_IMAGE);
}

public MailpitContainer(final DockerImageName dockerImageName)
{
super(dockerImageName);

// Version check is not needed in tests
this.addEnv("MP_DISABLE_VERSION_CHECK", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import software.xdev.tci.factory.registry.TCIFactoryRegistry;
import software.xdev.tci.mailpit.containers.MailpitContainer;
import software.xdev.tci.mailpit.factory.MailpitTCIFactory;
import software.xdev.tci.network.LazyNetwork;
import software.xdev.tci.network.LazyNetworkPool;


class SimpleMailpitTest
Expand All @@ -52,16 +50,12 @@ class SimpleMailpitTest
container.addExposedPort(MailpitTCIFactory.SMTP_PORT);
return container;
});
protected static final LazyNetworkPool LAZY_NETWORK_POOL = new LazyNetworkPool();

protected LazyNetwork network;
protected MailpitTCI mailpitInfra;

@BeforeAll
static void beforeAll()
{
LAZY_NETWORK_POOL.managePoolAsync();

TCIFactoryRegistry.instance().warmUp();

// Preload classes
Expand All @@ -71,8 +65,7 @@ static void beforeAll()
@BeforeEach
void beforeEach()
{
this.network = LAZY_NETWORK_POOL.getNew();
this.mailpitInfra = FACTORY.getNew(this.network);
this.mailpitInfra = FACTORY.getNew(null);
}

@Test
Expand Down Expand Up @@ -129,17 +122,11 @@ void afterEach()
this.mailpitInfra.stop();
this.mailpitInfra = null;
}
if(this.network != null)
{
this.network.close();
this.network = null;
}
}

@AfterAll
static void afterAll()
{
FACTORY.close();
LAZY_NETWORK_POOL.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.function.Function;

import org.rnorth.ducttape.unreliables.Unreliables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import software.xdev.tci.TCI;
import software.xdev.tci.envperf.EnvironmentPerformance;
Expand All @@ -40,8 +38,6 @@ public abstract class BaseOIDCTCI<
A extends OIDCServerMockApi>
extends TCI<C>
{
private static final Logger LOG = LoggerFactory.getLogger(BaseOIDCTCI.class);

public static final String CLIENT_ID = BaseOIDCServerContainer.DEFAULT_CLIENT_ID;
public static final String CLIENT_SECRET = BaseOIDCServerContainer.DEFAULT_CLIENT_SECRET;

Expand Down Expand Up @@ -102,14 +98,7 @@ protected void closeAndFreeAPI()
{
if(this.api instanceof final AutoCloseable autoCloseableApi)
{
try
{
autoCloseableApi.close();
}
catch(final Exception ex)
{
LOG.warn("Failed to close API", ex);
}
this.closeNonNull(autoCloseableApi, "API");
}
this.api = null;
}
Expand Down
Loading
Loading