function_regression_tests

package
v1.1.26 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

Outbox 功能回归测试套件

概述

这是 jxt-core Outbox 组件的功能回归测试套件,用于验证 Outbox 模式的核心功能和改进特性。

测试文件结构

jxt-core/tests/outbox/function_regression_tests/
├── README.md                      # 本文档
├── test_helper.go                 # 测试辅助工具和 Mock 实现
├── uuid_generation_test.go        # UUID 生成功能测试
├── idempotency_test.go            # 幂等性功能测试
└── event_lifecycle_test.go        # 事件生命周期测试

测试覆盖

1. UUID 生成测试 (uuid_generation_test.go)

测试 UUIDv7/UUIDv4 生成机制:

  • 基本生成:验证 UUID 格式和有效性
  • 唯一性:生成 1000 个 UUID 验证无重复
  • 并发安全:100 个 goroutine 并发生成 10000 个 UUID
  • 时间排序:验证 UUIDv7 的时间排序特性
  • 格式验证:验证 UUID 格式(8-4-4-4-12)
  • 性能测试:验证 10000 个 UUID 生成性能
  • 稳定性测试:多次运行确保无 panic
  • 不同聚合根:验证不同聚合类型的 UUID 生成
  • 降级机制:验证 UUIDv7 失败时降级到 UUIDv4

测试用例:

  • TestUUIDGeneration_Basic
  • TestUUIDGeneration_Uniqueness
  • TestUUIDGeneration_Concurrent
  • TestUUIDGeneration_TimeOrdering
  • TestUUIDGeneration_Format
  • TestUUIDGeneration_Performance
  • TestUUIDGeneration_Stability
  • TestUUIDGeneration_DifferentAggregates
  • TestUUIDGeneration_Fallback
2. 幂等性测试 (idempotency_test.go)

测试幂等性键生成和检查机制:

  • 自动生成:验证幂等性键自动生成
  • 自定义键:验证自定义幂等性键
  • 唯一性:验证不同事件生成不同幂等性键
  • 相同事件不同 ID:验证相同参数事件的幂等性键
  • 发布器检查:验证发布器的幂等性检查逻辑
  • 不同租户:验证不同租户的幂等性隔离
  • 键格式:验证幂等性键格式规范
  • 空字段处理:验证空字段的幂等性键生成
  • 特殊字符:验证特殊字符的幂等性键处理
  • 并发发布:验证并发发布的幂等性保证
  • 批量发布:验证批量发布的幂等性检查

测试用例:

  • TestIdempotency_AutoGeneration
  • TestIdempotency_CustomKey
  • TestIdempotency_UniqueKeys
  • TestIdempotency_SameEventDifferentIDs
  • TestIdempotency_PublisherCheck
  • TestIdempotency_DifferentTenants
  • TestIdempotency_KeyFormat
  • TestIdempotency_EmptyFields
  • TestIdempotency_SpecialCharacters
  • TestIdempotency_ConcurrentPublish
  • TestIdempotency_BatchPublish
3. 事件生命周期测试 (event_lifecycle_test.go)

测试事件状态转换和生命周期管理:

  • 初始状态:验证事件创建时的初始状态
  • 发布成功:验证发布成功后的状态变化
  • 发布失败:验证发布失败后的状态变化
  • 重试机制:验证重试次数和状态转换
  • 状态转换:验证所有状态转换路径
  • 延迟发布:验证计划发布时间功能
  • 时间戳:验证各种时间戳字段
  • 最大重试:验证超过最大重试次数的处理
  • 错误跟踪:验证错误信息记录
  • 版本跟踪:验证事件版本管理
  • 追踪和关联:验证 TraceID 和 CorrelationID

测试用例:

  • TestEventLifecycle_InitialState
  • TestEventLifecycle_PublishSuccess
  • TestEventLifecycle_PublishFailure
  • TestEventLifecycle_RetryMechanism
  • TestEventLifecycle_StatusTransitions
  • TestEventLifecycle_ScheduledPublish
  • TestEventLifecycle_Timestamps
  • TestEventLifecycle_MaxRetriesExceeded
  • TestEventLifecycle_ErrorTracking
  • TestEventLifecycle_VersionTracking
  • TestEventLifecycle_TraceAndCorrelation

