mock

package
v1.2.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	IsolatedStatus = iota
	UnhealthyStatus
)

Variables

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

)

Functions

This section is empty.

Types

type NamingServer

type NamingServer interface {
	namingpb.PolarisGRPCServer
	// MakeOperationTimeout 设置模拟某个方法进行超时
	MakeOperationTimeout(operation OperationType, enable bool)
	// MakeForceOperationTimeout 设置强制模拟方法超时
	MakeForceOperationTimeout(operation OperationType, enable bool)
	// SetMethodInterval 设置方法超时时间
	SetMethodInterval(interval time.Duration)
	// SetPrintDiscoverReturn 设置打印返回的服务列表信息
	SetPrintDiscoverReturn(v bool)
	// SetReturnException 设置mockserver是否返回异常
	SetReturnException(e bool)
	// SetNotRegisterAssistant 设置是否自动注册网格的辅助服务
	SetNotRegisterAssistant(e bool)
	// RegisterService 注册服务
	RegisterService(svc *namingpb.Service) string
	// DeregisterService 反注册服务
	DeregisterService(namespace, service string) *namingpb.Service
	// RegisterRateLimitRule 注册限流规则
	RegisterRateLimitRule(svc *namingpb.Service, rateLimit *namingpb.RateLimit) error
	// DeRegisterRateLimitRule 注销限流规则
	DeRegisterRateLimitRule(svc *namingpb.Service)
	// RegisterMeshConfig 注册网格规则
	RegisterMeshConfig(svc *namingpb.Service, mtype string, mc *namingpb.MeshConfig)
	// RegisterMesh 注册网格
	RegisterMesh(svc *namingpb.Service, mtype string, mc *namingpb.Mesh)
	// DeRegisterMeshConfig 注销网格规则
	DeRegisterMeshConfig(svc *namingpb.Service, meshID, mtype string)
	// RegisterRouteRule 注册路由规则
	RegisterRouteRule(svc *namingpb.Service, routing *namingpb.Routing) error
	// DeregisterRouteRule 反注册路由规则
	DeregisterRouteRule(svc *namingpb.Service)
	// RegisterNamespace 注册命名空间
	RegisterNamespace(namespace *namingpb.Namespace)
	// DeregisterNamespace 反注册命名空间
	DeregisterNamespace(name string)
	// BuildRouteRule 构建系统服务的路由规则
	BuildRouteRule(namespace string, name string) *namingpb.Routing
	// RegisterServerInstance 注册服务实例
	RegisterServerInstance(host string, port int, name string, token string, health bool) *namingpb.Instance
	// RegisterServerInstanceReturnId .
	RegisterServerInstanceReturnId(host string, port int, name string, token string, health bool) string
	// RegisterServiceInstances 批量注册服务实例
	RegisterServiceInstances(svc *namingpb.Service, instances []*namingpb.Instance)
	// GetServiceInstances 直接获取服务实例
	GetServiceInstances(key *model.ServiceKey) []*namingpb.Instance
	// RegisterServerService 注册系统服务,返回服务token
	RegisterServerService(name string) string
	// RegisterServerServices 注册所有系统服务以及对应的服务实例
	RegisterServerServices(host string, port int)
	// ClearServiceInstances 清空某个测试服务的实例
	ClearServiceInstances(svc *namingpb.Service)
	// SetServiceMetadata 设置服务的元数据信息
	SetServiceMetadata(token string, key string, value string)
	// GenTestInstances 为服务生成N个随机服务实例
	GenTestInstances(svc *namingpb.Service, num int) []*namingpb.Instance
	// DeleteServerInstance 删除测试实例
	DeleteServerInstance(namespace string, service string, id string)
	// UpdateServerInstanceWeight 修改系统服务实例权重
	UpdateServerInstanceWeight(namespace string, service string, id string, weight uint32)
	// UpdateServerInstanceHealthy 修改系统服务实例健康状态
	UpdateServerInstanceHealthy(namespace string, service string, id string, healthy bool)
	// UpdateServerInstanceIsolate 修改系统服务实例隔离状态
	UpdateServerInstanceIsolate(namespace string, service string, id string, isolate bool)
	// GenTestInstancesWithHostPort 产生测试用实例,带上地址端口号,权重随机生成
	GenTestInstancesWithHostPort(svc *namingpb.Service, num int, host string, startPort int) []*namingpb.Instance

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

NamingServer 测试桩相关接口

func NewNamingServer

func NewNamingServer() NamingServer

NewNamingServer 创建NamingServer模拟桩

type OperationType

type OperationType string

操作类型

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

Jump to

Keyboard shortcuts

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