-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds timeout mechanism in reader with maxWait (#246)
* Adds timeout mechanism in reader with maxWait * Adds comment to test behavior * Run prettier on the example scripts * MaxWait is now a string * Update tests --------- Co-authored-by: Mostafa Moradian <mostafamoradian0@gmail.com>
- Loading branch information
Showing
5 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ | |
|
||
### maxWait | ||
|
||
• **maxWait**: `number` | ||
• **maxWait**: `string` | ||
|
||
#### Defined in | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
This is a k6 test script that imports the xk6-kafka and | ||
*/ | ||
|
||
import { check } from "k6"; | ||
// import * as kafka from "k6/x/kafka"; | ||
import { Reader, Connection } from "k6/x/kafka"; // import kafka extension | ||
|
||
// Prints module-level constants | ||
// console.log(kafka); | ||
|
||
const brokers = ["localhost:9092"]; | ||
const topic = "xk6_kafka_json_topic"; | ||
|
||
const reader = new Reader({ | ||
brokers: brokers, | ||
topic: topic, | ||
maxWait: "5s", | ||
}); | ||
|
||
const connection = new Connection({ | ||
address: brokers[0], | ||
}); | ||
|
||
if (__VU === 0) { | ||
connection.createTopic({ topic: topic }); | ||
} | ||
|
||
export const options = { | ||
thresholds: { | ||
// Base thresholds to see if the writer or reader is working | ||
kafka_writer_error_count: ["count == 0"], | ||
kafka_reader_error_count: ["count == 0"], | ||
}, | ||
duration: "11s", | ||
}; | ||
|
||
export default function () { | ||
// Read 10 messages only | ||
let messages = reader.consume({ limit: 10 }); | ||
|
||
console.log("continuing execution"); | ||
|
||
check(messages, { | ||
"10 messages are received": (messages) => messages.length === 10, | ||
}); | ||
} | ||
|
||
export function teardown(data) { | ||
if (__VU === 0) { | ||
// Delete the topic | ||
connection.deleteTopic(topic); | ||
} | ||
reader.close(); | ||
connection.close(); | ||
} |