测试辅助工具 (test_helper.go)

TestHelper

提供常用的测试断言方法:

helper := NewTestHelper(t)
helper.AssertNoError(err, "Should not error")
helper.AssertEqual(expected, actual, "Should be equal")
helper.AssertNotEmpty(value, "Should not be empty")
MockRepository

模拟 Outbox 仓储,实现完整的 OutboxRepository 接口:

repo := NewMockRepository()
repo.Save(ctx, event)
repo.FindPendingEvents(ctx, 100, "tenant1")
repo.FindByIdempotencyKey(ctx, "key")

支持的方法:

  • Save, SaveBatch
  • Update, BatchUpdate
  • FindPendingEvents, FindByID, FindByAggregateID
  • FindByIdempotencyKey, ExistsByIdempotencyKey
  • MarkAsPublished, MarkAsFailed
  • IncrementRetry, MarkAsMaxRetry
  • Delete, DeleteBatch
  • FindFailedEvents, FindMaxRetryEvents
  • FindScheduledEvents
  • CountPendingEvents, CountFailedEvents
MockEventPublisher

模拟事件发布器,实现 EventPublisher 接口:

publisher := NewMockEventPublisher()
publisher.Publish(ctx, "topic", data)
publisher.SetPublishError(err)  // 模拟发布错误
publisher.GetPublishedCount()   // 获取发布次数
MockTopicMapper

模拟 Topic 映射器,实现 TopicMapper 接口:

mapper := NewMockTopicMapper()
mapper.SetTopicMapping("Order", "order-events")
topic := mapper.GetTopic("Order")  // 返回 "order-events"

运行测试

运行所有测试
cd jxt-core/tests/outbox/function_regression_tests
go test -v .
运行特定测试
# UUID 生成测试
go test -v -run "TestUUIDGeneration"

# 幂等性测试
go test -v -run "TestIdempotency"

# 事件生命周期测试
go test -v -run "TestEventLifecycle"
运行单个测试用例
go test -v -run "TestUUIDGeneration_Concurrent"
性能测试
go test -v -run "TestUUIDGeneration_Performance"

测试原则

  1. 独立性:每个测试用例独立运行,不依赖其他测试
  2. 可重复性:测试结果可重复,不受外部环境影响
  3. 清晰性:测试名称清晰,测试逻辑简单
  4. 完整性:覆盖正常流程和异常流程
  5. 性能:包含性能和并发测试

测试数据

测试使用的示例数据:

  • 租户 IDtenant1, tenant2
  • 聚合类型Order, User, Product, Payment, Inventory
  • 聚合 IDorder-123, user-456, etc.
  • 事件类型OrderCreated, UserRegistered, etc.

扩展测试

要添加新的测试用例:

  1. 在相应的测试文件中添加测试函数
  2. 使用 TestHelper 进行断言
  3. 使用 Mock 对象模拟依赖
  4. 遵循现有的命名规范

示例:

func TestNewFeature_BasicUsage(t *testing.T) {
    helper := NewTestHelper(t)
    
    // 准备测试数据
    event := helper.CreateTestEvent("tenant1", "Order", "order-123", "OrderCreated")
    
    // 执行测试
    // ...
    
    // 验证结果
    helper.AssertNoError(err, "Should not error")
    helper.AssertEqual(expected, actual, "Should match")
}

持续集成

这些测试应该在 CI/CD 流程中自动运行:

# .github/workflows/test.yml
- name: Run Outbox Function Tests
  run: |
    cd jxt-core/tests/outbox/function_regression_tests
    go test -v -race -coverprofile=coverage.out .
    go tool cover -html=coverage.out -o coverage.html

测试覆盖率

目标覆盖率:>= 80%

查看覆盖率:

go test -coverprofile=coverage.out .
go tool cover -html=coverage.out

相关文档


版本: v1.0
更新时间: 2025-10-21
作者: Augment Agent

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultPublisherConfig

func GetDefaultPublisherConfig() *outbox.PublisherConfig

GetDefaultPublisherConfig 获取默认发布器配置

Types

type MockAsyncEventPublisher

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

MockAsyncEventPublisher 模拟异步事件发布器(支持 PublishEnvelope 和 ACK)

