Files
tasks/service/history/shard/context_util_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

75 lines
2.0 KiB
Go

package shard
import (
"math"
"math/rand"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
historyi "github.com/hanzoai/tasks/service/history/interfaces"
"github.com/hanzoai/tasks/service/history/tests"
"go.uber.org/mock/gomock"
)
type (
contextUtilSuite struct {
suite.Suite
*require.Assertions
}
)
func TestContextUtilSuite(t *testing.T) {
s := &contextUtilSuite{}
suite.Run(t, s)
}
func (s *contextUtilSuite) SetupTest() {
s.Assertions = require.New(s.T())
}
func (s *contextUtilSuite) TeardownTest() {
s.Assertions = require.New(s.T())
}
func (s *contextUtilSuite) TestReplicationReaderIDConversion() {
expectedClusterID := int64(rand.Int31())
expectedShardID := rand.Int31()
actualClusterID, actualShardID := ReplicationReaderIDToClusterShardID(
ReplicationReaderIDFromClusterShardID(expectedClusterID, expectedShardID),
)
s.Equal(expectedClusterID, actualClusterID)
s.Equal(expectedShardID, actualShardID)
}
func (s *contextUtilSuite) TestReplicationReaderIDConversion_1() {
expectedClusterID := int64(1)
expectedShardID := int32(1)
actualClusterID, actualShardID := ReplicationReaderIDToClusterShardID(
ReplicationReaderIDFromClusterShardID(expectedClusterID, expectedShardID),
)
s.Equal(expectedClusterID, actualClusterID)
s.Equal(expectedShardID, actualShardID)
}
func (s *contextUtilSuite) TestReplicationReaderIDConversion_Int32Max() {
expectedClusterID := int64(math.MaxInt32)
expectedShardID := int32(math.MaxInt32)
actualClusterID, actualShardID := ReplicationReaderIDToClusterShardID(
ReplicationReaderIDFromClusterShardID(expectedClusterID, expectedShardID),
)
s.Equal(expectedClusterID, actualClusterID)
s.Equal(expectedShardID, actualShardID)
}
func (s *contextUtilSuite) newMockContext() *historyi.MockShardContext {
controller := gomock.NewController(s.T())
mockContext := historyi.NewMockShardContext(controller)
mockContext.EXPECT().GetShardID().Return(int32(1)).AnyTimes()
mockContext.EXPECT().GetConfig().Return(tests.NewDynamicConfig()).AnyTimes()
return mockContext
}