mosn

Форк
0
/
flowcontrol_test.go 
80 строк · 1.7 Кб
1
//go:build MOSNTest
2
// +build MOSNTest
3

4
package grpc
5

6
import (
7
	"context"
8
	"testing"
9

10
	"google.golang.org/grpc"
11
	pb "google.golang.org/grpc/examples/helloworld/helloworld"
12
	. "mosn.io/mosn/test/framework"
13
	"mosn.io/mosn/test/lib"
14
)
15

16
func TestGrpcFlowControl(t *testing.T) {
17
	Scenario(t, "flow control grpc server in mosn", func() {
18
		_, _ = lib.InitMosn(ConfigFlowControlGrpcFilter) // no servers need
19
		Case("call grpc", func() {
20
			conn, err := grpc.Dial("127.0.0.1:2045", grpc.WithInsecure(), grpc.WithBlock())
21
			Verify(err, Equal, nil)
22
			defer conn.Close()
23
			c := pb.NewGreeterClient(conn)
24
			for i := 0; i < 2; i++ {
25
				r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: "mosn grpc"})
26
				if i == 0 {
27
					Verify(err, Equal, nil)
28
					Verify(r.GetMessage(), Equal, "Hello mosn grpc")
29
				} else if i == 1 {
30
					Verify(err, NotNil)
31
					Verify(err.Error(), Equal, "rpc error: code = Unknown desc = current request is limited")
32
				}
33
			}
34
		})
35
	})
36
}
37

38
const ConfigFlowControlGrpcFilter = `{
39
	"servers":[
40
		{
41
			"default_log_path":"stdout",
42
			"default_log_level":"DEBUG",
43
			"listeners":[
44
				{
45
					"address":"127.0.0.1:2045",
46
					"bind_port": true,
47
					"filter_chains": [{
48
						"filters": [
49
							{
50
								"type":"grpc",
51
								"config": {
52
									"server_name":"hello"
53
								}
54
							}
55
						]
56
					}],
57
					"stream_filters": [
58
						{
59
							"type": "flowControlFilter",
60
							"config": {
61
								"global_switch": true,
62
								"monitor": false,
63
								"limit_key_type": "PATH",
64
								"rules": [
65
									{
66
										"resource": "/helloworld.Greeter/SayHello",
67
										"limitApp": "",
68
										"grade": 1,
69
										"threshold": 1,
70
										"strategy": 0
71
									}
72
								]
73
							}
74
						}
75
					]
76
				}
77
			]
78
		}
79
	]
80
}`
81

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.