func NewMockAsyncEventPublisher

func NewMockAsyncEventPublisher() *MockAsyncEventPublisher

NewMockAsyncEventPublisher 创建模拟异步事件发布器

func (*MockAsyncEventPublisher) Clear

func (m *MockAsyncEventPublisher) Clear()

Clear 清空已发布事件

func (*MockAsyncEventPublisher) Close

func (m *MockAsyncEventPublisher) Close()

Close 关闭发布器

func (*MockAsyncEventPublisher) GetPublishResultChannel

func (m *MockAsyncEventPublisher) GetPublishResultChannel() <-chan *outbox.PublishResult

GetPublishResultChannel 获取发布结果通道(符合 EventPublisher 接口)

func (*MockAsyncEventPublisher) GetPublishedEnvelopeCount

func (m *MockAsyncEventPublisher) GetPublishedEnvelopeCount() int

GetPublishedEnvelopeCount 获取已发布 Envelope 数量

func (*MockAsyncEventPublisher) GetPublishedEnvelopes

func (m *MockAsyncEventPublisher) GetPublishedEnvelopes() []*outbox.Envelope

GetPublishedEnvelopes 获取已发布的 Envelope

func (*MockAsyncEventPublisher) GetPublishedTopics

func (m *MockAsyncEventPublisher) GetPublishedTopics() []string

GetPublishedTopics 获取已发布主题

func (*MockAsyncEventPublisher) PublishEnvelope

func (m *MockAsyncEventPublisher) PublishEnvelope(ctx context.Context, topic string, envelope *outbox.Envelope) error

PublishEnvelope 发布 Envelope(符合 EventPublisher 接口)

func (*MockAsyncEventPublisher) SendACKFailure

func (m *MockAsyncEventPublisher) SendACKFailure(eventID, topic, aggregateID, eventType string, err error)

SendACKFailure 发送 ACK 失败结果

func (*MockAsyncEventPublisher) SendACKSuccess

func (m *MockAsyncEventPublisher) SendACKSuccess(eventID, topic, aggregateID, eventType string)

SendACKSuccess 发送 ACK 成功结果

func (*MockAsyncEventPublisher) SetPublishDelay

func (m *MockAsyncEventPublisher) SetPublishDelay(delay time.Duration)

SetPublishDelay 设置发布延迟

func (*MockAsyncEventPublisher) SetPublishError

func (m *MockAsyncEventPublisher) SetPublishError(err error)

SetPublishError 设置发布错误

type MockEventBusForAdapter

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

MockEventBusForAdapter 用于测试 EventBus 适配器的 Mock EventBus 实现完整的 eventbus.EventBus 接口

func NewMockEventBusForAdapter

func NewMockEventBusForAdapter() *MockEventBusForAdapter

NewMockEventBusForAdapter 创建用于适配器测试的 Mock EventBus

func (*MockEventBusForAdapter) Close

func (m *MockEventBusForAdapter) Close() error

func (*MockEventBusForAdapter) ConfigureTopic

func (m *MockEventBusForAdapter) ConfigureTopic(ctx context.Context, topic string, options eventbus.TopicOptions) error

func (*MockEventBusForAdapter) GetConnectionState

func (m *MockEventBusForAdapter) GetConnectionState() eventbus.ConnectionState

func (*MockEventBusForAdapter) GetHealthCheckPublisherStatus

func (m *MockEventBusForAdapter) GetHealthCheckPublisherStatus() eventbus.HealthCheckStatus

func (*MockEventBusForAdapter) GetHealthCheckSubscriberStats

func (m *MockEventBusForAdapter) GetHealthCheckSubscriberStats() eventbus.HealthCheckSubscriberStats

func (*MockEventBusForAdapter) GetHealthStatus

func (m *MockEventBusForAdapter) GetHealthStatus() eventbus.HealthCheckStatus

func (*MockEventBusForAdapter) GetMetrics

func (m *MockEventBusForAdapter) GetMetrics() eventbus.Metrics

func (*MockEventBusForAdapter) GetPublishResultChannel

func (m *MockEventBusForAdapter) GetPublishResultChannel() <-chan *eventbus.PublishResult

