Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use generic param for Container interface #104

Merged
merged 2 commits into from
Nov 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Configuration for an DBMS like Postgres, MySql, Oracle, SQLServer
*/
abstract class BaseConfig<C, SELF extends BaseConfig<C, SELF>> implements ContainerBuilder<C, SELF> {
abstract class BaseBuilder<C, SELF extends BaseBuilder<C, SELF>> implements ContainerBuilder<C, SELF> {

/**
* The database platform.
Expand Down Expand Up @@ -81,7 +81,7 @@ abstract class BaseConfig<C, SELF extends BaseConfig<C, SELF>> implements Contai

protected final String version;

BaseConfig(String platform, int port, int internalPort, String version) {
BaseBuilder(String platform, int port, int internalPort, String version) {
this.platform = platform;
this.port = port;
this.internalPort = internalPort;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/ebean/test/containers/BaseContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

abstract class BaseContainer implements Container {
abstract class BaseContainer<C extends Container<C>> implements Container<C> {

static final System.Logger log = Commands.log;

protected final BaseConfig<?, ?> buildConfig;
protected final BaseBuilder<?, ?> buildConfig;
protected InternalConfig config;
protected final Commands commands;
protected int waitForConnectivityAttempts = 200;
Expand All @@ -27,7 +27,7 @@ abstract class BaseContainer implements Container {
protected boolean usingRandomPort;
protected boolean removeOnExit;

BaseContainer(BaseConfig<?, ?> buildConfig) {
BaseContainer(BaseBuilder<?, ?> buildConfig) {
this.buildConfig = buildConfig;
this.commands = new Commands(buildConfig.docker);
this.config = buildConfig.internalConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Configuration for an DBMS like Postgres, MySql, Oracle, SQLServer
*/
abstract class DbConfig<C, SELF extends DbConfig<C, SELF>> extends BaseConfig<C, SELF> implements ContainerBuilderDb<C, SELF> {
abstract class BaseDbBuilder<C, SELF extends BaseDbBuilder<C, SELF>> extends BaseBuilder<C, SELF> implements ContainerBuilderDb<C, SELF> {

/**
* Set for in-memory tmpfs use.
Expand Down Expand Up @@ -91,7 +91,7 @@ abstract class DbConfig<C, SELF extends DbConfig<C, SELF>> extends BaseConfig<C,
*/
protected String collation;

DbConfig(String platform, int port, int internalPort, String version) {
BaseDbBuilder(String platform, int port, int internalPort, String version) {
super(platform, port, internalPort, version);
}

Expand Down Expand Up @@ -357,7 +357,7 @@ protected InternalConfigDb internalConfig() {
return new InnerConfig();
}

private class InnerConfig extends BaseConfig<?, ?>.Inner implements InternalConfigDb {
private class InnerConfig extends BaseBuilder<?, ?>.Inner implements InternalConfigDb {

/**
* Return a description of the configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/BaseDbContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
/**
* Common DB Container.
*/
abstract class BaseDbContainer extends DbContainer implements Container {
abstract class BaseDbContainer<C extends BaseDbContainer<C>> extends DbContainer<C> {

protected static final System.Logger log = Commands.log;

BaseDbContainer(DbConfig config) {
BaseDbContainer(BaseDbBuilder config) {
super(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import static java.lang.System.Logger.Level.WARNING;

abstract class JdbcBaseDbContainer extends DbContainer {
abstract class BaseJdbcContainer<C extends BaseJdbcContainer<C>> extends DbContainer<C> {

JdbcBaseDbContainer(DbConfig<?, ?> config) {
BaseJdbcContainer(BaseDbBuilder<?, ?> config) {
super(config);
this.checkConnectivityUsingAdmin = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.sql.SQLException;
import java.util.List;

abstract class MySqlBaseContainer extends JdbcBaseDbContainer implements Container {
abstract class BaseMySqlContainer<C extends BaseMySqlContainer<C>> extends BaseJdbcContainer<C> {

MySqlBaseContainer(DbConfig<?, ?> config) {
BaseMySqlContainer(BaseDbBuilder<?, ?> config) {
super(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
* <p>
* References: <a href="https://github.com/docker-library/postgres/issues/146">docker-library/postgres/issues/146</a>
*/
abstract class BasePostgresContainer extends JdbcBaseDbContainer implements Container {
abstract class BasePostgresContainer<C extends BasePostgresContainer<C>> extends BaseJdbcContainer<C> {

BasePostgresContainer(DbConfig<?, ?> config) {
BasePostgresContainer(BaseDbBuilder<?, ?> config) {
super(config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.ArrayList;
import java.util.List;

public class ClickHouseContainer extends JdbcBaseDbContainer {
public class ClickHouseContainer extends BaseJdbcContainer<ClickHouseContainer> {

@Override
public ClickHouseContainer start() {
Expand All @@ -20,7 +20,7 @@ public static Builder builder(String version) {
return new Builder(version);
}

public static class Builder extends DbConfig<ClickHouseContainer, ClickHouseContainer.Builder> {
public static class Builder extends BaseDbBuilder<ClickHouseContainer, Builder> {

private Builder(String version) {
super("clickhouse", 8123, 8123, version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Commands for controlling a CockroachDB docker container.
*/
public class CockroachContainer extends BaseDbContainer implements Container {
public class CockroachContainer extends BaseDbContainer<CockroachContainer> {

@Override
public CockroachContainer start() {
Expand All @@ -26,7 +26,7 @@ public static Builder builder(String version) {
/**
* Builder for CockroachContainer.
*/
public static class Builder extends DbConfig<CockroachContainer, CockroachContainer.Builder> {
public static class Builder extends BaseDbBuilder<CockroachContainer, Builder> {

private Builder(String version) {
super("cockroach", 26257, 26257, version);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Commands for starting and stopping a DB container.
*/
public interface Container {
public interface Container<C extends Container<C>> {

/**
* Returns the container configuration.
Expand All @@ -15,7 +15,7 @@ public interface Container {
* <p>
* Throws an IllegalStateException if the container can not be started.
*/
<C extends Container> C start();
C start();

/**
* Start the container or throw a IllegalStateException.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/Db2Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Commands for controlling a DB2 docker container.
*/
public class Db2Container extends JdbcBaseDbContainer implements Container {
public class Db2Container extends BaseJdbcContainer<Db2Container> {

@Override
public Db2Container start() {
Expand All @@ -37,7 +37,7 @@ public static Builder newBuilder(String version) {
/**
* Builder for Db2Container.
*/
public static class Builder extends DbConfig<Db2Container, Db2Container.Builder> {
public static class Builder extends BaseDbBuilder<Db2Container, Builder> {

private String createOptions;
private String configOptions;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/DbContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

abstract class DbContainer extends BaseContainer implements Container {
abstract class DbContainer<C extends DbContainer<C>> extends BaseContainer<C> {

final InternalConfigDb dbConfig;
boolean checkConnectivityUsingAdmin;
int conditionPauseMillis = 100;

DbContainer(DbConfig<?, ?> config) {
DbContainer(BaseDbBuilder<?, ?> config) {
super(config);
this.dbConfig = config.internalConfig();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/ElasticContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* ElasticSearch container commands.
*/
public class ElasticContainer extends BaseContainer {
public class ElasticContainer extends BaseContainer<ElasticContainer> {

@Override
public ElasticContainer start() {
Expand All @@ -32,7 +32,7 @@ public static Builder newBuilder(String version) {
/**
* Builder for ElasticContainer.
*/
public static class Builder extends BaseConfig<ElasticContainer, ElasticContainer.Builder> {
public static class Builder extends BaseBuilder<ElasticContainer, Builder> {

private Builder(String version) {
super("elastic", 9201, 9200, version);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/HanaContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Commands for controlling a SAP HANA docker container.
*/
public class HanaContainer extends DbContainer implements Container {
public class HanaContainer extends DbContainer<HanaContainer> {

private static final System.Logger log = Commands.log;

Expand Down Expand Up @@ -67,7 +67,7 @@ public static boolean checkLicenseAgreement() {
* For more information about the HANA docker configuration see the tutorial
* <a href="https://developers.sap.com/tutorials/hxe-ua-install-using-docker.html">Installing SAP HANA, express edition with Docker</a>
*/
public static class Builder extends DbConfig<HanaContainer, Builder> {
public static class Builder extends BaseDbBuilder<HanaContainer, Builder> {


private String mountsDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* touch ~/.ebean/ignore-docker-shutdown
* </pre>
*/
public class LocalDynamoDBContainer extends BaseContainer {
public class LocalDynamoDBContainer extends BaseContainer<LocalDynamoDBContainer> {

@Override
public LocalDynamoDBContainer start() {
Expand All @@ -62,7 +62,7 @@ public static Builder builder(String version) {
return new Builder(version);
}

public static class Builder extends BaseConfig<LocalDynamoDBContainer, LocalDynamoDBContainer.Builder> {
public static class Builder extends BaseBuilder<LocalDynamoDBContainer, Builder> {

private String awsRegion = "ap-southeast-2";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* }</pre>
*/
public class LocalstackContainer extends BaseContainer {
public class LocalstackContainer extends BaseContainer<LocalstackContainer> {

@Override
public LocalstackContainer start() {
Expand All @@ -60,7 +60,7 @@ public static Builder newBuilder(String version) {
/**
* Builder for LocalstackContainer.
*/
public static class Builder extends BaseConfig<LocalstackContainer, LocalstackContainer.Builder> {
public static class Builder extends BaseBuilder<LocalstackContainer, Builder> {

private String services = "dynamodb";
private String awsRegion = "ap-southeast-2";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/MariaDBContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* MariaDB container.
*/
public class MariaDBContainer extends MySqlBaseContainer {
public class MariaDBContainer extends BaseMySqlContainer<MariaDBContainer> {

@Override
public MariaDBContainer start() {
Expand All @@ -26,7 +26,7 @@ public static Builder newBuilder(String version) {
return builder(version);
}

public static class Builder extends DbConfig<MariaDBContainer, MariaDBContainer.Builder> {
public static class Builder extends BaseDbBuilder<MariaDBContainer, Builder> {

private Builder(String version) {
super("mariadb", 4306, 3306, version);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/MySqlContainer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.ebean.test.containers;

public class MySqlContainer extends MySqlBaseContainer {
public class MySqlContainer extends BaseMySqlContainer<MySqlContainer> {

@Override
public MySqlContainer start() {
Expand All @@ -23,7 +23,7 @@ public static Builder newBuilder(String version) {
return builder(version);
}

public static class Builder extends DbConfig<MySqlContainer, MySqlContainer.Builder> {
public static class Builder extends BaseDbBuilder<MySqlContainer, Builder> {

private Builder(String version) {
super("mysql", 4306, 3306, version);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/NuoDBContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.ArrayList;
import java.util.List;

public class NuoDBContainer extends JdbcBaseDbContainer {
public class NuoDBContainer extends BaseJdbcContainer<NuoDBContainer> {

@Override
public NuoDBContainer start() {
Expand All @@ -33,7 +33,7 @@ public static Builder newBuilder(String version) {
return builder(version);
}

public static class Builder extends DbConfig<NuoDBContainer, NuoDBContainer.Builder> {
public static class Builder extends BaseDbBuilder<NuoDBContainer, Builder> {

private String network;
private String sm1 = "sm";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/OracleContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Commands for controlling an Oracle docker container.
*/
public class OracleContainer extends JdbcBaseDbContainer implements Container {
public class OracleContainer extends BaseJdbcContainer<OracleContainer> {

@Override
public OracleContainer start() {
Expand All @@ -30,7 +30,7 @@ public static Builder newBuilder(String version) {
return builder(version);
}

public static class Builder extends DbConfig<OracleContainer, OracleContainer.Builder> {
public static class Builder extends BaseDbBuilder<OracleContainer, Builder> {

private String apexPort;
private String internalApexPort = "8080";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/PostgisContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Commands for controlling a postgis docker container.
*/
public class PostgisContainer extends BasePostgresContainer implements Container {
public class PostgisContainer extends BasePostgresContainer<PostgisContainer> {

@Override
public PostgisContainer start() {
Expand Down Expand Up @@ -33,7 +33,7 @@ private PostgisContainer(Builder config) {
/**
* Builder for Postgis container.
*/
public static class Builder extends DbConfig<PostgisContainer, Builder> {
public static class Builder extends BaseDbBuilder<PostgisContainer, Builder> {

private Builder(String version) {
super("postgis", 6432, 5432, version);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/ebean/test/containers/PostgresContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Commands for controlling a postgres docker container.
*/
public class PostgresContainer extends BasePostgresContainer implements Container {
public class PostgresContainer extends BasePostgresContainer<PostgresContainer> {

@Override
public PostgresContainer start() {
Expand Down Expand Up @@ -33,7 +33,7 @@ private PostgresContainer(Builder config) {
/**
* Builder for Postgres container.
*/
public static class Builder extends DbConfig<PostgresContainer, Builder> {
public static class Builder extends BaseDbBuilder<PostgresContainer, Builder> {

private Builder(String version) {
super("postgres", 6432, 5432, version);
Expand Down
Loading