From 5671e091728f2dacc48c4d5f82c33f664c5368ea Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen Date: Sun, 12 Jan 2025 09:33:37 +0200 Subject: [PATCH 1/5] MariaDB: support restarted containers --- .../mariadb/src/mariadb-container.test.ts | 19 +++++++++++++++++++ .../modules/mariadb/src/mariadb-container.ts | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/modules/mariadb/src/mariadb-container.test.ts b/packages/modules/mariadb/src/mariadb-container.test.ts index 534f5bbbf..82d0fbbf9 100644 --- a/packages/modules/mariadb/src/mariadb-container.test.ts +++ b/packages/modules/mariadb/src/mariadb-container.test.ts @@ -125,4 +125,23 @@ describe("MariaDb", () => { await container.stop(); }); // } + + it("should work with restarted container", async () => { + const container = await new MariaDbContainer().start(); + await container.restart(); + + const client = await mariadb.createConnection({ + host: container.getHost(), + port: container.getPort(), + database: container.getDatabase(), + user: container.getUsername(), + password: container.getUserPassword(), + }); + + const rows = await client.query("SELECT 1 as res"); + expect(rows).toEqual([{ res: 1 }]); + + await client.end(); + await container.stop(); + }); }); diff --git a/packages/modules/mariadb/src/mariadb-container.ts b/packages/modules/mariadb/src/mariadb-container.ts index 3a34ca929..c1574f07a 100644 --- a/packages/modules/mariadb/src/mariadb-container.ts +++ b/packages/modules/mariadb/src/mariadb-container.ts @@ -51,8 +51,6 @@ export class MariaDbContainer extends GenericContainer { } export class StartedMariaDbContainer extends AbstractStartedContainer { - private readonly port: number; - constructor( startedTestContainer: StartedTestContainer, private readonly database: string, @@ -61,11 +59,10 @@ export class StartedMariaDbContainer extends AbstractStartedContainer { private readonly rootPassword: string ) { super(startedTestContainer); - this.port = startedTestContainer.getMappedPort(MARIADB_PORT); } public getPort(): number { - return this.port; + return this.startedTestContainer.getMappedPort(MARIADB_PORT); } public getDatabase(): string { From 893ec5239145389e5ef8fd1655627075beb9d112 Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen Date: Sun, 12 Jan 2025 09:34:24 +0200 Subject: [PATCH 2/5] MySQL: support restarted containers --- .../modules/mysql/src/mysql-container.test.ts | 19 +++++++++++++++++++ packages/modules/mysql/src/mysql-container.ts | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/modules/mysql/src/mysql-container.test.ts b/packages/modules/mysql/src/mysql-container.test.ts index 0c202a8ea..0034d999a 100644 --- a/packages/modules/mysql/src/mysql-container.test.ts +++ b/packages/modules/mysql/src/mysql-container.test.ts @@ -114,4 +114,23 @@ describe("MySqlContainer", () => { await container.stop(); }); // } + + it("should work with restarted container", async () => { + const container = await new MySqlContainer().start(); + await container.restart(); + + const client = await createConnection({ + host: container.getHost(), + port: container.getPort(), + database: container.getDatabase(), + user: container.getUsername(), + password: container.getUserPassword(), + }); + + const [rows] = await client.execute("SELECT 1 as res"); + expect(rows).toEqual([{ res: 1 }]); + + await client.end(); + await container.stop(); + }); }); diff --git a/packages/modules/mysql/src/mysql-container.ts b/packages/modules/mysql/src/mysql-container.ts index 3e720aaf7..7ac44d3fe 100644 --- a/packages/modules/mysql/src/mysql-container.ts +++ b/packages/modules/mysql/src/mysql-container.ts @@ -51,8 +51,6 @@ export class MySqlContainer extends GenericContainer { } export class StartedMySqlContainer extends AbstractStartedContainer { - private readonly port: number; - constructor( startedTestContainer: StartedTestContainer, private readonly database: string, @@ -61,11 +59,10 @@ export class StartedMySqlContainer extends AbstractStartedContainer { private readonly rootPassword: string ) { super(startedTestContainer); - this.port = startedTestContainer.getMappedPort(3306); } public getPort(): number { - return this.port; + return this.startedTestContainer.getMappedPort(MYSQL_PORT); } public getDatabase(): string { From c03de6be8742f800ce6d6cc339dd818a820ce827 Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen Date: Sun, 12 Jan 2025 09:34:36 +0200 Subject: [PATCH 3/5] ScyllaDB: support restarted containers --- .../scylladb/src/scylladb-container.test.ts | 19 +++++++++++++++++++ .../scylladb/src/scylladb-container.ts | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/modules/scylladb/src/scylladb-container.test.ts b/packages/modules/scylladb/src/scylladb-container.test.ts index c861722de..da0e22f61 100644 --- a/packages/modules/scylladb/src/scylladb-container.test.ts +++ b/packages/modules/scylladb/src/scylladb-container.test.ts @@ -64,4 +64,23 @@ describe("ScyllaDB", () => { await container.stop(); }); // } + + it("should work with restarted container", async () => { + const container = await new ScyllaContainer("scylladb/scylla:6.2.0").start(); + await container.restart(); + + const client = new Client({ + contactPoints: [container.getContactPoint()], + localDataCenter: container.getDatacenter(), + keyspace: "system", + }); + + await client.connect(); + + const result = await client.execute("SELECT cql_version FROM system.local"); + expect(result.rows[0].cql_version).toBe("3.3.1"); + + await client.shutdown(); + await container.stop(); + }); }); diff --git a/packages/modules/scylladb/src/scylladb-container.ts b/packages/modules/scylladb/src/scylladb-container.ts index d2c3548a7..73e74539a 100644 --- a/packages/modules/scylladb/src/scylladb-container.ts +++ b/packages/modules/scylladb/src/scylladb-container.ts @@ -21,15 +21,12 @@ export class ScyllaContainer extends GenericContainer { } export class StartedScyllaContainer extends AbstractStartedContainer { - private readonly port: number; - constructor(startedTestContainer: StartedTestContainer) { super(startedTestContainer); - this.port = startedTestContainer.getMappedPort(SCYLLA_PORT); } public getPort(): number { - return this.port; + return this.startedTestContainer.getMappedPort(SCYLLA_PORT); } public getDatacenter(): string { From be93af238d137341b6ba6a6c2a0fe3bec3562440 Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen Date: Sun, 12 Jan 2025 09:34:49 +0200 Subject: [PATCH 4/5] Cassandra: support restarted containers --- .../cassandra/src/cassandra-container.test.ts | 19 +++++++++++++++++++ .../cassandra/src/cassandra-container.ts | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/modules/cassandra/src/cassandra-container.test.ts b/packages/modules/cassandra/src/cassandra-container.test.ts index 8a6eef17e..93fe0da2b 100644 --- a/packages/modules/cassandra/src/cassandra-container.test.ts +++ b/packages/modules/cassandra/src/cassandra-container.test.ts @@ -109,4 +109,23 @@ describe("Cassandra", () => { await container.stop(); }); // } + + it("should work with restarted container", async () => { + const container = await new CassandraContainer("cassandra:5.0.2").start(); + await container.restart(); + + const client = new Client({ + contactPoints: [container.getContactPoint()], + localDataCenter: container.getDatacenter(), + keyspace: "system", + }); + + await client.connect(); + + const result = await client.execute("SELECT release_version FROM system.local"); + expect(result.rows[0].release_version).toBe("5.0.2"); + + await client.shutdown(); + await container.stop(); + }); }); diff --git a/packages/modules/cassandra/src/cassandra-container.ts b/packages/modules/cassandra/src/cassandra-container.ts index fa96bb532..39e6cf58b 100644 --- a/packages/modules/cassandra/src/cassandra-container.ts +++ b/packages/modules/cassandra/src/cassandra-container.ts @@ -50,8 +50,6 @@ export class CassandraContainer extends GenericContainer { } export class StartedCassandraContainer extends AbstractStartedContainer { - private readonly port: number; - constructor( startedTestContainer: StartedTestContainer, private readonly dc: string, @@ -60,11 +58,10 @@ export class StartedCassandraContainer extends AbstractStartedContainer { private readonly password: string ) { super(startedTestContainer); - this.port = startedTestContainer.getMappedPort(CASSANDRA_PORT); } public getPort(): number { - return this.port; + return this.startedTestContainer.getMappedPort(CASSANDRA_PORT); } public getDatacenter(): string { From a3221f57749350c31745b28e19ed58fc77802eb0 Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen Date: Sun, 12 Jan 2025 09:35:00 +0200 Subject: [PATCH 5/5] ElasticSearch: support restarted containers --- .../src/elasticsearch-container.test.ts | 12 ++++++++++++ .../elasticsearch/src/elasticsearch-container.ts | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/modules/elasticsearch/src/elasticsearch-container.test.ts b/packages/modules/elasticsearch/src/elasticsearch-container.test.ts index a74b6f1c8..8f13491d9 100644 --- a/packages/modules/elasticsearch/src/elasticsearch-container.test.ts +++ b/packages/modules/elasticsearch/src/elasticsearch-container.test.ts @@ -35,4 +35,16 @@ describe("ElasticsearchContainer", () => { await container.stop(); }); // } + + it("should work with restarted container", async () => { + const container = await new ElasticsearchContainer().start(); + await container.restart(); + + const client = new Client({ node: container.getHttpUrl() }); + + await client.indices.create({ index: "people" }); + + expect((await client.indices.exists({ index: "people" })).statusCode).toBe(200); + await container.stop(); + }); }); diff --git a/packages/modules/elasticsearch/src/elasticsearch-container.ts b/packages/modules/elasticsearch/src/elasticsearch-container.ts index 6983c1574..1c513b9e3 100644 --- a/packages/modules/elasticsearch/src/elasticsearch-container.ts +++ b/packages/modules/elasticsearch/src/elasticsearch-container.ts @@ -22,14 +22,15 @@ export class ElasticsearchContainer extends GenericContainer { } export class StartedElasticsearchContainer extends AbstractStartedContainer { - private readonly httpPort: number; - constructor(override readonly startedTestContainer: StartedTestContainer) { super(startedTestContainer); - this.httpPort = this.getMappedPort(ELASTIC_SEARCH_HTTP_PORT); + } + + public getPort(): number { + return this.getMappedPort(ELASTIC_SEARCH_HTTP_PORT); } public getHttpUrl(): string { - return `http://${this.getHost()}:${this.httpPort}`; + return `http://${this.getHost()}:${this.getPort()}`; } }