boltv2

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClosedConnection = errors.New("send request on closed connection")
	ErrRequestTimeout   = errors.New("sync call timeout")
)
View Source
var DefaultErrorBuilder = &ResponseBuilder{
	StatusCode: int16(bolt.ResponseStatusError),
}
View Source
var DefaultSucessBuilder = &ResponseBuilder{
	StatusCode: int16(bolt.ResponseStatusSuccess),
}

Functions

func NewBoltClient

func NewBoltClient(config interface{}) types.MockClient

func NewBoltServer

func NewBoltServer(config interface{}) types.MockServer

TODO: make xprotocol server

Types

type BoltClientConfig

type BoltClientConfig struct {
	TargetAddr string         `json:"target_address"`
	MaxConn    uint32         `json:"max_connection"`
	Request    *RequestConfig `json:"request_config"`
	Verify     *VerifyConfig  `json:"verify_config"`
}

func NewBoltClientConfig

func NewBoltClientConfig(config interface{}) (*BoltClientConfig, error)

type BoltConn

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

func NewConn

func NewConn(addr string, cb func()) (*BoltConn, error)

func (*BoltConn) AsyncSendRequest

func (c *BoltConn) AsyncSendRequest(receiver *receiver, req *RequestConfig)

func (*BoltConn) Close

func (c *BoltConn) Close()

func (*BoltConn) IsClosed

func (c *BoltConn) IsClosed() bool

func (*BoltConn) OnEvent

func (c *BoltConn) OnEvent(event api.ConnectionEvent)

func (*BoltConn) ReqID

func (c *BoltConn) ReqID() uint32

func (*BoltConn) SyncSendRequest

func (c *BoltConn) SyncSendRequest(req *RequestConfig) (*Response, error)

type BoltServerConfig

type BoltServerConfig struct {
	Addr string                     `json:"address"`
	Mux  map[string]*ResponseConfig `json:"mux_config"`
}

func NewBoltServerConfig

func NewBoltServerConfig(config interface{}) (*BoltServerConfig, error)

type Condition

type Condition struct {
	// If a request contains the expected header, matched this condition.
	// A request must have the configured header key and value, and can have others headers
	// which will be ingored.
	ExpectedHeader map[string]string `json:"expected_header"`
	// If a request contains the unexpected header, matched failed.
	UnexpectedHeaderKey []string `json:"unexpected_header_key"`
}

func (*Condition) Match

func (cond *Condition) Match(req *boltv2.Request) bool

type ConnectionManager

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

func (*ConnectionManager) Add

func (mgr *ConnectionManager) Add(conn net.Conn) uint64

func (*ConnectionManager) Clean

func (mgr *ConnectionManager) Clean()

func (*ConnectionManager) Delete

func (mgr *ConnectionManager) Delete(id uint64)

type MockBoltClient

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

MockBoltClient use mosn xprotocol.bolt protocol and stream

func (*MockBoltClient) AsyncCall

func (c *MockBoltClient) AsyncCall()

TODO: implement it

func (*MockBoltClient) Close

func (c *MockBoltClient) Close()

Close will close all the connections

func (*MockBoltClient) Stats

func (*MockBoltClient) SyncCall

func (c *MockBoltClient) SyncCall() bool

type MockBoltServer

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

func (*MockBoltServer) Start

func (s *MockBoltServer) Start()

func (*MockBoltServer) Stats

func (*MockBoltServer) Stop

func (s *MockBoltServer) Stop()

type RequestConfig

type RequestConfig struct {
	Header  map[string]string `json:"header"`
	Body    json.RawMessage   `json:"body"`
	Timeout time.Duration     `json:"timeout"` // request timeout
}

RequestConfig decides what request to send

func (*RequestConfig) BuildRequest

func (c *RequestConfig) BuildRequest(id uint32) (api.HeaderMap, buffer.IoBuffer)

type Response

type Response struct {
	Header  boltv2.ResponseHeader
	Content buffer.IoBuffer
	Cost    time.Duration
}

func (*Response) GetResponseStatus

func (r *Response) GetResponseStatus() int16

type ResponseBuilder

type ResponseBuilder struct {
	// The response status code
	StatusCode int16 `json:"status_code"`
	// The response header that not contains the protocol header part.
	Header map[string]string `json:"header"`
	// The repsonse body content
	Body json.RawMessage `json:"body"`
}

ResponseBuilder builds a boltv2 response based on the boltv2 request

func (*ResponseBuilder) Build

func (b *ResponseBuilder) Build(req *boltv2.Request) (*boltv2.Response, int16)

type ResponseConfig

type ResponseConfig struct {
	Condition     *Condition       `json:"condition"`
	CommonBuilder *ResponseBuilder `json:"common_builder"`
	ErrorBuilder  *ResponseBuilder `json:"error_buidler"`
}

func (*ResponseConfig) HandleRequest

func (c *ResponseConfig) HandleRequest(req *boltv2.Request, engine api.XProtocol) (resp api.XRespFrame, status int16)

type ResponseToWrite

type ResponseToWrite struct {
	StatusCode int16
	Body       []byte
}

type VerifyConfig

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

VerifyConfig describes what response want

func (*VerifyConfig) Verify

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

Jump to

Keyboard shortcuts

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