Skip to content

Commit

Permalink
add grpc echo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vordimous committed Nov 8, 2024
1 parent 99a2f8e commit 64a0321
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 14 deletions.
6 changes: 3 additions & 3 deletions grpc.echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Listens on tcp port `7151` and will echo grpc message sent by client.

## Requirements

- jq, nc, grpcurl
- Compose compatible host
- [grpcurl](https://github.com/fullstorydev/grpcurl)
- [ghz](https://ghz.sh/docs/install)

## Setup
Expand All @@ -29,7 +29,7 @@ docker compose up -d
Echo `{"message":"Hello World"}` message via unary rpc using `grpcurl` command.

```bash
grpcurl -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 example.EchoService.EchoUnary
grpcurl -plaintext -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 example.EchoService.EchoUnary
```

output:
Expand All @@ -45,7 +45,7 @@ output:
Echo messages via bidirectional streaming rpc.

```bash
grpcurl -insecure -proto echo.proto -d @ localhost:7151 example.EchoService.EchoBidiStream
grpcurl -plaintext -proto echo.proto -d @ localhost:7151 example.EchoService.EchoBidiStream
```

Paste below message.
Expand Down
60 changes: 60 additions & 0 deletions grpc.echo/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
set -x

EXIT=0

# GIVEN
PORT="7151"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}'
echo \# Testing grpc.echo/example.EchoService.EchoUnary
echo PORT="$PORT"
echo INPUT="$INPUT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT example.EchoService.EchoUnary)
RESULT=$?
echo RESULT="$RESULT"
# THEN
echo OUTPUT="$OUTPUT"
echo EXPECTED="$EXPECTED"
echo
if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then
echo
else
echo
EXIT=1
fi

# GIVEN
PORT="7151"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}'
echo \# Testing grpc.echo/example.EchoService.EchoBidiStream
echo PORT="$PORT"
echo INPUT="$INPUT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT example.EchoService.EchoBidiStream)
RESULT=$?
echo RESULT="$RESULT"
# THEN
echo OUTPUT="$OUTPUT"
echo EXPECTED="$EXPECTED"
echo
if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then
echo
else
echo
EXIT=1
fi

exit $EXIT
7 changes: 4 additions & 3 deletions grpc.kafka.echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Listens on https port `7151` and will exchange grpc message in protobuf format t

## Requirements

- jq, nc, grpcurl
- jq
- Compose compatible host
- [grpcurl](https://github.com/fullstorydev/grpcurl)
- [ghz](https://ghz.sh/docs/install)

## Setup
Expand All @@ -29,7 +30,7 @@ docker compose up -d
Echo `{"message":"Hello World"}` message via unary rpc using `grpcurl` client.

```bash
grpcurl -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho
grpcurl -plaintext -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho
```

output:
Expand Down Expand Up @@ -98,7 +99,7 @@ output:
Echo messages via bidirectional streaming rpc.

```bash
grpcurl -insecure -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho
grpcurl -plaintext -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho
```

Paste below message.
Expand Down
3 changes: 1 addition & 2 deletions grpc.kafka.echo/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ services:
command:
- |
echo -e "Creating kafka topic";
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic items-requests
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic items-responses --config cleanup.policy=compact
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --create --if-not-exists --topic echo-messages
echo -e "Successfully created the following topics:";
/opt/bitnami/kafka/bin/kafka-topics.sh --bootstrap-server kafka:29092 --list;
Expand Down
62 changes: 62 additions & 0 deletions grpc.kafka.echo/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh
set -x

EXIT=0

# GIVEN
PORT="7151"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}'
echo \# Testing grpc.kafka.echo/UnaryEcho
echo PORT="$PORT"
echo INPUT="$INPUT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT grpc.examples.echo.Echo.UnaryEcho)
RESULT=$?
echo RESULT="$RESULT"

# THEN
echo OUTPUT="$OUTPUT"
echo EXPECTED="$EXPECTED"
echo
if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then
echo
else
echo
EXIT=1
fi

# GIVEN
PORT="7151"
INPUT='{"message":"Hello World"}'
EXPECTED='{
"message": "Hello World"
}'
echo \# Testing grpc.kafka.echo/BidirectionalStreamingEcho
echo PORT="$PORT"
echo INPUT="$INPUT"
echo EXPECTED="$EXPECTED"
echo

# WHEN
OUTPUT=$(docker run --rm -v ./echo.proto:/echo.proto fullstorydev/grpcurl -plaintext -proto echo.proto -d "$INPUT" host.docker.internal:$PORT grpc.examples.echo.Echo.BidirectionalStreamingEcho)
RESULT=$?
echo RESULT="$RESULT"

# THEN
echo OUTPUT="$OUTPUT"
echo EXPECTED="$EXPECTED"
echo
if [ "$RESULT" -eq 0 ] && [ "$OUTPUT" = "$EXPECTED" ]; then
echo
else
echo
EXIT=1
fi

exit $EXIT
5 changes: 3 additions & 2 deletions grpc.kafka.fanout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Listens on https port `7151` and fanout messages from `messages` topic in Kafka.

## Requirements

- jq, nc, grpcurl, protoc
- jq, protoc
- Compose compatible host
- [grpcurl](https://github.com/fullstorydev/grpcurl)

## Setup

Expand Down Expand Up @@ -41,7 +42,7 @@ docker compose -p zilla-grpc-kafka-fanout exec kafkacat \
Stream messages via server streaming rpc.

```bash
grpcurl -insecure -proto fanout.proto -d '' localhost:7151 example.FanoutService.FanoutServerStream
grpcurl -plaintext -proto fanout.proto -d '' localhost:7151 example.FanoutService.FanoutServerStream
```

output:
Expand Down
7 changes: 4 additions & 3 deletions grpc.kafka.proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Listens on https port `7151` and uses kafka as proxy to talk to `grpc-echo` on t

## Requirements

- jq, nc, grpcurl
- jq
- Compose compatible host
- [grpcurl](https://github.com/fullstorydev/grpcurl)

## Setup

Expand All @@ -28,7 +29,7 @@ docker compose up -d
Echo `{"message":"Hello World"}` message via unary rpc.

```bash
grpcurl -insecure -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho
grpcurl -plaintext -proto echo.proto -d '{"message":"Hello World"}' localhost:7151 grpc.examples.echo.Echo.UnaryEcho
```

output:
Expand Down Expand Up @@ -97,7 +98,7 @@ output:
Echo messages via bidirectional streaming rpc.

```bash
grpcurl -insecure -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho <<EOM
grpcurl -plaintext -proto echo.proto -d @ localhost:7151 grpc.examples.echo.Echo.BidirectionalStreamingEcho <<EOM
{"message":"Hello World, first"}
{"message":"Hello World, stream"}
{"message":"Hello World, stream"}
Expand Down
2 changes: 1 addition & 1 deletion grpc.proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Listens on https port `7151` and will echo back whatever is published to `grpc-e

## Requirements

- jq, nc, grpcurl
- Compose compatible host
- [grpcurl](https://github.com/fullstorydev/grpcurl)

## Setup

Expand Down

0 comments on commit 64a0321

Please sign in to comment.