forked from testcontainers/testcontainers-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcassandra-container.ts
More file actions
89 lines (73 loc) · 2.2 KB
/
cassandra-container.ts
File metadata and controls
89 lines (73 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { AbstractStartedContainer, GenericContainer, type StartedTestContainer } from "testcontainers";
const CASSANDRA_PORT = 9042;
export class CassandraContainer extends GenericContainer {
private dc = "dc1";
private rack = "rack1";
private username = "cassandra";
private password = "cassandra";
constructor(image = "cassandra:5.0.2") {
super(image);
this.withExposedPorts(CASSANDRA_PORT).withStartupTimeout(120_000);
}
public withDatacenter(dc: string): this {
this.dc = dc;
return this;
}
public withRack(rack: string): this {
this.rack = rack;
return this;
}
public withUsername(username: string): this {
this.username = username;
return this;
}
public withPassword(password: string): this {
this.password = password;
return this;
}
public override async start(): Promise<StartedCassandraContainer> {
this.withEnvironment({
CASSANDRA_DC: this.dc,
CASSANDRA_RACK: this.rack,
CASSANDRA_LISTEN_ADDRESS: "auto",
CASSANDRA_BROADCAST_ADDRESS: "auto",
CASSANDRA_RPC_ADDRESS: "0.0.0.0",
CASSANDRA_USERNAME: this.username,
CASSANDRA_PASSWORD: this.password,
CASSANDRA_SNITCH: "GossipingPropertyFileSnitch",
CASSANDRA_ENDPOINT_SNITCH: "GossipingPropertyFileSnitch",
});
return new StartedCassandraContainer(await super.start(), this.dc, this.rack, this.username, this.password);
}
}
export class StartedCassandraContainer extends AbstractStartedContainer {
private readonly port: number;
constructor(
startedTestContainer: StartedTestContainer,
private readonly dc: string,
private readonly rack: string,
private readonly username: string,
private readonly password: string
) {
super(startedTestContainer);
this.port = startedTestContainer.getMappedPort(CASSANDRA_PORT);
}
public getPort(): number {
return this.port;
}
public getDatacenter(): string {
return this.dc;
}
public getRack(): string {
return this.rack;
}
public getUsername(): string {
return this.username;
}
public getPassword(): string {
return this.password;
}
public getContactPoint(): string {
return `${this.getHost()}:${this.getPort()}`;
}
}