Skip to content

Commit 6d3940b

Browse files
committed
Updated EvenStoreDB container to 24.10.0
1 parent f727769 commit 6d3940b

File tree

2 files changed

+90
-31
lines changed

2 files changed

+90
-31
lines changed
Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,69 @@
1+
import { assertOk } from '@event-driven-io/emmett';
12
import { jsonEvent } from '@eventstore/db-client';
23
import { randomUUID } from 'node:crypto';
3-
import { after, beforeEach, describe, it } from 'node:test';
4+
import { describe, it } from 'node:test';
45
import {
56
EventStoreDBContainer,
6-
StartedEventStoreDBContainer,
7+
getEventStoreDBTestContainer,
8+
releaseShartedEventStoreDBTestContainer,
79
} from './eventStoreDBContainer';
8-
import { assertOk } from '@event-driven-io/emmett';
910

1011
void describe('EventStoreDBContainer', () => {
11-
let container: StartedEventStoreDBContainer;
12+
void it('should connect to EventStoreDB and append new event', async () => {
13+
const container = await new EventStoreDBContainer().start();
14+
15+
try {
16+
const client = container.getClient();
17+
18+
const result = await client.appendToStream(
19+
`test-${randomUUID()}`,
20+
jsonEvent({ type: 'test-event', data: { test: 'test' } }),
21+
);
1222

13-
beforeEach(async () => {
14-
container = await new EventStoreDBContainer().start();
23+
assertOk(result.success);
24+
} finally {
25+
await container.stop();
26+
}
1527
});
1628

17-
void it('should connect to EventStoreDB and append new event', async () => {
18-
const client = container.getClient();
29+
void it('should connect to shared EventStoreDB and append new event', async () => {
30+
const container = await getEventStoreDBTestContainer();
31+
32+
try {
33+
const client = container.getClient();
1934

20-
const result = await client.appendToStream(
21-
`test-${randomUUID()}`,
22-
jsonEvent({ type: 'test-event', data: { test: 'test' } }),
23-
);
35+
const result = await client.appendToStream(
36+
`test-${randomUUID()}`,
37+
jsonEvent({ type: 'test-event', data: { test: 'test' } }),
38+
);
2439

25-
assertOk(result.success);
40+
assertOk(result.success);
41+
} finally {
42+
await releaseShartedEventStoreDBTestContainer();
43+
}
2644
});
2745

28-
after(async () => {
29-
await container.stop();
46+
void it('should connect to multiple shared EventStoreDB and append new event', async () => {
47+
const containers = [
48+
await getEventStoreDBTestContainer(),
49+
await getEventStoreDBTestContainer(),
50+
await getEventStoreDBTestContainer(),
51+
];
52+
53+
try {
54+
const container = containers[0]!;
55+
const client = container.getClient();
56+
57+
const result = await client.appendToStream(
58+
`test-${randomUUID()}`,
59+
jsonEvent({ type: 'test-event', data: { test: 'test' } }),
60+
);
61+
62+
assertOk(result.success);
63+
} finally {
64+
for (let i = 0; i < containers.length; i++) {
65+
await releaseShartedEventStoreDBTestContainer();
66+
}
67+
}
3068
});
3169
});

src/packages/emmett-testcontainers/src/eventStore/eventStoreDBContainer.ts

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,28 @@ import {
77
import type { Environment } from 'testcontainers/build/types';
88

99
export const EVENTSTOREDB_PORT = 2113;
10-
export const EVENTSTOREDB_TCP_PORT = 1113;
11-
export const EVENTSTOREDB_TCP_PORTS = [
12-
EVENTSTOREDB_TCP_PORT,
13-
EVENTSTOREDB_PORT,
14-
];
1510
export const EVENTSTOREDB_IMAGE_NAME = 'eventstore/eventstore';
16-
export const EVENTSTOREDB_IMAGE_TAG = '23.10.1-bookworm-slim';
17-
export const EVENTSTOREDB_ARM64_IMAGE_TAG = '23.10.1-alpha-arm64v8';
11+
export const EVENTSTOREDB_IMAGE_TAG = '24.10.0-bookworm-slim';
12+
export const EVENTSTOREDB_ARM64_IMAGE_TAG = '24.10.0-alpha-arm64v8';
1813

1914
export const EVENTSTOREDB_DEFAULT_IMAGE = `${EVENTSTOREDB_IMAGE_NAME}:${process.arch !== 'arm64' ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG}`;
2015

2116
export type EventStoreDBContainerOptions = {
2217
disableProjections?: boolean;
2318
isSecure?: boolean;
2419
useFileStorage?: boolean;
25-
withoutReuse?: boolean;
20+
withReuse?: boolean;
2621
};
2722

2823
export const defaultEventStoreDBContainerOptions: EventStoreDBContainerOptions =
2924
{
3025
disableProjections: false,
3126
isSecure: false,
3227
useFileStorage: false,
33-
withoutReuse: false,
28+
withReuse: false,
3429
};
3530

3631
export class EventStoreDBContainer extends GenericContainer {
37-
private readonly tcpPorts = EVENTSTOREDB_TCP_PORTS;
38-
3932
constructor(
4033
image = EVENTSTOREDB_DEFAULT_IMAGE,
4134
options: EventStoreDBContainerOptions = defaultEventStoreDBContainerOptions,
@@ -61,15 +54,13 @@ export class EventStoreDBContainer extends GenericContainer {
6154
: {}),
6255
EVENTSTORE_CLUSTER_SIZE: '1',
6356
EVENTSTORE_START_STANDARD_PROJECTIONS: 'true',
64-
EVENTSTORE_EXT_TCP_PORT: `${EVENTSTOREDB_TCP_PORT}`,
65-
EVENTSTORE_HTTP_PORT: `${EVENTSTOREDB_PORT}`,
66-
EVENTSTORE_ENABLE_EXTERNAL_TCP: 'true',
57+
EVENTSTORE_NODE_PORT: `${EVENTSTOREDB_PORT}`,
6758
EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP: 'true',
6859
};
6960

70-
this.withEnvironment(environment).withExposedPorts(...this.tcpPorts);
61+
this.withEnvironment(environment).withExposedPorts(EVENTSTOREDB_PORT);
7162

72-
if (!options.withoutReuse) this.withReuse();
63+
if (options.withReuse) this.withReuse();
7364
}
7465

7566
async start(): Promise<StartedEventStoreDBContainer> {
@@ -90,3 +81,33 @@ export class StartedEventStoreDBContainer extends AbstractStartedContainer {
9081
return EventStoreDBClient.connectionString(this.getConnectionString());
9182
}
9283
}
84+
let container: EventStoreDBContainer | null = null;
85+
let startedContainer: StartedEventStoreDBContainer | null = null;
86+
let startedCount = 0;
87+
88+
export const getEventStoreDBTestContainer = async () => {
89+
if (startedContainer) return startedContainer;
90+
91+
if (!container)
92+
container = new EventStoreDBContainer(EVENTSTOREDB_DEFAULT_IMAGE);
93+
94+
startedContainer = await container.start();
95+
startedCount++;
96+
97+
return startedContainer;
98+
};
99+
100+
export const getSharedTestEventStoreDBClient = async () => {
101+
return (await getEventStoreDBTestContainer()).getClient();
102+
};
103+
104+
export const releaseShartedEventStoreDBTestContainer = async () => {
105+
if (startedContainer && --startedCount === 0)
106+
try {
107+
await startedContainer.stop();
108+
} catch {
109+
/* do nothing */
110+
}
111+
container = null;
112+
startedContainer = null;
113+
};

0 commit comments

Comments
 (0)