GetPublishResultChannel 获取发布结果通道(实现 eventbus.EventBus 接口)

func (*MockEventBusForAdapter) GetPublishedEnvelopeCount

func (m *MockEventBusForAdapter) GetPublishedEnvelopeCount() int

GetPublishedEnvelopeCount 获取已发布 Envelope 数量

func (*MockEventBusForAdapter) GetPublishedEnvelopes

func (m *MockEventBusForAdapter) GetPublishedEnvelopes() []*eventbus.Envelope

GetPublishedEnvelopes 获取已发布的 Envelope

func (*MockEventBusForAdapter) GetRegisteredTenants added in v1.1.22

func (m *MockEventBusForAdapter) GetRegisteredTenants() []string

GetRegisteredTenants 获取已注册的租户列表(Mock 实现)

func (*MockEventBusForAdapter) GetTenantPublishResultChannel added in v1.1.22

func (m *MockEventBusForAdapter) GetTenantPublishResultChannel(tenantID string) <-chan *eventbus.PublishResult

GetTenantPublishResultChannel 获取租户专属的 ACK Channel(Mock 实现)

func (*MockEventBusForAdapter) GetTopicConfig

func (m *MockEventBusForAdapter) GetTopicConfig(topic string) (eventbus.TopicOptions, error)

func (*MockEventBusForAdapter) GetTopicConfigStrategy

func (m *MockEventBusForAdapter) GetTopicConfigStrategy() eventbus.TopicConfigStrategy

func (*MockEventBusForAdapter) ListConfiguredTopics

func (m *MockEventBusForAdapter) ListConfiguredTopics() []string

func (*MockEventBusForAdapter) Publish

func (m *MockEventBusForAdapter) Publish(ctx context.Context, topic string, message []byte) error

实现 eventbus.EventBus 接口的其他方法(空实现)

func (*MockEventBusForAdapter) PublishEnvelope

func (m *MockEventBusForAdapter) PublishEnvelope(ctx context.Context, topic string, envelope *eventbus.Envelope) error

PublishEnvelope 发布 Envelope(实现 eventbus.EventBus 接口)

func (*MockEventBusForAdapter) PublishWithOptions

func (m *MockEventBusForAdapter) PublishWithOptions(ctx context.Context, topic string, message []byte, opts eventbus.PublishOptions) error

func (*MockEventBusForAdapter) RegisterHealthCheckPublisherCallback

func (m *MockEventBusForAdapter) RegisterHealthCheckPublisherCallback(callback eventbus.HealthCheckCallback) error

func (*MockEventBusForAdapter) RegisterHealthCheckSubscriberCallback

func (m *MockEventBusForAdapter) RegisterHealthCheckSubscriberCallback(callback eventbus.HealthCheckAlertCallback) error

func (*MockEventBusForAdapter) RegisterPublishCallback

func (m *MockEventBusForAdapter) RegisterPublishCallback(callback eventbus.PublishCallback) error

func (*MockEventBusForAdapter) RegisterPublisherBacklogCallback

func (m *MockEventBusForAdapter) RegisterPublisherBacklogCallback(callback eventbus.PublisherBacklogCallback) error

func (*MockEventBusForAdapter) RegisterReconnectCallback

func (m *MockEventBusForAdapter) RegisterReconnectCallback(callback eventbus.ReconnectCallback) error

func (*MockEventBusForAdapter) RegisterSubscriberBacklogCallback

func (m *MockEventBusForAdapter) RegisterSubscriberBacklogCallback(callback eventbus.BacklogStateCallback) error

func (*MockEventBusForAdapter) RegisterSubscriptionCallback

func (m *MockEventBusForAdapter) RegisterSubscriptionCallback(callback eventbus.SubscriptionCallback) error

func (*MockEventBusForAdapter) RegisterTenant added in v1.1.22

func (m *MockEventBusForAdapter) RegisterTenant(tenantID string, bufferSize int) error

RegisterTenant 注册租户(Mock 实现)

func (*MockEventBusForAdapter) RemoveTopicConfig

func (m *MockEventBusForAdapter) RemoveTopicConfig(topic string) error

func (*MockEventBusForAdapter) SendACKFailure

func (m *MockEventBusForAdapter) SendACKFailure(eventID, topic, aggregateID, eventType string, err error)

