kafka-ts 0.0.1-beta → 0.0.3-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +17 -0
- package/.prettierrc +3 -2
- package/LICENSE +1 -1
- package/README.md +48 -35
- package/docker-compose.yml +102 -102
- package/examples/package-lock.json +28 -27
- package/examples/package.json +12 -12
- package/examples/src/client.ts +6 -6
- package/examples/src/consumer.ts +9 -8
- package/examples/src/create-topic.ts +23 -16
- package/examples/src/producer.ts +7 -7
- package/examples/src/replicator.ts +4 -4
- package/examples/src/utils/delay.ts +1 -0
- package/examples/src/utils/json.ts +1 -1
- package/examples/tsconfig.json +2 -2
- package/package.json +21 -15
- package/src/__snapshots__/request-handler.test.ts.snap +9 -718
- package/src/api/api-versions.ts +2 -2
- package/src/api/create-topics.ts +2 -2
- package/src/api/delete-topics.ts +2 -2
- package/src/api/fetch.ts +3 -3
- package/src/api/find-coordinator.ts +2 -2
- package/src/api/heartbeat.ts +2 -2
- package/src/api/index.ts +18 -18
- package/src/api/init-producer-id.ts +2 -2
- package/src/api/join-group.ts +3 -3
- package/src/api/leave-group.ts +2 -2
- package/src/api/list-offsets.ts +3 -3
- package/src/api/metadata.ts +3 -3
- package/src/api/offset-commit.ts +2 -2
- package/src/api/offset-fetch.ts +2 -2
- package/src/api/produce.ts +3 -3
- package/src/api/sasl-authenticate.ts +2 -2
- package/src/api/sasl-handshake.ts +2 -2
- package/src/api/sync-group.ts +2 -2
- package/src/broker.ts +9 -9
- package/src/client.ts +6 -6
- package/src/{request-handler.test.ts → cluster.test.ts} +72 -69
- package/src/cluster.ts +7 -7
- package/src/connection.ts +17 -15
- package/src/consumer/consumer-group.ts +14 -14
- package/src/consumer/consumer-metadata.ts +2 -2
- package/src/consumer/consumer.ts +84 -82
- package/src/consumer/fetch-manager.ts +179 -0
- package/src/consumer/fetcher.ts +57 -0
- package/src/consumer/offset-manager.ts +6 -6
- package/src/consumer/processor.ts +47 -0
- package/src/distributors/assignments-to-replicas.test.ts +7 -7
- package/src/distributors/assignments-to-replicas.ts +1 -1
- package/src/distributors/messages-to-topic-partition-leaders.test.ts +6 -6
- package/src/index.ts +4 -3
- package/src/metadata.ts +4 -4
- package/src/producer/producer.ts +8 -8
- package/src/types.ts +2 -0
- package/src/utils/api.ts +4 -4
- package/src/utils/debug.ts +2 -2
- package/src/utils/decoder.ts +4 -4
- package/src/utils/encoder.ts +6 -6
- package/src/utils/error.ts +3 -3
- package/src/utils/retrier.ts +1 -1
- package/src/utils/tracer.ts +7 -4
- package/tsconfig.json +16 -16
- package/dist/api/api-versions.d.ts +0 -9
- package/dist/api/api-versions.js +0 -24
- package/dist/api/create-topics.d.ts +0 -38
- package/dist/api/create-topics.js +0 -53
- package/dist/api/delete-topics.d.ts +0 -18
- package/dist/api/delete-topics.js +0 -33
- package/dist/api/fetch.d.ts +0 -77
- package/dist/api/fetch.js +0 -106
- package/dist/api/find-coordinator.d.ts +0 -21
- package/dist/api/find-coordinator.js +0 -39
- package/dist/api/heartbeat.d.ts +0 -11
- package/dist/api/heartbeat.js +0 -27
- package/dist/api/index.d.ts +0 -573
- package/dist/api/index.js +0 -164
- package/dist/api/init-producer-id.d.ts +0 -13
- package/dist/api/init-producer-id.js +0 -29
- package/dist/api/join-group.d.ts +0 -34
- package/dist/api/join-group.js +0 -51
- package/dist/api/leave-group.d.ts +0 -19
- package/dist/api/leave-group.js +0 -39
- package/dist/api/list-offsets.d.ts +0 -29
- package/dist/api/list-offsets.js +0 -48
- package/dist/api/metadata.d.ts +0 -40
- package/dist/api/metadata.js +0 -58
- package/dist/api/offset-commit.d.ts +0 -28
- package/dist/api/offset-commit.js +0 -48
- package/dist/api/offset-fetch.d.ts +0 -33
- package/dist/api/offset-fetch.js +0 -57
- package/dist/api/produce.d.ts +0 -53
- package/dist/api/produce.js +0 -129
- package/dist/api/sasl-authenticate.d.ts +0 -11
- package/dist/api/sasl-authenticate.js +0 -23
- package/dist/api/sasl-handshake.d.ts +0 -6
- package/dist/api/sasl-handshake.js +0 -19
- package/dist/api/sync-group.d.ts +0 -24
- package/dist/api/sync-group.js +0 -36
- package/dist/broker.d.ts +0 -29
- package/dist/broker.js +0 -60
- package/dist/client.d.ts +0 -23
- package/dist/client.js +0 -36
- package/dist/cluster.d.ts +0 -24
- package/dist/cluster.js +0 -72
- package/dist/connection.d.ts +0 -25
- package/dist/connection.js +0 -155
- package/dist/consumer/consumer-group.d.ts +0 -36
- package/dist/consumer/consumer-group.js +0 -182
- package/dist/consumer/consumer-metadata.d.ts +0 -7
- package/dist/consumer/consumer-metadata.js +0 -14
- package/dist/consumer/consumer.d.ts +0 -37
- package/dist/consumer/consumer.js +0 -178
- package/dist/consumer/metadata.d.ts +0 -24
- package/dist/consumer/metadata.js +0 -64
- package/dist/consumer/offset-manager.d.ts +0 -22
- package/dist/consumer/offset-manager.js +0 -56
- package/dist/distributors/assignments-to-replicas.d.ts +0 -17
- package/dist/distributors/assignments-to-replicas.js +0 -60
- package/dist/distributors/assignments-to-replicas.test.d.ts +0 -1
- package/dist/distributors/assignments-to-replicas.test.js +0 -40
- package/dist/distributors/messages-to-topic-partition-leaders.d.ts +0 -17
- package/dist/distributors/messages-to-topic-partition-leaders.js +0 -15
- package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +0 -1
- package/dist/distributors/messages-to-topic-partition-leaders.test.js +0 -30
- package/dist/examples/src/replicator.js +0 -34
- package/dist/examples/src/utils/json.js +0 -5
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -19
- package/dist/metadata.d.ts +0 -24
- package/dist/metadata.js +0 -89
- package/dist/producer/producer.d.ts +0 -19
- package/dist/producer/producer.js +0 -111
- package/dist/request-handler.d.ts +0 -16
- package/dist/request-handler.js +0 -67
- package/dist/request-handler.test.d.ts +0 -1
- package/dist/request-handler.test.js +0 -340
- package/dist/src/api/api-versions.js +0 -18
- package/dist/src/api/create-topics.js +0 -46
- package/dist/src/api/delete-topics.js +0 -26
- package/dist/src/api/fetch.js +0 -95
- package/dist/src/api/find-coordinator.js +0 -34
- package/dist/src/api/heartbeat.js +0 -22
- package/dist/src/api/index.js +0 -38
- package/dist/src/api/init-producer-id.js +0 -24
- package/dist/src/api/join-group.js +0 -48
- package/dist/src/api/leave-group.js +0 -30
- package/dist/src/api/list-offsets.js +0 -39
- package/dist/src/api/metadata.js +0 -47
- package/dist/src/api/offset-commit.js +0 -39
- package/dist/src/api/offset-fetch.js +0 -44
- package/dist/src/api/produce.js +0 -119
- package/dist/src/api/sync-group.js +0 -31
- package/dist/src/broker.js +0 -35
- package/dist/src/connection.js +0 -21
- package/dist/src/consumer/consumer-group.js +0 -131
- package/dist/src/consumer/consumer.js +0 -103
- package/dist/src/consumer/metadata.js +0 -52
- package/dist/src/consumer/offset-manager.js +0 -23
- package/dist/src/index.js +0 -19
- package/dist/src/producer/producer.js +0 -84
- package/dist/src/request-handler.js +0 -57
- package/dist/src/request-handler.test.js +0 -321
- package/dist/src/types.js +0 -2
- package/dist/src/utils/api.js +0 -5
- package/dist/src/utils/decoder.js +0 -161
- package/dist/src/utils/encoder.js +0 -137
- package/dist/src/utils/error.js +0 -10
- package/dist/types.d.ts +0 -9
- package/dist/types.js +0 -2
- package/dist/utils/api.d.ts +0 -9
- package/dist/utils/api.js +0 -5
- package/dist/utils/debug.d.ts +0 -2
- package/dist/utils/debug.js +0 -11
- package/dist/utils/decoder.d.ts +0 -29
- package/dist/utils/decoder.js +0 -147
- package/dist/utils/delay.d.ts +0 -1
- package/dist/utils/delay.js +0 -5
- package/dist/utils/encoder.d.ts +0 -28
- package/dist/utils/encoder.js +0 -122
- package/dist/utils/error.d.ts +0 -11
- package/dist/utils/error.js +0 -27
- package/dist/utils/memo.d.ts +0 -1
- package/dist/utils/memo.js +0 -16
- package/dist/utils/retrier.d.ts +0 -10
- package/dist/utils/retrier.js +0 -22
- package/dist/utils/tracer.d.ts +0 -1
- package/dist/utils/tracer.js +0 -26
- package/examples/node_modules/.package-lock.json +0 -22
package/src/api/api-versions.ts
CHANGED
package/src/api/create-topics.ts
CHANGED
package/src/api/delete-topics.ts
CHANGED
package/src/api/fetch.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { Decoder } from
|
|
3
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { Decoder } from '../utils/decoder';
|
|
3
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
4
4
|
|
|
5
5
|
export const enum IsolationLevel {
|
|
6
6
|
READ_UNCOMMITTED = 0,
|
package/src/api/heartbeat.ts
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Api } from
|
|
2
|
-
import { API_VERSIONS } from
|
|
3
|
-
import { CREATE_TOPICS } from
|
|
4
|
-
import { DELETE_TOPICS } from
|
|
5
|
-
import { FETCH } from
|
|
6
|
-
import { FIND_COORDINATOR } from
|
|
7
|
-
import { HEARTBEAT } from
|
|
8
|
-
import { INIT_PRODUCER_ID } from
|
|
9
|
-
import { JOIN_GROUP } from
|
|
10
|
-
import { LEAVE_GROUP } from
|
|
11
|
-
import { LIST_OFFSETS } from
|
|
12
|
-
import { METADATA } from
|
|
13
|
-
import { OFFSET_COMMIT } from
|
|
14
|
-
import { OFFSET_FETCH } from
|
|
15
|
-
import { PRODUCE } from
|
|
16
|
-
import { SASL_AUTHENTICATE } from
|
|
17
|
-
import { SASL_HANDSHAKE } from
|
|
18
|
-
import { SYNC_GROUP } from
|
|
1
|
+
import { Api } from '../utils/api';
|
|
2
|
+
import { API_VERSIONS } from './api-versions';
|
|
3
|
+
import { CREATE_TOPICS } from './create-topics';
|
|
4
|
+
import { DELETE_TOPICS } from './delete-topics';
|
|
5
|
+
import { FETCH } from './fetch';
|
|
6
|
+
import { FIND_COORDINATOR } from './find-coordinator';
|
|
7
|
+
import { HEARTBEAT } from './heartbeat';
|
|
8
|
+
import { INIT_PRODUCER_ID } from './init-producer-id';
|
|
9
|
+
import { JOIN_GROUP } from './join-group';
|
|
10
|
+
import { LEAVE_GROUP } from './leave-group';
|
|
11
|
+
import { LIST_OFFSETS } from './list-offsets';
|
|
12
|
+
import { METADATA } from './metadata';
|
|
13
|
+
import { OFFSET_COMMIT } from './offset-commit';
|
|
14
|
+
import { OFFSET_FETCH } from './offset-fetch';
|
|
15
|
+
import { PRODUCE } from './produce';
|
|
16
|
+
import { SASL_AUTHENTICATE } from './sasl-authenticate';
|
|
17
|
+
import { SASL_HANDSHAKE } from './sasl-handshake';
|
|
18
|
+
import { SYNC_GROUP } from './sync-group';
|
|
19
19
|
|
|
20
20
|
export const API = {
|
|
21
21
|
API_VERSIONS,
|
package/src/api/join-group.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { Encoder } from
|
|
3
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { Encoder } from '../utils/encoder';
|
|
3
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
4
4
|
|
|
5
5
|
export const JOIN_GROUP = createApi({
|
|
6
6
|
apiKey: 11,
|
package/src/api/leave-group.ts
CHANGED
package/src/api/list-offsets.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { KafkaTSApiError } from
|
|
3
|
-
import { IsolationLevel } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
3
|
+
import { IsolationLevel } from './fetch';
|
|
4
4
|
|
|
5
5
|
export const LIST_OFFSETS = createApi({
|
|
6
6
|
apiKey: 2,
|
package/src/api/metadata.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api';
|
|
2
|
+
import { KafkaTSApiError } from '../utils/error';
|
|
3
3
|
|
|
4
|
-
export type Metadata = ReturnType<(typeof METADATA)[
|
|
4
|
+
export type Metadata = ReturnType<(typeof METADATA)['response']>;
|
|
5
5
|
|
|
6
6
|
export const METADATA = createApi({
|
|
7
7
|
apiKey: 3,
|
package/src/api/offset-commit.ts
CHANGED
package/src/api/offset-fetch.ts
CHANGED
package/src/api/produce.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createApi } from
|
|
2
|
-
import { Encoder } from
|
|
3
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { createApi } from '../utils/api.js';
|
|
2
|
+
import { Encoder } from '../utils/encoder.js';
|
|
3
|
+
import { KafkaTSApiError } from '../utils/error.js';
|
|
4
4
|
|
|
5
5
|
export const PRODUCE = createApi({
|
|
6
6
|
apiKey: 0,
|
package/src/api/sync-group.ts
CHANGED
package/src/broker.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { TcpSocketConnectOpts } from
|
|
2
|
-
import { TLSSocketOptions } from
|
|
3
|
-
import { API } from
|
|
4
|
-
import { Connection, SendRequest } from
|
|
5
|
-
import { KafkaTSError } from
|
|
6
|
-
import { memo } from
|
|
1
|
+
import { TcpSocketConnectOpts } from 'net';
|
|
2
|
+
import { TLSSocketOptions } from 'tls';
|
|
3
|
+
import { API } from './api';
|
|
4
|
+
import { Connection, SendRequest } from './connection';
|
|
5
|
+
import { KafkaTSError } from './utils/error';
|
|
6
|
+
import { memo } from './utils/memo';
|
|
7
7
|
|
|
8
|
-
export type SASLOptions = { mechanism:
|
|
8
|
+
export type SASLOptions = { mechanism: 'PLAIN'; username: string; password: string };
|
|
9
9
|
|
|
10
10
|
type BrokerOptions = {
|
|
11
11
|
clientId: string | null;
|
|
@@ -64,11 +64,11 @@ export class Broker {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
private async saslAuthenticate() {
|
|
67
|
-
if (this.options.sasl?.mechanism !==
|
|
67
|
+
if (this.options.sasl?.mechanism !== 'PLAIN') {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
const { username, password } = this.options.sasl;
|
|
71
|
-
const authBytes = [null, username, password].join(
|
|
71
|
+
const authBytes = [null, username, password].join('\u0000');
|
|
72
72
|
await this.sendRequest(API.SASL_AUTHENTICATE, { authBytes: Buffer.from(authBytes) });
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/client.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { TcpSocketConnectOpts } from
|
|
2
|
-
import { TLSSocketOptions } from
|
|
3
|
-
import { SASLOptions } from
|
|
4
|
-
import { Cluster } from
|
|
5
|
-
import { Consumer, ConsumerOptions } from
|
|
6
|
-
import { Producer, ProducerOptions } from
|
|
1
|
+
import { TcpSocketConnectOpts } from 'net';
|
|
2
|
+
import { TLSSocketOptions } from 'tls';
|
|
3
|
+
import { SASLOptions } from './broker';
|
|
4
|
+
import { Cluster } from './cluster';
|
|
5
|
+
import { Consumer, ConsumerOptions } from './consumer/consumer';
|
|
6
|
+
import { Producer, ProducerOptions } from './producer/producer';
|
|
7
7
|
|
|
8
8
|
type ClientOptions = {
|
|
9
9
|
clientId?: string | null;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { randomBytes } from
|
|
2
|
-
import { readFileSync } from
|
|
3
|
-
import { afterAll, beforeAll, describe, expect, it } from
|
|
4
|
-
import { API } from
|
|
5
|
-
import { KEY_TYPE } from
|
|
6
|
-
import { createKafkaClient } from
|
|
7
|
-
import { Cluster } from
|
|
8
|
-
import { KafkaTSApiError } from
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
4
|
+
import { API } from './api';
|
|
5
|
+
import { KEY_TYPE } from './api/find-coordinator';
|
|
6
|
+
import { createKafkaClient } from './client';
|
|
7
|
+
import { Cluster } from './cluster';
|
|
8
|
+
import { KafkaTSApiError } from './utils/error';
|
|
9
9
|
|
|
10
10
|
export const kafka = createKafkaClient({
|
|
11
|
-
clientId:
|
|
12
|
-
bootstrapServers: [{ host:
|
|
13
|
-
sasl: { mechanism:
|
|
14
|
-
ssl: { ca: readFileSync(
|
|
11
|
+
clientId: 'kafka-ts',
|
|
12
|
+
bootstrapServers: [{ host: 'localhost', port: 9092 }],
|
|
13
|
+
sasl: { mechanism: 'PLAIN', username: 'admin', password: 'admin' },
|
|
14
|
+
ssl: { ca: readFileSync('./certs/ca.crt').toString() },
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
describe.sequential(
|
|
18
|
-
const groupId = randomBytes(16).toString(
|
|
17
|
+
describe.sequential('Request handler', () => {
|
|
18
|
+
const groupId = randomBytes(16).toString('hex');
|
|
19
19
|
|
|
20
20
|
let cluster: Cluster;
|
|
21
21
|
|
|
@@ -27,9 +27,9 @@ describe.sequential("Request handler", () => {
|
|
|
27
27
|
allowTopicAutoCreation: false,
|
|
28
28
|
includeTopicAuthorizedOperations: false,
|
|
29
29
|
});
|
|
30
|
-
if (metadataResult.topics.some((topic) => topic.name ===
|
|
30
|
+
if (metadataResult.topics.some((topic) => topic.name === 'kafka-ts-test-topic')) {
|
|
31
31
|
await cluster.sendRequest(API.DELETE_TOPICS, {
|
|
32
|
-
topics: [{ name:
|
|
32
|
+
topics: [{ name: 'kafka-ts-test-topic', topicId: null }],
|
|
33
33
|
timeoutMs: 10000,
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -39,18 +39,18 @@ describe.sequential("Request handler", () => {
|
|
|
39
39
|
await cluster.disconnect();
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it(
|
|
42
|
+
it('should request api versions', async () => {
|
|
43
43
|
const result = await cluster.sendRequest(API.API_VERSIONS, {});
|
|
44
44
|
expect(result).toMatchSnapshot();
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
let topicId: string =
|
|
47
|
+
let topicId: string = 'd6718d178e1b47c886441ad2d19faea5';
|
|
48
48
|
|
|
49
|
-
it(
|
|
49
|
+
it('should create topics', async () => {
|
|
50
50
|
const result = await cluster.sendRequest(API.CREATE_TOPICS, {
|
|
51
51
|
topics: [
|
|
52
52
|
{
|
|
53
|
-
name:
|
|
53
|
+
name: 'kafka-ts-test-topic',
|
|
54
54
|
numPartitions: 1,
|
|
55
55
|
replicationFactor: 1,
|
|
56
56
|
assignments: [],
|
|
@@ -62,22 +62,23 @@ describe.sequential("Request handler", () => {
|
|
|
62
62
|
});
|
|
63
63
|
topicId = result.topics[0].topicId;
|
|
64
64
|
result.topics.forEach((topic) => {
|
|
65
|
-
topic.topicId =
|
|
65
|
+
topic.topicId = 'Any<UUID>';
|
|
66
66
|
});
|
|
67
67
|
expect(result).toMatchSnapshot();
|
|
68
68
|
|
|
69
69
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it(
|
|
72
|
+
it('should request metadata for all topics', async () => {
|
|
73
73
|
const result = await cluster.sendRequest(API.METADATA, {
|
|
74
74
|
topics: null,
|
|
75
75
|
allowTopicAutoCreation: false,
|
|
76
76
|
includeTopicAuthorizedOperations: false,
|
|
77
77
|
});
|
|
78
78
|
result.controllerId = 0;
|
|
79
|
+
result.topics = result.topics.filter((topic) => topic.name !== '__consumer_offsets');
|
|
79
80
|
result.topics.forEach((topic) => {
|
|
80
|
-
topic.topicId =
|
|
81
|
+
topic.topicId = 'Any<UUID>';
|
|
81
82
|
topic.partitions.forEach((partition) => {
|
|
82
83
|
partition.leaderId = 0;
|
|
83
84
|
partition.isrNodes = [0];
|
|
@@ -89,16 +90,16 @@ describe.sequential("Request handler", () => {
|
|
|
89
90
|
|
|
90
91
|
let leaderId = 0;
|
|
91
92
|
|
|
92
|
-
it(
|
|
93
|
+
it('should request metadata for a topic', async () => {
|
|
93
94
|
const result = await cluster.sendRequest(API.METADATA, {
|
|
94
|
-
topics: [{ id: topicId, name:
|
|
95
|
+
topics: [{ id: topicId, name: 'kafka-ts-test-topic' }],
|
|
95
96
|
allowTopicAutoCreation: false,
|
|
96
97
|
includeTopicAuthorizedOperations: false,
|
|
97
98
|
});
|
|
98
99
|
leaderId = result.topics[0].partitions[0].leaderId;
|
|
99
100
|
result.controllerId = 0;
|
|
100
101
|
result.topics.forEach((topic) => {
|
|
101
|
-
topic.topicId =
|
|
102
|
+
topic.topicId = 'Any<UUID>';
|
|
102
103
|
topic.partitions.forEach((partition) => {
|
|
103
104
|
partition.leaderId = 0;
|
|
104
105
|
partition.isrNodes = [0];
|
|
@@ -108,18 +109,20 @@ describe.sequential("Request handler", () => {
|
|
|
108
109
|
expect(result).toMatchSnapshot();
|
|
109
110
|
});
|
|
110
111
|
|
|
111
|
-
|
|
112
|
+
let producerId = 9n;
|
|
113
|
+
|
|
114
|
+
it('should init producer id', async () => {
|
|
112
115
|
const result = await cluster.sendRequest(API.INIT_PRODUCER_ID, {
|
|
113
116
|
transactionalId: null,
|
|
114
117
|
transactionTimeoutMs: 0,
|
|
115
|
-
producerId
|
|
118
|
+
producerId,
|
|
116
119
|
producerEpoch: 0,
|
|
117
120
|
});
|
|
118
121
|
result.producerId = 0n;
|
|
119
122
|
expect(result).toMatchSnapshot();
|
|
120
123
|
});
|
|
121
124
|
|
|
122
|
-
it(
|
|
125
|
+
it('should produce messages', async () => {
|
|
123
126
|
const now = Date.now();
|
|
124
127
|
const result = await cluster.sendRequestToNode(leaderId)(API.PRODUCE, {
|
|
125
128
|
transactionalId: null,
|
|
@@ -127,7 +130,7 @@ describe.sequential("Request handler", () => {
|
|
|
127
130
|
acks: 1,
|
|
128
131
|
topicData: [
|
|
129
132
|
{
|
|
130
|
-
name:
|
|
133
|
+
name: 'kafka-ts-test-topic',
|
|
131
134
|
partitionData: [
|
|
132
135
|
{
|
|
133
136
|
index: 0,
|
|
@@ -139,18 +142,18 @@ describe.sequential("Request handler", () => {
|
|
|
139
142
|
lastOffsetDelta: 0,
|
|
140
143
|
maxTimestamp: BigInt(now),
|
|
141
144
|
producerEpoch: 0,
|
|
142
|
-
producerId
|
|
145
|
+
producerId,
|
|
143
146
|
records: [
|
|
144
147
|
{
|
|
145
148
|
attributes: 0,
|
|
146
149
|
offsetDelta: 0,
|
|
147
150
|
timestampDelta: 0n,
|
|
148
|
-
key:
|
|
149
|
-
value:
|
|
151
|
+
key: 'key',
|
|
152
|
+
value: 'value',
|
|
150
153
|
headers: [
|
|
151
154
|
{
|
|
152
|
-
key:
|
|
153
|
-
value:
|
|
155
|
+
key: 'header-key',
|
|
156
|
+
value: 'header-value',
|
|
154
157
|
},
|
|
155
158
|
],
|
|
156
159
|
},
|
|
@@ -163,7 +166,7 @@ describe.sequential("Request handler", () => {
|
|
|
163
166
|
expect(result).toMatchSnapshot();
|
|
164
167
|
});
|
|
165
168
|
|
|
166
|
-
it(
|
|
169
|
+
it('should fetch messages', async () => {
|
|
167
170
|
const result = await cluster.sendRequestToNode(leaderId)(API.FETCH, {
|
|
168
171
|
maxWaitMs: 100,
|
|
169
172
|
minBytes: 1,
|
|
@@ -187,10 +190,10 @@ describe.sequential("Request handler", () => {
|
|
|
187
190
|
},
|
|
188
191
|
],
|
|
189
192
|
forgottenTopicsData: [],
|
|
190
|
-
rackId:
|
|
193
|
+
rackId: '',
|
|
191
194
|
});
|
|
192
195
|
result.responses.forEach((response) => {
|
|
193
|
-
response.topicId =
|
|
196
|
+
response.topicId = 'Any<UUID>';
|
|
194
197
|
response.partitions.forEach((partition) => {
|
|
195
198
|
partition.records.forEach((record) => {
|
|
196
199
|
expect(record.baseTimestamp).toBeGreaterThan(1721926744730n);
|
|
@@ -208,10 +211,10 @@ describe.sequential("Request handler", () => {
|
|
|
208
211
|
|
|
209
212
|
let coordinatorId = -1;
|
|
210
213
|
|
|
211
|
-
it(
|
|
214
|
+
it('should find coordinator', async () => {
|
|
212
215
|
const result = await cluster.sendRequest(API.FIND_COORDINATOR, { keyType: KEY_TYPE.GROUP, keys: [groupId] });
|
|
213
216
|
result.coordinators.forEach((coordinator) => {
|
|
214
|
-
coordinator.key =
|
|
217
|
+
coordinator.key = 'Any<String>';
|
|
215
218
|
});
|
|
216
219
|
coordinatorId = result.coordinators[0].nodeId;
|
|
217
220
|
result.coordinators.forEach((coordinator) => {
|
|
@@ -221,9 +224,9 @@ describe.sequential("Request handler", () => {
|
|
|
221
224
|
expect(result).toMatchSnapshot();
|
|
222
225
|
});
|
|
223
226
|
|
|
224
|
-
let memberId =
|
|
227
|
+
let memberId = '';
|
|
225
228
|
|
|
226
|
-
it(
|
|
229
|
+
it('should fail join group request with new memberId', async () => {
|
|
227
230
|
try {
|
|
228
231
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.JOIN_GROUP, {
|
|
229
232
|
groupId,
|
|
@@ -231,67 +234,67 @@ describe.sequential("Request handler", () => {
|
|
|
231
234
|
rebalanceTimeoutMs: 60000,
|
|
232
235
|
memberId,
|
|
233
236
|
groupInstanceId: null,
|
|
234
|
-
protocolType:
|
|
237
|
+
protocolType: 'consumer',
|
|
235
238
|
protocols: [
|
|
236
239
|
{
|
|
237
|
-
name:
|
|
238
|
-
metadata: { version: 0, topics: [
|
|
240
|
+
name: 'RoundRobinAssigner',
|
|
241
|
+
metadata: { version: 0, topics: ['kafka-ts-test-topic'] },
|
|
239
242
|
},
|
|
240
243
|
],
|
|
241
244
|
reason: null,
|
|
242
245
|
});
|
|
243
|
-
expect(false,
|
|
246
|
+
expect(false, 'Should throw an error').toBe(true);
|
|
244
247
|
} catch (error) {
|
|
245
248
|
const { response } = error as KafkaTSApiError;
|
|
246
249
|
memberId = response.memberId;
|
|
247
|
-
response.memberId =
|
|
250
|
+
response.memberId = 'Any<UUID>';
|
|
248
251
|
expect(response).toMatchSnapshot();
|
|
249
252
|
}
|
|
250
253
|
});
|
|
251
254
|
|
|
252
|
-
it(
|
|
255
|
+
it('should join group', async () => {
|
|
253
256
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.JOIN_GROUP, {
|
|
254
257
|
groupId,
|
|
255
258
|
sessionTimeoutMs: 30000,
|
|
256
259
|
rebalanceTimeoutMs: 60000,
|
|
257
260
|
memberId,
|
|
258
261
|
groupInstanceId: null,
|
|
259
|
-
protocolType:
|
|
262
|
+
protocolType: 'consumer',
|
|
260
263
|
protocols: [
|
|
261
264
|
{
|
|
262
|
-
name:
|
|
263
|
-
metadata: { version: 0, topics: [
|
|
265
|
+
name: 'RoundRobinAssigner',
|
|
266
|
+
metadata: { version: 0, topics: ['kafka-ts-test-topic'] },
|
|
264
267
|
},
|
|
265
268
|
],
|
|
266
269
|
reason: null,
|
|
267
270
|
});
|
|
268
|
-
result.memberId =
|
|
269
|
-
result.leader =
|
|
271
|
+
result.memberId = 'Any<UUID>';
|
|
272
|
+
result.leader = 'Any<UUID>';
|
|
270
273
|
result.members.forEach((member) => {
|
|
271
|
-
member.memberId =
|
|
274
|
+
member.memberId = 'Any<UUID>';
|
|
272
275
|
});
|
|
273
276
|
expect(result).toMatchSnapshot();
|
|
274
277
|
});
|
|
275
278
|
|
|
276
|
-
it(
|
|
279
|
+
it('should sync group', async () => {
|
|
277
280
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.SYNC_GROUP, {
|
|
278
281
|
groupId,
|
|
279
282
|
generationId: 1,
|
|
280
283
|
memberId,
|
|
281
284
|
groupInstanceId: null,
|
|
282
|
-
protocolType:
|
|
283
|
-
protocolName:
|
|
285
|
+
protocolType: 'consumer',
|
|
286
|
+
protocolName: 'RoundRobinAssigner',
|
|
284
287
|
assignments: [
|
|
285
288
|
{
|
|
286
289
|
memberId,
|
|
287
|
-
assignment: {
|
|
290
|
+
assignment: { 'kafka-test-topic': [0] },
|
|
288
291
|
},
|
|
289
292
|
],
|
|
290
293
|
});
|
|
291
294
|
expect(result).toMatchSnapshot();
|
|
292
295
|
});
|
|
293
296
|
|
|
294
|
-
it(
|
|
297
|
+
it('should commit offsets', async () => {
|
|
295
298
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.OFFSET_COMMIT, {
|
|
296
299
|
groupId,
|
|
297
300
|
generationIdOrMemberEpoch: 1,
|
|
@@ -299,7 +302,7 @@ describe.sequential("Request handler", () => {
|
|
|
299
302
|
groupInstanceId: null,
|
|
300
303
|
topics: [
|
|
301
304
|
{
|
|
302
|
-
name:
|
|
305
|
+
name: 'kafka-ts-test-topic',
|
|
303
306
|
partitions: [
|
|
304
307
|
{ partitionIndex: 0, committedOffset: 1n, committedLeaderEpoch: 0, committedMetadata: null },
|
|
305
308
|
],
|
|
@@ -309,7 +312,7 @@ describe.sequential("Request handler", () => {
|
|
|
309
312
|
expect(result).toMatchSnapshot();
|
|
310
313
|
});
|
|
311
314
|
|
|
312
|
-
it(
|
|
315
|
+
it('should fetch offsets', async () => {
|
|
313
316
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.OFFSET_FETCH, {
|
|
314
317
|
groups: [
|
|
315
318
|
{
|
|
@@ -318,7 +321,7 @@ describe.sequential("Request handler", () => {
|
|
|
318
321
|
memberEpoch: 0,
|
|
319
322
|
topics: [
|
|
320
323
|
{
|
|
321
|
-
name:
|
|
324
|
+
name: 'kafka-ts-test-topic',
|
|
322
325
|
partitionIndexes: [0],
|
|
323
326
|
},
|
|
324
327
|
],
|
|
@@ -327,12 +330,12 @@ describe.sequential("Request handler", () => {
|
|
|
327
330
|
requireStable: false,
|
|
328
331
|
});
|
|
329
332
|
result.groups.forEach((group) => {
|
|
330
|
-
group.groupId =
|
|
333
|
+
group.groupId = 'Any<String>';
|
|
331
334
|
});
|
|
332
335
|
expect(result).toMatchSnapshot();
|
|
333
336
|
});
|
|
334
337
|
|
|
335
|
-
it(
|
|
338
|
+
it('should heartbeat', async () => {
|
|
336
339
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.HEARTBEAT, {
|
|
337
340
|
groupId,
|
|
338
341
|
generationId: 1,
|
|
@@ -342,24 +345,24 @@ describe.sequential("Request handler", () => {
|
|
|
342
345
|
expect(result).toMatchSnapshot();
|
|
343
346
|
});
|
|
344
347
|
|
|
345
|
-
it(
|
|
348
|
+
it('should leave group', async () => {
|
|
346
349
|
const result = await cluster.sendRequestToNode(coordinatorId)(API.LEAVE_GROUP, {
|
|
347
350
|
groupId,
|
|
348
351
|
members: [{ memberId, groupInstanceId: null, reason: null }],
|
|
349
352
|
});
|
|
350
353
|
result.members.forEach((member) => {
|
|
351
|
-
member.memberId =
|
|
354
|
+
member.memberId = 'Any<UUID>';
|
|
352
355
|
});
|
|
353
356
|
expect(result).toMatchSnapshot();
|
|
354
357
|
});
|
|
355
358
|
|
|
356
|
-
it(
|
|
359
|
+
it('should delete topics', async () => {
|
|
357
360
|
const result = await cluster.sendRequest(API.DELETE_TOPICS, {
|
|
358
|
-
topics: [{ name:
|
|
361
|
+
topics: [{ name: 'kafka-ts-test-topic', topicId: null }],
|
|
359
362
|
timeoutMs: 10000,
|
|
360
363
|
});
|
|
361
364
|
result.responses.forEach((response) => {
|
|
362
|
-
response.topicId =
|
|
365
|
+
response.topicId = 'Any<UUID>';
|
|
363
366
|
});
|
|
364
367
|
expect(result).toMatchSnapshot();
|
|
365
368
|
});
|