mock

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	//monitor的ip端口
	MonitorIp   = "127.0.0.1"
	MonitorPort = 8090
)
View Source
const (
	IsolatedStatus = iota
	UnhealthyStatus
)

Variables

View Source
var (
	VS = `` /* 629-byte string literal not displayed */

)

Functions

func NewMonitorServer

func NewMonitorServer() *monitorServer

创建monitor

Types

type MonitorServer

type MonitorServer interface {
	monitorpb.GrpcAPIServer
	//获取monitor接收到的熔断状态
	GetCircuitBreakStatus(svcKey model.ServiceKey) []*monitorpb.ServiceCircuitbreak
	//设置monitor接收到的熔断状态
	SetCircuitBreakCache(data []*monitorpb.ServiceCircuitbreak)
	//获取上报的缓存信息
	GetCacheReport(svcKey model.ServiceKey) []*monitorpb.ServiceInfo
	//设置monitor中上报的缓存信息
	SetCacheReport(data []*monitorpb.ServiceInfo)
	//获取服务统计
	GetSvcStat() []*monitorpb.ServiceStatistics
	//获取sdk统计
	GetSdkStat() []*monitorpb.SDKAPIStatistics
	//获取sdk配置统计
	GetSdkCfg() []*monitorpb.SDKConfig
	//设置配置统计
	SetSdkCfg(data []*monitorpb.SDKConfig)
	//设置服务统计
	SetSvcStat(data []*monitorpb.ServiceStatistics)
	//设置sdk统计
	SetSdkStat(data []*monitorpb.SDKAPIStatistics)
	SetPluginStat(data []*monitorpb.PluginAPIStatistics)
	GetPluginStat() []*monitorpb.PluginAPIStatistics
	GetLbStat() []*monitorpb.ServiceLoadBalanceInfo
	SetLbStat(data []*monitorpb.ServiceLoadBalanceInfo)
	GetRateLimitRecords() []*monitorpb.RateLimitRecord
	SetRateLimitRecords(data []*monitorpb.RateLimitRecord)
	GetServiceRouteRecords() []*monitorpb.ServiceRouteRecord
	SetServiceRouteRecords(data []*monitorpb.ServiceRouteRecord)
	GetMeshConfigRecords() []*monitorpb.MeshResourceInfo
	SetMeshConfigRecords(data []*monitorpb.MeshResourceInfo)
}

监控server

type NamingServer

