-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfan_out_complex_test.go
82 lines (66 loc) · 1.63 KB
/
fan_out_complex_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package fanout
import (
"context"
"fmt"
"testing"
"time"
"google.golang.org/grpc"
)
//taggingDispatcher implement our dispatcher interface
type taggingDispatcher struct {
Address string
// stream proto.StreamClient
conn *grpc.ClientConn
}
type messageContent struct {
content string
priority int
}
func TestComplexStreamingFanOut(t *testing.T) {
builder := func() IDispatcher {
return &taggingDispatcher{Address: "127.0.0.2"}
}
tagging := &Tagging{
topic: "new topic",
pipeline: NewPipeline(builder, 2, true),
}
tagging.pipeline.Dispatch(messageContent{"all,please stay home", 1000})
tagging.pipeline.Start(context.Background())
//模拟处理过程,让工作者线程完成工作
time.Sleep(time.Second * 2)
t.Log("Done")
}
type Tagging struct {
topic string
pipeline *Pipeline
}
func (d *taggingDispatcher) Before(ctx context.Context) error {
fmt.Println("i'm doing somthing before processing")
conn, err := grpc.Dial(d.Address, grpc.WithInsecure())
if err != nil {
return err
}
d.conn = conn
// // // client := proto.NewClient(conn)
// // stream, err := client.StreamMetric(ctx)
// // if err != nil {
// // return err
// // }
// // d.stream = stream
return nil
}
func (d *taggingDispatcher) After() error {
// _, err := d.stream.CloseAndRecv()
// e := d.conn.Close()
// if e != nil {
// log.Error("close connection error", field.Error(e))
// }
//return err
fmt.Println("i'm doing somthing After processing")
return nil
}
func (d *taggingDispatcher) Process(msg interface{}) error {
content := msg.(messageContent)
fmt.Println("i'm doing processing,with conten", content)
return nil
}