of_rpc => grpc
This commit is contained in:
parent
9334f6c70b
commit
e1747396da
|
@ -49,7 +49,7 @@ func initCrawlers() {
|
|||
//AddDelegate(pb.Crawlers_HEALTH_HTTP.String(), http_protocol_crawler_go.NewHTTPHealthCrawler())
|
||||
}
|
||||
|
||||
func start(rc pb.ConfigServer, rd pb.DataServer) {
|
||||
func start(rc pb.ConfigServer, rd pb.DataServer, rs pb.StatusServer) {
|
||||
|
||||
port := flag.String("Port", "50000", "RPC Port Default 50000")
|
||||
flag.Parse()
|
||||
|
@ -63,6 +63,7 @@ func start(rc pb.ConfigServer, rd pb.DataServer) {
|
|||
s := grpc.NewServer()
|
||||
pb.RegisterConfigServer(s, rc)
|
||||
pb.RegisterDataServer(s, rd)
|
||||
pb.RegisterStatusServer(s, rs)
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
}
|
||||
|
@ -70,5 +71,5 @@ func start(rc pb.ConfigServer, rd pb.DataServer) {
|
|||
|
||||
func main() {
|
||||
initCrawlers()
|
||||
start(&ConfigServer{}, &DataServer{})
|
||||
start(&ConfigServer{}, &DataServer{}, &StatusServer{})
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ type call func() crawler.Crawler
|
|||
func startRPCServerTest(cc call) {
|
||||
rr := cc()
|
||||
AddDelegate(pb.Crawlers_HEALTH_REDIS.String(), rr)
|
||||
go start(&ConfigServer{}, &DataServer{})
|
||||
go start(&ConfigServer{}, &DataServer{},&StatusServer{})
|
||||
}
|
||||
|
||||
func clientCall(t *testing.T, cl pb.Crawlers) {
|
||||
|
@ -68,6 +68,30 @@ func TestRedisGRPC(t *testing.T) {
|
|||
clientCall(t, pb.Crawlers_HEALTH_REDIS)
|
||||
}
|
||||
|
||||
func TestStatusCall(t *testing.T) {
|
||||
go startRPCServerTest(func()crawler.Crawler {return nil })
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
conn, err := grpc.Dial("localhost:50000", grpc.WithInsecure())
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
c := pb.NewStatusClient(conn)
|
||||
|
||||
in := &pb.Empty{}
|
||||
|
||||
out, err := c.Status(context.Background(), in)
|
||||
if err != nil {
|
||||
log.Fatalf("could not greet: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, true, out.Check)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//type configcall func()
|
||||
//
|
||||
//////////////////////////////////////// redis rpc test start -->
|
||||
|
|
16
server_status.go
Normal file
16
server_status.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import(
|
||||
"golang.org/x/net/context"
|
||||
pb "loafle.com/overflow/crawler_go/grpc"
|
||||
)
|
||||
|
||||
type StatusServer struct {
|
||||
}
|
||||
|
||||
func (s *StatusServer) Status(c context.Context, in *pb.Empty) (*pb.Boolean, error) {
|
||||
output := &pb.Boolean{}
|
||||
output.Check =true
|
||||
return output, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user