Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoltz committed Jan 7, 2024
1 parent 1ce4ce6 commit 6cdc768
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/admin/__tests__/alterPartitionReassignments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('Admin', () => {
)
})

test('throws an error if the if trying to reassign partitions for a topic that does not exist', async () => {
test('throws an error when trying to reassign partitions for a topic that does not exist', async () => {
admin = createAdmin({ cluster: createCluster(), logger: newLogger() })

await admin.connect()
Expand All @@ -121,7 +121,7 @@ describe('Admin', () => {
message: 'Errors altering partition reassignments',
errors: expect.arrayContaining([
expect.objectContaining({
message: 'This server does not host this topic-partition',
message: `This server does not host this topic-partition [${topicName + 'x'}]`,
topic: topicName + 'x',
partition: 0,
}),
Expand Down
5 changes: 4 additions & 1 deletion src/admin/__tests__/createPartitions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ describe('Admin', () => {
admin.createPartitions({
topicPartitions: [{ topic: topicName + 'x', count: 3 }],
})
).rejects.toHaveProperty('message', 'This server does not host this topic-partition')
).rejects.toHaveProperty(
'message',
`This server does not host this topic-partition [${topicName + 'x'}]`
)
})

test('throws an error trying to assign invalid broker', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/admin/__tests__/fetchTopicMetadata.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ describe('Admin', () => {
admin.fetchTopicMetadata({
topics: [existingTopicName, newTopicName],
})
).rejects.toHaveProperty('message', 'This server does not host this topic-partition')
).rejects.toHaveProperty(
'message',
`This server does not host this topic-partition [${newTopicName}]`
)
})
})
})
8 changes: 7 additions & 1 deletion src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ class KafkaJSOffsetOutOfRange extends KafkaJSProtocolError {
}
}

/**
* Wraps 'UNKNOWN_TOPIC_OR_PARTITION' (code=3) but is only
* used in cases where it is clearly the topic that is unknown
* (e.g. a `metadata` request has no partition parameter)
*/
class KafkaJSUnknownTopic extends KafkaJSProtocolError {
constructor(e, { topic }) {
super(e)
super(e, { retriable: false })
this.topic = topic
this.name = 'KafkaJSUnknownTopic'
this.message = `${this.message} [${this.topic}]`
Expand All @@ -55,6 +60,7 @@ class KafkaJSTopicAuthorizationFailed extends KafkaJSProtocolError {
this.message = `${this.message} [${this.topic})]`
}
}

class KafkaJSMemberIdRequired extends KafkaJSProtocolError {
constructor(e, { memberId }) {
super(e)
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const errorCodes = [
{
type: 'UNKNOWN_TOPIC_OR_PARTITION',
code: 3,
retriable: false,
retriable: true,
message: 'This server does not host this topic-partition',
},
{
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ export interface KafkaJSOffsetOutOfRangeMetadata {
export interface KafkaJSUnknownTopicMetadata {
topic: string
}

export interface KafkaJSTopicAuthorizationFailedMetadata {
topic: string
}
Expand Down
2 changes: 1 addition & 1 deletion types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ new KafkaJSServerDoesNotSupportApiKey(
)

new KafkaJSUnknownTopic('This server does not host this topic-partition', { topic: 'my_topic' })
new KafkaJSTopicAuthorizationFailed('Not authorized to access topics: [Topic authorization failed]', { topic: 'my_topic' })
new KafkaJSTopicAuthorizationFailed('Not authorized to access topics: [Topic authorization failed]', { topic: 'my_topic' })

0 comments on commit 6cdc768

Please sign in to comment.