SendACKFailure 发送 ACK 失败结果

func (*MockEventBusForAdapter) SendACKSuccess

func (m *MockEventBusForAdapter) SendACKSuccess(eventID, topic, aggregateID, eventType string)

SendACKSuccess 发送 ACK 成功结果

func (*MockEventBusForAdapter) SetErrorHandler

func (m *MockEventBusForAdapter) SetErrorHandler(handler eventbus.ErrorHandler) error

func (*MockEventBusForAdapter) SetMessageFormatter

func (m *MockEventBusForAdapter) SetMessageFormatter(formatter eventbus.MessageFormatter) error

func (*MockEventBusForAdapter) SetMessageRouter

func (m *MockEventBusForAdapter) SetMessageRouter(router eventbus.MessageRouter) error

func (*MockEventBusForAdapter) SetPublishError

func (m *MockEventBusForAdapter) SetPublishError(err error)

SetPublishError 设置发布错误

func (*MockEventBusForAdapter) SetTopicConfigStrategy

func (m *MockEventBusForAdapter) SetTopicConfigStrategy(strategy eventbus.TopicConfigStrategy)

func (*MockEventBusForAdapter) SetTopicPersistence

func (m *MockEventBusForAdapter) SetTopicPersistence(ctx context.Context, topic string, persistent bool) error

func (*MockEventBusForAdapter) Start

func (*MockEventBusForAdapter) StartAllBacklogMonitoring

func (m *MockEventBusForAdapter) StartAllBacklogMonitoring(ctx context.Context) error

func (*MockEventBusForAdapter) StartAllHealthCheck

func (m *MockEventBusForAdapter) StartAllHealthCheck(ctx context.Context) error

func (*MockEventBusForAdapter) StartHealthCheck

func (m *MockEventBusForAdapter) StartHealthCheck(ctx context.Context) error

func (*MockEventBusForAdapter) StartHealthCheckPublisher

func (m *MockEventBusForAdapter) StartHealthCheckPublisher(ctx context.Context) error

func (*MockEventBusForAdapter) StartHealthCheckSubscriber

func (m *MockEventBusForAdapter) StartHealthCheckSubscriber(ctx context.Context) error

func (*MockEventBusForAdapter) StartPublisherBacklogMonitoring

func (m *MockEventBusForAdapter) StartPublisherBacklogMonitoring(ctx context.Context) error

func (*MockEventBusForAdapter) StartSubscriberBacklogMonitoring

func (m *MockEventBusForAdapter) StartSubscriberBacklogMonitoring(ctx context.Context) error

func (*MockEventBusForAdapter) Stop

func (m *MockEventBusForAdapter) Stop() error

func (*MockEventBusForAdapter) StopAllBacklogMonitoring

func (m *MockEventBusForAdapter) StopAllBacklogMonitoring() error

func (*MockEventBusForAdapter) StopAllHealthCheck

func (m *MockEventBusForAdapter) StopAllHealthCheck() error

func (*MockEventBusForAdapter) StopHealthCheck

func (m *MockEventBusForAdapter) StopHealthCheck() error

func (*MockEventBusForAdapter) StopHealthCheckPublisher

func (m *MockEventBusForAdapter) StopHealthCheckPublisher() error

func (*MockEventBusForAdapter) StopHealthCheckSubscriber

func (m *MockEventBusForAdapter) StopHealthCheckSubscriber() error

func (*MockEventBusForAdapter) StopPublisherBacklogMonitoring

func (m *MockEventBusForAdapter) StopPublisherBacklogMonitoring() error

func (*MockEventBusForAdapter) StopSubscriberBacklogMonitoring

func (m *MockEventBusForAdapter) StopSubscriberBacklogMonitoring() error

func (*MockEventBusForAdapter) Subscribe

func (m *MockEventBusForAdapter) Subscribe(ctx context.Context, topic string, handler eventbus.MessageHandler) error

func (*MockEventBusForAdapter) SubscribeEnvelope

func (m *MockEventBusForAdapter) SubscribeEnvelope(ctx context.Context, topic string, handler eventbus.EnvelopeHandler) error

func (*MockEventBusForAdapter) SubscribeWithOptions

