describe('Admin', () => { let admin afterEach(async () => { admin && (await admin.disconnect()) }) describe('describeCluster', () => { test('retrieves metadata for all brokers in the cluster', async () => { const cluster = createCluster() admin = createAdmin({ cluster, logger: newLogger() }) await admin.connect() const { brokers, clusterId, controller } = await admin.describeCluster() expect(brokers).toHaveLength(3) expect(brokers).toEqual( expect.arrayContaining([ expect.objectContaining({ nodeId: expect.any(Number), host: expect.any(String), port: expect.any(Number), }), ]) ) expect(clusterId).toEqual(expect.any(String)) expect(brokers.map(({ nodeId }) => nodeId)).toContain(controller) }) }) })
partitions: [expect.objectContaining({ partition: 0 })], }, ]) partitions: [expect.objectContaining({ partition: 1 })], }, ]) partitions: [expect.objectContaining({ partition: 2 })], }, ])
await expect(brokerPool.withBroker(callback)).resolves.toEqual(output) expect(callback).toHaveBeenCalledWith( expect.objectContaining({ nodeId: expect.any(String), broker: expect.any(Broker),
topic: topicName, partition: 0, message: expect.objectContaining({ key: Buffer.from(messages[0].key), value: Buffer.from(messages[0].value), topic: topicName, partition: 0, message: expect.objectContaining({ key: Buffer.from(messages[messages.length - 1].key), value: Buffer.from(messages[messages.length - 1].value),
expect.objectContaining({ commitOffsetsIfNecessary: expect.any(Function), })
expect(request.entry.resolve).toHaveBeenCalledWith(expect.objectContaining({ size, payload })) })
expect.arrayContaining([expect.objectContaining({ groupId })])
message: expect.objectContaining({ key: Buffer.from(message1.key), value: Buffer.from(message1.value), message: expect.objectContaining({ key: Buffer.from(message2.key), value: Buffer.from(message2.value),
expect.objectContaining({ key: Buffer.from([0, 0, 0, 0]), // Abort control message }), }) ).toStrictEqual([ expect.objectContaining({ key: Buffer.from([0, 0, 0, 0]), }), }) ).toStrictEqual([ expect.objectContaining({ key: Buffer.from([0, 0, 0, 0]), }),
expect.objectContaining({ topic: topicName, partition: 0, highWatermark: '2', messages: [ expect.objectContaining({ key: Buffer.from(message1.key), value: Buffer.from(message1.value), offset: '0', }), expect.objectContaining({ key: Buffer.from(message2.key), value: Buffer.from(message2.value),
memberId: expect.any(String), members: expect.arrayContaining([ expect.objectContaining({ memberId: expect.any(String), memberMetadata: expect.any(Buffer),
expect.objectContaining({ producerId: mockProducerId, transactionalId: undefined, expect.objectContaining({ producerId: mockProducerId, transactionalId: undefined, expect.objectContaining({ producerId: mockProducerId, transactionalId: undefined,
message: expect.objectContaining({ key: Buffer.from(message1.key), value: Buffer.from(message1.value),
message: expect.objectContaining({ key: Buffer.from(message1.key), value: Buffer.from(message1.value), message: expect.objectContaining({ key: Buffer.from(message2.key), value: Buffer.from(message2.value),
expect.objectContaining({ producerId: mockProducerId, transactionalId: mockTransactionalId, expect.objectContaining({ producerId: mockProducerId, transactionalId: mockTransactionalId, expect.objectContaining({ producerId: mockProducerId, transactionalId: mockTransactionalId,