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

Support restart on 5 containers with previously fixed ports #895

Merged
merged 5 commits into from
Jan 13, 2025
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
19 changes: 19 additions & 0 deletions packages/modules/cassandra/src/cassandra-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
5 changes: 1 addition & 4 deletions packages/modules/cassandra/src/cassandra-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions packages/modules/elasticsearch/src/elasticsearch-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
9 changes: 5 additions & 4 deletions packages/modules/elasticsearch/src/elasticsearch-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
}
}
19 changes: 19 additions & 0 deletions packages/modules/mariadb/src/mariadb-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
5 changes: 1 addition & 4 deletions packages/modules/mariadb/src/mariadb-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions packages/modules/mysql/src/mysql-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
5 changes: 1 addition & 4 deletions packages/modules/mysql/src/mysql-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions packages/modules/scylladb/src/scylladb-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
5 changes: 1 addition & 4 deletions packages/modules/scylladb/src/scylladb-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading