sofarpc

package
v0.0.0-...-78a648b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBoltV1Serve = &BoltV1Serve{
	Configs: []*BoltV1ReponseConfig{
		{
			Builder: DefaultBuilder,
		},
	},
}
View Source
var DefaultBuilder = &BoltV1ResponseBuilder{
	Status: sofarpc.RESPONSE_STATUS_SUCCESS,
	Header: map[string]string{
		"mosn-test-default": "boltv1",
	},
	Content: buffer.NewIoBufferString("default-boltv1"),
}
View Source
var DefaultVeirfy = &VerifyConfig{
	ExpectedStatus: sofarpc.RESPONSE_STATUS_SUCCESS,
}
View Source
var ErrorBuilder = &BoltV1ResponseBuilder{
	Status: sofarpc.RESPONSE_STATUS_ERROR,
	Header: map[string]string{
		"error-message": "no matched config",
	},
}

Functions

func BuildBoltV1Request

func BuildBoltV1Request(id uint64, header map[string]string, body []byte) (types.HeaderMap, types.IoBuffer)

Types

type BoltV1ReponseConfig

type BoltV1ReponseConfig struct {
	ExpectedHeader      map[string]string
	UnexpectedHeaderKey []string
	Builder             *BoltV1ResponseBuilder
}

TODO: Support More

func (*BoltV1ReponseConfig) Match

func (cfg *BoltV1ReponseConfig) Match(header map[string]string) bool

type BoltV1ResponseBuilder

type BoltV1ResponseBuilder struct {
	Status  int16
	Header  map[string]string
	Content types.IoBuffer
}

func (*BoltV1ResponseBuilder) Build

type BoltV1Serve

type BoltV1Serve struct {
	Configs []*BoltV1ReponseConfig
}

func (*BoltV1Serve) MakeResponse

func (s *BoltV1Serve) MakeResponse(req *sofarpc.BoltRequest) sofarpc.SofaRpcCmd

func (*BoltV1Serve) Serve

func (s *BoltV1Serve) Serve(reqdata types.IoBuffer) *WriteResponseData

type Client

type Client struct {
	Cfg *ClientConfig
	// Stats
	Stats *ClientStats
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *ClientConfig, maxConnections uint32) *Client

func (*Client) Close

func (c *Client) Close()

Close All the connections

func (*Client) SyncCall

func (c *Client) SyncCall() bool

type ClientConfig

type ClientConfig struct {
	Addr          string
	MakeRequest   MakeRequestFunc
	RequestHeader map[string]string
	RequestBody   []byte
	// request timeout is used for sync call
	// if zero, we set default request time, 5 second
	RequestTImeout time.Duration
	// if Verify is nil, just expected returns success
	Verify ResponseVerify
}

func CreateSimpleConfig

func CreateSimpleConfig(addr string) *ClientConfig

type ClientStats

type ClientStats struct {
	*ServerStats
	// contains filtered or unexported fields
}

func NewClientStats

func NewClientStats() *ClientStats

func (*ClientStats) ExpectedResponse

func (c *ClientStats) ExpectedResponse() (uint32, uint32)

func (*ClientStats) Response

func (c *ClientStats) Response(expected bool)

type ConnClient

type ConnClient struct {
	MakeRequest MakeRequestFunc
	SyncTimeout time.Duration
	// contains filtered or unexported fields
}

func NewConnClient

func NewConnClient(addr string, f MakeRequestFunc) (*ConnClient, error)

func (*ConnClient) Close

func (c *ConnClient) Close()

func (*ConnClient) IsClosed

func (c *ConnClient) IsClosed() bool

func (*ConnClient) OnEvent

func (c *ConnClient) OnEvent(event types.ConnectionEvent)

func (*ConnClient) SyncSend

func (c *ConnClient) SyncSend(header map[string]string, body []byte) (*Response, error)

type MakeRequestFunc

type MakeRequestFunc func(id uint64, header map[string]string, body []byte) (types.HeaderMap, types.IoBuffer)

type MockServer

type MockServer struct {
	Addr      string
	ServeFunc ServeFunc

	// stats
	ServerStats *ServerStats
	// contains filtered or unexported fields
}

func NewMockServer

func NewMockServer(addr string, f ServeFunc) *MockServer

func (*MockServer) Close

func (srv *MockServer) Close()

func (*MockServer) Serve

func (srv *MockServer) Serve(id uint64, conn net.Conn)

func (*MockServer) SetConnectionIdleTimeout

func (srv *MockServer) SetConnectionIdleTimeout(d time.Duration)

func (*MockServer) SetResponseDelay

func (srv *MockServer) SetResponseDelay(d time.Duration)

func (*MockServer) Start

func (srv *MockServer) Start()

type Response

type Response struct {
	Status uint32
	Header map[string]string
	Data   []byte
	Cost   time.Duration
}

Client

type ResponseVerify

type ResponseVerify func(*Response) bool

type ServeFunc

type ServeFunc func(types.IoBuffer) *WriteResponseData

Server

type ServerStats

type ServerStats struct {
	// contains filtered or unexported fields
}

func NewServerStats

func NewServerStats() *ServerStats

func (*ServerStats) ActiveConnection

func (s *ServerStats) ActiveConnection()

func (*ServerStats) CloseConnection

func (s *ServerStats) CloseConnection()

func (*ServerStats) ConnectionStats

func (s *ServerStats) ConnectionStats() (uint32, uint32, uint32)

func (*ServerStats) Request

func (s *ServerStats) Request()

func (*ServerStats) RequestStats

func (s *ServerStats) RequestStats() uint32

func (*ServerStats) Response

func (s *ServerStats) Response(status int16)

func (*ServerStats) ResponseStats

func (s *ServerStats) ResponseStats() map[int16]uint32

type VerifyConfig

type VerifyConfig struct {
	ExpectedStatus int16
	// if ExepctedHeader is nil, means do not care about header
	// if ExepctedHeader is exists, means resposne Header should contain all the ExpectedHeader
	// TODO :  support regex
	ExpectedHeader map[string]string
	// if ExpectedBody is nil, means do not care about body
	// TODO: support regex
	ExpectedBody []byte
	// if ExpectedRT is zero, means do not care about rt
	// if ExpectedRT is not zero, means response's rt should no more than it
	ExpectedRT time.Duration
	// if MinRT is zero means do not care about it
	// if MinRT is not zero, means response's rt should more than it
	MinRT time.Duration
}

func (*VerifyConfig) Verify

func (cfg *VerifyConfig) Verify(resp *Response) bool

type WriteResponseData

type WriteResponseData struct {
	Status      int16
	DataToWrite []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL