forked from taiyoh/sqsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_test.go
54 lines (44 loc) · 1.17 KB
/
grpc_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
package sqsd
import (
"context"
"fmt"
"net"
"strconv"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
)
func TestGRPC(t *testing.T) {
l, err := net.Listen("tcp4", ":0")
assert.NoError(t, err)
assert.NotNil(t, l)
port, err := strconv.Atoi(strings.Split(l.Addr().String(), ":")[1])
assert.NoError(t, err)
l.Close()
sys := NewSystem(
GatewayBuilder(nil, "", 1, time.Hour),
ConsumerBuilder(nil, 3),
MonitorBuilder(port),
)
rCtx := sys.system.Root
distributor := rCtx.Spawn(sys.consumer.NewDistributorActorProps())
remover := rCtx.Spawn(sys.gateway.NewRemoverGroup())
worker := rCtx.Spawn(sys.consumer.NewWorkerActorProps(distributor, remover))
monitor := NewMonitoringService(rCtx, worker)
grpcServer, err := newGRPCServer(monitor, port)
assert.NoError(t, err)
grpcServer.Start()
defer grpcServer.Stop()
conn, err := grpc.Dial(
fmt.Sprintf("localhost:%d", port),
grpc.WithInsecure(),
grpc.WithBlock(),
)
assert.NoError(t, err)
client := NewMonitoringServiceClient(conn)
resp, err := client.CurrentWorkings(context.Background(), &CurrentWorkingsRequest{})
assert.NoError(t, err)
assert.NotNil(t, resp)
}