package fakegrpclb

import "google.golang.org/grpc/internal/testutils/fakegrpclb"

Package fakegrpclb provides a fake implementation of the grpclb server.

Index

Types

type 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.

func 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.

func (*Server) Address

func (s *Server) Address() string

Address returns the host:port on which the LoadBalancer service is serving.

func (*Server) BalanceLoad

func (s *Server) BalanceLoad(stream lbgrpc.LoadBalancer_BalanceLoadServer) error

BalanceLoad provides a fake implementation of the LoadBalancer service.

func (*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.

func (*Server) Stop

func (s *Server) Stop()

Stop stops serving the LoadBalancer service and unblocks the preceding call to Serve().

type 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.

Source Files

server.go

Version
v1.70.0 (latest)
Published
Jan 23, 2025
Platform
linux/amd64
Imports
14 packages
Last checked
14 seconds ago

Tools for package owners.