diff --git a/network_crawler.go b/network_crawler.go index 177f993..be6464e 100644 --- a/network_crawler.go +++ b/network_crawler.go @@ -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{}) } diff --git a/network_crawler_test.go b/network_crawler_test.go index c7a76cf..bdec158 100644 --- a/network_crawler_test.go +++ b/network_crawler_test.go @@ -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 --> diff --git a/config_server.go b/server_config.go similarity index 100% rename from config_server.go rename to server_config.go diff --git a/data_server.go b/server_data.go similarity index 100% rename from data_server.go rename to server_data.go diff --git a/server_status.go b/server_status.go new file mode 100644 index 0000000..65c2b9e --- /dev/null +++ b/server_status.go @@ -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 +} +