-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
- Loading branch information
1 parent
9cf4101
commit 903534a
Showing
9 changed files
with
392 additions
and
10 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
13 changes: 9 additions & 4 deletions
13
src/data/markdown/docs/02 javascript api/07 k6-experimental/07 grpc.md
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
66 changes: 66 additions & 0 deletions
66
...own/docs/02 javascript api/07 k6-experimental/07 grpc/30 Stream/10-Stream-on.md
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,66 @@ | ||
--- | ||
title: "Stream.on()" | ||
excerpt: 'Set up handler functions for various events on the GRPC stream.' | ||
--- | ||
|
||
Set up handler functions for various events on the GRPC stream. | ||
|
||
| Parameter | Type | Description | | ||
| --------- | -------- | -------------------------------------------- | | ||
| event | string | The event name to define a handler for. | | ||
| handler | function | The function to call when the event happens. | | ||
|
||
Possible events: | ||
|
||
| Event name | Description | | ||
| --------- | -------- | | ||
| data | Emitted when the server sends data| | ||
| error | Emitted when an error occurs. In case of the error, an [`Error`](/javascript-api/k6-experimental/grpc/stream/stream-error) object sends to the handler function.| | ||
| end | Emitted when stream closes | | ||
|
||
|
||
### Example | ||
|
||
<div class="code-group" data-props='{"labels": ["Simple example"], "lineNumbers": [true]}'> | ||
|
||
```javascript | ||
import { Client, Stream } from 'k6/experimental/grpc'; | ||
import { sleep } from 'k6'; | ||
|
||
const COORD_FACTOR = 1e7; | ||
|
||
const client = new Client(); | ||
client.load([], '../../grpc_server/route_guide.proto'); | ||
|
||
export default () => { | ||
if (__ITER == 0) { | ||
client.connect('127.0.0.1:10000', { plaintext: true }); | ||
} | ||
|
||
const stream = new Stream(client, 'main.RouteGuide/RecordRoute'); | ||
|
||
// sets up a handler for the data (server sends data) event | ||
stream.on('data', (stats) => { | ||
console.log('Finished trip with', stats.pointCount, 'points'); | ||
console.log('Passed', stats.featureCount, 'features'); | ||
console.log('Traveled', stats.distance, 'meters'); | ||
console.log('It took', stats.elapsedTime, 'seconds'); | ||
}); | ||
|
||
// sets up a handler for the end event (stream closes) | ||
stream.on('end', function () { | ||
// The server has finished sending | ||
client.close(); | ||
console.log('All done'); | ||
}); | ||
|
||
// sets up a handler for the error event (an error occurs) | ||
stream.on('error', function (e) { | ||
// An error has occurred and the stream has been closed. | ||
console.log('Error: ' + JSON.stringify(e)); | ||
}); | ||
|
||
sleep(1); | ||
}; | ||
``` | ||
</div> |
13 changes: 13 additions & 0 deletions
13
.../docs/02 javascript api/07 k6-experimental/07 grpc/30 Stream/15-Stream-error.md
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,13 @@ | ||
--- | ||
title: "Error" | ||
head_title: 'gRPC.Error' | ||
excerpt: 'The error object of a gRPC stream.' | ||
--- | ||
|
||
The error object is the object that is passed to the `error` event handler function. | ||
|
||
| Name | Type | Description | | ||
|------|------|-------------| | ||
| `Error.code` | number | A gRPC error code. | | ||
| `Error.details` | array | A list details attached to the error. | | ||
| `Error.message` | string | An original error message. | |
45 changes: 45 additions & 0 deletions
45
...wn/docs/02 javascript api/07 k6-experimental/07 grpc/30 Stream/40-Stream-end.md
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,45 @@ | ||
--- | ||
title: "Stream.end()" | ||
excerpt: 'Signals to the server that the client has finished sending.' | ||
--- | ||
|
||
Signals to the server that the client has finished sending messages. | ||
|
||
### Example | ||
|
||
<div class="code-group" data-props='{"labels": ["Simple example"], "lineNumbers": [true]}'> | ||
|
||
```javascript | ||
import { Client, Stream } from 'k6/experimental/grpc'; | ||
import { sleep } from 'k6'; | ||
|
||
const COORD_FACTOR = 1e7; | ||
|
||
const client = new Client(); | ||
client.load([], '../../grpc_server/route_guide.proto'); | ||
|
||
export default () => { | ||
if (__ITER == 0) { | ||
client.connect('127.0.0.1:10000', { plaintext: true }); | ||
} | ||
|
||
const stream = new Stream(client, 'main.RouteGuide/RecordRoute'); | ||
|
||
stream.on('data', (stats) => { | ||
console.log('Finished trip with', stats.pointCount, 'points'); | ||
console.log('Passed', stats.featureCount, 'features'); | ||
console.log('Traveled', stats.distance, 'meters'); | ||
console.log('It took', stats.elapsedTime, 'seconds'); | ||
}); | ||
|
||
// send 2 items | ||
stream.write({ latitude: 406109563, longitude: -742186778 }); | ||
stream.write({ latitude: 416802456, longitude: -742370183 }); | ||
|
||
// send end-signal to the server | ||
stream.end(); | ||
|
||
sleep(1); | ||
}; | ||
``` | ||
</div> |
41 changes: 41 additions & 0 deletions
41
.../docs/02 javascript api/07 k6-experimental/07 grpc/30 Stream/40-Stream-write.md
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,41 @@ | ||
--- | ||
title: "Stream.write()" | ||
excerpt: 'Writes a message to the stream.' | ||
--- | ||
|
||
Writes a message to the stream. | ||
|
||
### Example | ||
|
||
<div class="code-group" data-props='{"labels": ["Simple example"], "lineNumbers": [true]}'> | ||
|
||
```javascript | ||
import { Client, Stream } from 'k6/experimental/grpc'; | ||
import { sleep } from 'k6'; | ||
|
||
const COORD_FACTOR = 1e7; | ||
|
||
const client = new Client(); | ||
client.load([], '../../grpc_server/route_guide.proto'); | ||
|
||
export default () => { | ||
if (__ITER == 0) { | ||
client.connect('127.0.0.1:10000', { plaintext: true }); | ||
} | ||
|
||
const stream = new Stream(client, 'main.RouteGuide/RecordRoute'); | ||
|
||
stream.on('data', (stats) => { | ||
console.log('Finished trip with', stats.pointCount, 'points'); | ||
}); | ||
|
||
// send an item | ||
stream.write({ latitude: 406109563, longitude: -742186778 }); | ||
|
||
// send end-signal to the server | ||
stream.end(); | ||
|
||
sleep(1); | ||
}; | ||
``` | ||
</div> |
Oops, something went wrong.