func (m *MockEventBusForAdapter) SubscribeWithOptions(ctx context.Context, topic string, handler eventbus.MessageHandler, opts eventbus.SubscribeOptions) error

func (*MockEventBusForAdapter) UnregisterTenant added in v1.1.22

func (m *MockEventBusForAdapter) UnregisterTenant(tenantID string) error

UnregisterTenant 注销租户(Mock 实现)

type MockEventPublisher

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

MockEventPublisher 模拟事件发布器(旧版,已废弃,使用 MockAsyncEventPublisher)

func NewMockEventPublisher

func NewMockEventPublisher() *MockEventPublisher

NewMockEventPublisher 创建模拟事件发布器

func (*MockEventPublisher) Clear

func (m *MockEventPublisher) Clear()

Clear 清空已发布事件

func (*MockEventPublisher) GetPublishResultChannel

func (m *MockEventPublisher) GetPublishResultChannel() <-chan *outbox.PublishResult

GetPublishResultChannel 获取发布结果通道(符合 EventPublisher 接口)

func (*MockEventPublisher) GetPublishedCount

func (m *MockEventPublisher) GetPublishedCount() int

GetPublishedCount 获取已发布事件数量

func (*MockEventPublisher) GetPublishedData

func (m *MockEventPublisher) GetPublishedData() [][]byte

GetPublishedData 获取已发布数据

func (*MockEventPublisher) GetPublishedTopics

func (m *MockEventPublisher) GetPublishedTopics() []string

GetPublishedTopics 获取已发布主题

func (*MockEventPublisher) Publish

func (m *MockEventPublisher) Publish(ctx context.Context, topic string, data []byte) error

Publish 发布事件(符合 EventPublisher 接口)

func (*MockEventPublisher) PublishEnvelope

func (m *MockEventPublisher) PublishEnvelope(ctx context.Context, topic string, envelope *outbox.Envelope) error

PublishEnvelope 发布 Envelope(符合 EventPublisher 接口)

func (*MockEventPublisher) SetPublishDelay

func (m *MockEventPublisher) SetPublishDelay(delay time.Duration)

SetPublishDelay 设置发布延迟

func (*MockEventPublisher) SetPublishError

func (m *MockEventPublisher) SetPublishError(err error)

SetPublishError 设置发布错误

type MockRepository

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

MockRepository 模拟仓储

func NewMockRepository

func NewMockRepository() *MockRepository

NewMockRepository 创建模拟仓储

func (*MockRepository) BatchUpdate

func (m *MockRepository) BatchUpdate(ctx context.Context, events []*outbox.OutboxEvent) error

BatchUpdate 批量更新事件

func (*MockRepository) Clear

func (m *MockRepository) Clear()

Clear 清空所有事件

func (*MockRepository) Count

func (m *MockRepository) Count(ctx context.Context, status outbox.EventStatus, tenantID string) (int64, error)

Count 统计事件数量

func (*MockRepository) CountByStatus

func (m *MockRepository) CountByStatus(ctx context.Context, tenantID string) (map[outbox.EventStatus]int64, error)

CountByStatus 按状态统计事件数量

func (*MockRepository) CountFailedEvents

func (m *MockRepository) CountFailedEvents(ctx context.Context, tenantID string) (int64, error)

CountFailedEvents 统计失败事件数量

func (*MockRepository) CountPendingEvents

func (m *MockRepository) CountPendingEvents(ctx context.Context, tenantID string) (int64, error)

CountPendingEvents 统计待发布事件数量

func (*MockRepository) Delete

func (m *MockRepository) Delete(ctx context.Context, id string) error

Delete 删除事件

func (*MockRepository) DeleteBatch

func (m *MockRepository) DeleteBatch(ctx context.Context, ids []string) error

DeleteBatch 批量删除事件

func (*MockRepository) DeleteFailedBefore

func (m *MockRepository) DeleteFailedBefore(ctx context.Context, before time.Time, tenantID string) (int64, error)

DeleteFailedBefore 删除指定时间之前失败的事件

func (*MockRepository) DeletePublishedBefore

func (m *MockRepository) DeletePublishedBefore(ctx context.Context, before time.Time, tenantID string) (int64, error)