type NamingServer interface {
	namingpb.PolarisGRPCServer
	//设置模拟某个方法进行超时
	MakeOperationTimeout(operation OperationType, enable bool)
	//设置强制模拟方法超时
	MakeForceOperationTimeout(operation OperationType, enable bool)
	//设置方法超时时间
	SetMethodInterval(interval time.Duration)
	//设置打印返回的服务列表信息
	SetPrintDiscoverReturn(v bool)
	//设置mockserver是否返回异常
	SetReturnException(e bool)
	//设置是否自动注册网格的辅助服务
	SetNotRegisterAssistant(e bool)
	//注册服务
	RegisterService(svc *namingpb.Service) string
	//反注册服务
	DeregisterService(namespace, service string) *namingpb.Service
	//注册限流规则
	RegisterRateLimitRule(svc *namingpb.Service, rateLimit *namingpb.RateLimit) error
	//注销限流规则
	DeRegisterRateLimitRule(svc *namingpb.Service)
	//注册网格规则
	RegisterMeshConfig(svc *namingpb.Service, mtype string, mc *namingpb.MeshConfig)
	RegisterMesh(svc *namingpb.Service, mtype string, mc *namingpb.Mesh)
	//注销网格规则
	DeRegisterMeshConfig(svc *namingpb.Service, meshID, mtype string)
	//注册路由规则
	RegisterRouteRule(svc *namingpb.Service, routing *namingpb.Routing) error
	//反注册路由规则
	DeregisterRouteRule(svc *namingpb.Service)
	//注册命名空间
	RegisterNamespace(namespace *namingpb.Namespace)
	//反注册命名空间
	DeregisterNamespace(name string)
	//构建系统服务的路由规则
	BuildRouteRule(namespace string, name string) *namingpb.Routing
	//注册服务实例
	RegisterServerInstance(host string, port int, name string, token string, health bool) *namingpb.Instance

	RegisterServerInstanceReturnId(host string, port int, name string, token string, health bool) string
	//批量注册服务实例
	RegisterServiceInstances(svc *namingpb.Service, instances []*namingpb.Instance)
	//直接获取服务实例
	GetServiceInstances(key *model.ServiceKey) []*namingpb.Instance
	//注册系统服务,返回服务token
	RegisterServerService(name string) string
	//注册所有系统服务以及对应的服务实例
	RegisterServerServices(host string, port int)
	//清空某个测试服务的实例
	ClearServiceInstances(svc *namingpb.Service)
	//设置服务的元数据信息
	SetServiceMetadata(token string, key string, value string)
	//为服务生成N个随机服务实例
	GenTestInstances(svc *namingpb.Service, num int) []*namingpb.Instance
	//删除测试实例
	DeleteServerInstance(namespace string, service string, id string)
	//修改系统服务实例权重
	UpdateServerInstanceWeight(namespace string, service string, id string, weight uint32)
	//修改系统服务实例健康状态
	UpdateServerInstanceHealthy(namespace string, service string, id string, healthy bool)
	//修改系统服务实例隔离状态
	UpdateServerInstanceIsolate(namespace string, service string, id string, isolate bool)
	//产生测试用实例,带上地址端口号,权重随机生成
	GenTestInstancesWithHostPort(svc *namingpb.Service, num int, host string, startPort int) []*namingpb.Instance

	GenTestInstancesWithHostPortAndMeta(
		svc *namingpb.Service, num int, host string, startPort int, metadata map[string]string) []*namingpb.Instance
	//产生测试用实例,带上元数据,权重随机生成
	GenTestInstancesWithMeta(svc *namingpb.Service, num int, metadata map[string]string) []*namingpb.Instance
	//产生测试用实例,带上状态信息,权重随机生成
	GenInstancesWithStatus(svc *namingpb.Service, num int, st int, startPort int) []*namingpb.Instance
	//设置地域信息
	SetLocation(region, zone, campus string)
	//设置某个服务的实例
	SetServiceInstances(key *model.ServiceKey, insts []*namingpb.Instance)
	//获取地域信息
	GetLocation() (region, zone, campus string)
	//获取服务请求
	GetServiceRequests(key *model.ServiceKey) int
	//清空服务请求
	ClearServiceRequests(key *model.ServiceKey)
	//获取服务token
	GetServiceToken(key *model.ServiceKey) string
	//设置服务版本号
	SetServiceRevision(token string, revision string, k model.ServiceEventKey)
	//插入一个路由信息
	InsertRouting(svcKey model.ServiceKey, routing *namingpb.Routing)
	//设置某个服务的某个实例的状态(健康、隔离、权重)
	SetInstanceStatus(svcKey model.ServiceKey, idx int, healthy bool, isolate bool, weight uint32) error
	//设置首次不返回某个请求
	SetFirstNoReturn(svcKey model.ServiceEventKey)
	//反设置首次不返回某个请求
	UnsetFirstNoReturn(svcKey model.ServiceEventKey)
}

测试桩相关接口

func NewNamingServer

func NewNamingServer() NamingServer

创建NamingServer模拟桩

type OperationType

type OperationType string

操作类型

const (
	//服务发现实例接口操作
	OperationDiscoverInstance OperationType = "discoverInstance"
	//服务发现路由接口操作
	OperationDiscoverRouting OperationType = "discoverRouting"
	//服务注册接口
	OperationRegistry OperationType = "registry"
	//服务反注册接口
	OperationDeRegistry OperationType = "deregistry"
	//健康检查接口
	OperationHeartbeat OperationType = "heartbeat"
)

Jump to

Keyboard shortcuts

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