fakegrpclb
v1.51.4
Documentation
pkg.go.dev ↗Package fakegrpclb provides a fake implementation of the grpclb server.
Types
Server
type Server struct {
lbgrpc.UnimplementedLoadBalancerServer
// contains filtered or unexported fields
}
Server is a fake implementation of the grpclb LoadBalancer service. It does not support stats reporting from clients, and always sends back a static list of backends to the client to balance load across.
It is safe for concurrent access.
NewServer
func NewServer(params ServerParams) (*Server, error)
NewServer creates a new Server with passed in params. Returns a non-nil error if the params are invalid.
Server.Address
func (s *Server) Address() string
Address returns the host:port on which the LoadBalancer service is serving.
Server.BalanceLoad
func (s *Server) BalanceLoad(stream lbgrpc.LoadBalancer_BalanceLoadServer) error
BalanceLoad provides a fake implementation of the LoadBalancer service.
Server.Serve
func (s *Server) Serve() error
Serve starts serving the LoadBalancer service on a gRPC server.
It returns early with a non-nil error if it is unable to start serving. Otherwise, it blocks until Stop() is called, at which point it returns the error returned by the underlying grpc.Server's Serve() method.
Server.Stop
func (s *Server) Stop()
Stop stops serving the LoadBalancer service and unblocks the preceding call to Serve().
ServerParams
type ServerParams struct {
ListenPort int // Listening port for the balancer server.
ServerOptions []grpc.ServerOption // gRPC options for the balancer server.
LoadBalancedServiceName string // Service name being load balanced for.
LoadBalancedServicePort int // Service port being load balanced for.
BackendAddresses []string // Service backends to balance load across.
ShortStream bool // End balancer stream after sending server list.
}
ServerParams wraps options passed while creating a Server.