DeletePublishedBefore 删除指定时间之前已发布的事件

func (*MockRepository) ExistsByIdempotencyKey

func (m *MockRepository) ExistsByIdempotencyKey(ctx context.Context, idempotencyKey string) (bool, error)

ExistsByIdempotencyKey 检查幂等性键是否已存在

func (*MockRepository) FindByAggregateID

func (m *MockRepository) FindByAggregateID(ctx context.Context, aggregateID string, tenantID string) ([]*outbox.OutboxEvent, error)

FindByAggregateID 根据聚合根 ID 查找事件

func (*MockRepository) FindByAggregateType

func (m *MockRepository) FindByAggregateType(ctx context.Context, aggregateType string, limit int) ([]*outbox.OutboxEvent, error)

FindByAggregateType 根据聚合类型查找待发布事件

func (*MockRepository) FindByID

func (m *MockRepository) FindByID(ctx context.Context, id string) (*outbox.OutboxEvent, error)

FindByID 根据 ID 查找事件

func (*MockRepository) FindByIdempotencyKey

func (m *MockRepository) FindByIdempotencyKey(ctx context.Context, key string) (*outbox.OutboxEvent, error)

FindByIdempotencyKey 根据幂等性键查找事件

func (*MockRepository) FindEventsForRetry

func (m *MockRepository) FindEventsForRetry(ctx context.Context, maxRetries int, limit int) ([]*outbox.OutboxEvent, error)

FindEventsForRetry 查找需要重试的事件

func (*MockRepository) FindFailedEvents

func (m *MockRepository) FindFailedEvents(ctx context.Context, limit int, tenantID string) ([]*outbox.OutboxEvent, error)

FindFailedEvents 查找失败的事件

func (*MockRepository) FindMaxRetryEvents

func (m *MockRepository) FindMaxRetryEvents(ctx context.Context, limit int, tenantID string) ([]*outbox.OutboxEvent, error)

FindMaxRetryEvents 查找超过最大重试次数的事件

func (*MockRepository) FindPendingEvents

func (m *MockRepository) FindPendingEvents(ctx context.Context, limit int, tenantID string) ([]*outbox.OutboxEvent, error)

FindPendingEvents 查找待发布事件

func (*MockRepository) FindPendingEventsWithDelay

func (m *MockRepository) FindPendingEventsWithDelay(ctx context.Context, tenantID string, delaySeconds int, limit int) ([]*outbox.OutboxEvent, error)

FindPendingEventsWithDelay 查找创建时间超过指定延迟的待发布事件

func (*MockRepository) FindScheduledEvents

func (m *MockRepository) FindScheduledEvents(ctx context.Context, limit int, tenantID string) ([]*outbox.OutboxEvent, error)

FindScheduledEvents 查找计划发布的事件

func (*MockRepository) GetEventByID

func (m *MockRepository) GetEventByID(id string) *outbox.OutboxEvent

GetEventByID 获取事件

func (*MockRepository) GetEventCount

func (m *MockRepository) GetEventCount() int

GetEventCount 获取事件数量

func (*MockRepository) IncrementRetry

func (m *MockRepository) IncrementRetry(ctx context.Context, id string, errorMsg string) error

IncrementRetry 增加重试次数

func (*MockRepository) IncrementRetryCount

func (m *MockRepository) IncrementRetryCount(ctx context.Context, id string) error

IncrementRetryCount 增加重试次数(已废弃)

func (*MockRepository) MarkAsFailed

func (m *MockRepository) MarkAsFailed(ctx context.Context, id string, err error) error

MarkAsFailed 标记事件为失败

func (*MockRepository) MarkAsMaxRetry

func (m *MockRepository) MarkAsMaxRetry(ctx context.Context, id string, errorMsg string) error

MarkAsMaxRetry 标记事件为超过最大重试次数

func (*MockRepository) MarkAsPublished

func (m *MockRepository) MarkAsPublished(ctx context.Context, id string) error

MarkAsPublished 标记事件为已发布

func (*MockRepository) Save

func (m *MockRepository) Save(ctx context.Context, event *outbox.OutboxEvent) error

Save 保存事件

func (*MockRepository) SaveBatch

func (m *MockRepository) SaveBatch(ctx context.Context, events []*outbox.OutboxEvent) error

