Skip to main content
The RemoteService interface allows tests to connect to services that are hosted externally rather than deployed by the test framework. Configuration is provided through system properties.

Interface signature

public interface RemoteService extends Deployable

How it works

Remote services are enabled by setting a host property in the test configuration. When detected, the framework skips deployment and uses the provided connection details instead.

Default methods

enabled()

Determines if this remote service is configured and should be used.
@Override
default boolean enabled() {
    return propertyValue("host") != null;
}
A remote service is only enabled if the tnb.<service>.host property is set.

priority()

Returns the deployment priority for this service type.
@Override
default int priority() {
    return 2;
}
Priority determines the order in which services are deployed. Remote services have priority 2, which is higher than container deployments (0) and OpenShift deployments (1).

deploy()

No-op method since remote services don’t require deployment.
@Override
default void deploy() {
    // Remote services are already running externally
}

undeploy()

No-op method since remote services aren’t managed by the framework.
@Override
default void undeploy() {
    // Remote services are managed externally
}

propertyValue()

Retrieves configuration property values for this service.
default String propertyValue(String prop) {
    return propertyValue(prop, null);
}

default String propertyValue(String prop, String def) {
    return TestConfiguration.getProperty(
        String.format("tnb.%s.%s", 
            ReflectionUtil.getSuperClassName(this.getClass()).toLowerCase(), 
            prop), 
        def
    );
}
Parameters:
  • prop - The property name (e.g., “host”, “port”, “username”)
  • def - Default value if property is not set
Example properties:
tnb.postgresql.host=db.example.com
tnb.postgresql.port=5432
tnb.postgresql.username=admin
tnb.postgresql.password=secret

host()

Convenience method to retrieve the host property.
default String host() {
    return propertyValue("host");
}

getLogs()

Logs are not available for remote services.
default String getLogs() {
    LOG.warn("getLogs method not supported in RemoteService, returning an empty string");
    return "";
}
Since remote services are managed externally, the framework cannot access their logs.

Example implementation

Here’s a remote PostgreSQL service implementation:
public class RemotePostgreSQL implements RemoteService {
    private Connection connection;
    
    @Override
    public void openResources() {
        String host = host();
        String port = propertyValue("port", "5432");
        String database = propertyValue("database", "postgres");
        String username = propertyValue("username", "postgres");
        String password = propertyValue("password");
        
        String jdbcUrl = String.format(
            "jdbc:postgresql://%s:%s/%s", 
            host, port, database
        );
        
        connection = DriverManager.getConnection(jdbcUrl, username, password);
    }
    
    @Override
    public void closeResources() {
        if (connection != null) {
            connection.close();
        }
    }
    
    public Connection getConnection() {
        return connection;
    }
}

Configuration example

Enable the remote service by setting system properties:
# Run tests with remote PostgreSQL
mvn test \
  -Dtnb.postgresql.host=db.example.com \
  -Dtnb.postgresql.port=5432 \
  -Dtnb.postgresql.username=testuser \
  -Dtnb.postgresql.password=testpass
Or in a properties file:
# test.properties
tnb.postgresql.host=db.example.com
tnb.postgresql.port=5432
tnb.postgresql.username=testuser
tnb.postgresql.password=testpass

Use cases

Shared test environment

Connect to a centralized test database used across teams

CI/CD pipelines

Use managed services in cloud environments

Performance testing

Test against production-like infrastructure

External dependencies

Connect to third-party services that can’t be containerized

Build docs developers (and LLMs) love