SaveBatch 批量保存事件

func (*MockRepository) SetFindPendingError

func (m *MockRepository) SetFindPendingError(err error)

SetFindPendingError 设置查找待发布事件错误

func (*MockRepository) SetSaveError

func (m *MockRepository) SetSaveError(err error)

SetSaveError 设置保存错误

func (*MockRepository) SetUpdateError

func (m *MockRepository) SetUpdateError(err error)

SetUpdateError 设置更新错误

func (*MockRepository) Update

func (m *MockRepository) Update(ctx context.Context, event *outbox.OutboxEvent) error

Update 更新事件

type MockTopicMapper

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

MockTopicMapper 模拟 Topic 映射器

func NewMockTopicMapper

func NewMockTopicMapper() *MockTopicMapper

NewMockTopicMapper 创建模拟 Topic 映射器

func (*MockTopicMapper) GetTopic

func (m *MockTopicMapper) GetTopic(aggregateType string) string

GetTopic 获取 Topic(符合 TopicMapper 接口)

func (*MockTopicMapper) SetTopicMapping

func (m *MockTopicMapper) SetTopicMapping(aggregateType, topic string)

SetTopicMapping 设置 Topic 映射

type TestHelper

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

TestHelper 测试辅助工具

func NewTestHelper

func NewTestHelper(t *testing.T) *TestHelper

NewTestHelper 创建测试辅助工具

func (*TestHelper) AssertContains

func (h *TestHelper) AssertContains(s, contains interface{}, msgAndArgs ...interface{})

AssertContains 断言包含

func (*TestHelper) AssertEqual

func (h *TestHelper) AssertEqual(expected, actual interface{}, msgAndArgs ...interface{})

AssertEqual 断言相等

func (*TestHelper) AssertError added in v1.1.23

func (h *TestHelper) AssertError(err error, msgAndArgs ...interface{})

AssertError 断言有错误

func (*TestHelper) AssertFalse

func (h *TestHelper) AssertFalse(value bool, msgAndArgs ...interface{})

AssertFalse 断言为 false

func (*TestHelper) AssertGreater

func (h *TestHelper) AssertGreater(e1, e2 interface{}, msgAndArgs ...interface{})

AssertGreater 断言大于

func (*TestHelper) AssertNil

func (h *TestHelper) AssertNil(obj interface{}, msgAndArgs ...interface{})

AssertNil 断言为 nil

func (*TestHelper) AssertNoError

func (h *TestHelper) AssertNoError(err error, msgAndArgs ...interface{})

AssertNoError 断言无错误

func (*TestHelper) AssertNotEmpty

func (h *TestHelper) AssertNotEmpty(obj interface{}, msgAndArgs ...interface{})

AssertNotEmpty 断言非空

func (*TestHelper) AssertNotEqual

func (h *TestHelper) AssertNotEqual(expected, actual interface{}, msgAndArgs ...interface{})

AssertNotEqual 断言两个值不相等

func (*TestHelper) AssertNotNil

func (h *TestHelper) AssertNotNil(obj interface{}, msgAndArgs ...interface{})

AssertNotNil 断言不为 nil

func (*TestHelper) AssertRegex

func (h *TestHelper) AssertRegex(pattern, s string, msgAndArgs ...interface{})

AssertRegex 断言字符串匹配正则表达式

func (*TestHelper) AssertTrue

func (h *TestHelper) AssertTrue(value bool, msgAndArgs ...interface{})

AssertTrue 断言为 true

func (*TestHelper) CreateTestEvent

func (h *TestHelper) CreateTestEvent(tenantID, aggregateType, aggregateID, eventType string) *outbox.OutboxEvent

CreateTestEvent 创建测试事件

func (*TestHelper) CreateTestEventWithPayload

func (h *TestHelper) CreateTestEventWithPayload(tenantID, aggregateType, aggregateID, eventType string, payload interface{}) *outbox.OutboxEvent

CreateTestEventWithPayload 创建带自定义负载的测试事件

func (*TestHelper) RequireNoError

func (h *TestHelper) RequireNoError(err error, msgAndArgs ...interface{})

RequireNoError 要求无错误

Jump to

Keyboard shortcuts

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