Files
tasks/service/history/ndc/mutable_state_mapper_test.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

199 lines
4.3 KiB
Go

package ndc
import (
"context"
"testing"
"github.com/pborman/uuid"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/server/common/cluster"
"go.temporal.io/server/common/definition"
"go.temporal.io/server/common/log"
historyi "go.temporal.io/server/service/history/interfaces"
"go.uber.org/mock/gomock"
)
type (
mutableStateMapperSuite struct {
suite.Suite
*require.Assertions
controller *gomock.Controller
logger log.Logger
shardContext historyi.MockShardContext
branchMgrProvider branchMgrProvider
mockBranchMgr *MockBranchMgr
mutableStateMapper *MutableStateMapperImpl
clusterMetadata *cluster.MockMetadata
}
)
func TestMutableStateMapperSuite(t *testing.T) {
s := new(mutableStateMapperSuite)
suite.Run(t, s)
}
func (s *mutableStateMapperSuite) SetupSuite() {
s.Assertions = require.New(s.T())
s.controller = gomock.NewController(s.T())
s.mockBranchMgr = NewMockBranchMgr(s.controller)
s.branchMgrProvider = func(
wfContext historyi.WorkflowContext,
mutableState historyi.MutableState,
logger log.Logger) BranchMgr {
return s.mockBranchMgr
}
s.clusterMetadata = cluster.NewMockMetadata(s.controller)
s.clusterMetadata.EXPECT().ClusterNameForFailoverVersion(gomock.Any(), gomock.Any()).Return("some random cluster name").AnyTimes()
s.mutableStateMapper = NewMutableStateMapping(
nil,
nil,
s.branchMgrProvider,
nil,
nil)
}
func (s *mutableStateMapperSuite) TearDownSuite() {
}
func (s *mutableStateMapperSuite) TestGetOrCreateHistoryBranch_ValidEventBatch_NoDedupe() {
workflowKey := definition.WorkflowKey{
WorkflowID: uuid.New(),
RunID: uuid.New(),
}
eventSlices := [][]*historypb.HistoryEvent{
{
{
EventId: 11,
},
{
EventId: 12,
},
},
{
{
EventId: 13,
},
{
EventId: 14,
},
},
}
task, _ := newReplicationTask(
s.clusterMetadata,
nil,
workflowKey,
nil,
nil,
eventSlices,
nil,
"",
nil,
false,
)
s.mockBranchMgr.EXPECT().
GetOrCreate(gomock.Any(), gomock.Any(), int64(11), gomock.Any()).Return(true, int32(0), nil).Times(1)
_, out, err := s.mutableStateMapper.GetOrCreateHistoryBranch(context.Background(), nil, nil, task)
s.NoError(err)
s.Equal(int32(0), out.BranchIndex)
s.Equal(0, out.EventsApplyIndex)
s.True(out.DoContinue)
}
func (s *mutableStateMapperSuite) TestGetOrCreateHistoryBranch_ValidEventBatch_FirstBatchDedupe() {
workflowKey := definition.WorkflowKey{
WorkflowID: uuid.New(),
RunID: uuid.New(),
}
eventSlices := [][]*historypb.HistoryEvent{
{
{
EventId: 11,
},
{
EventId: 12,
},
},
{
{
EventId: 13,
},
{
EventId: 14,
},
},
}
task, _ := newReplicationTask(
s.clusterMetadata,
nil,
workflowKey,
nil,
nil,
eventSlices,
nil,
"",
nil,
false,
)
s.mockBranchMgr.EXPECT().
GetOrCreate(gomock.Any(), gomock.Any(), int64(11), gomock.Any()).Return(false, int32(0), nil).Times(1)
s.mockBranchMgr.EXPECT().
GetOrCreate(gomock.Any(), gomock.Any(), int64(13), gomock.Any()).Return(true, int32(0), nil).Times(1)
_, out, err := s.mutableStateMapper.GetOrCreateHistoryBranch(context.Background(), nil, nil, task)
s.NoError(err)
s.Equal(int32(0), out.BranchIndex)
s.Equal(1, out.EventsApplyIndex)
s.True(out.DoContinue)
}
func (s *mutableStateMapperSuite) TestGetOrCreateHistoryBranch_ValidEventBatch_AllBatchDedupe() {
workflowKey := definition.WorkflowKey{
WorkflowID: uuid.New(),
RunID: uuid.New(),
}
eventSlices := [][]*historypb.HistoryEvent{
{
{
EventId: 11,
},
{
EventId: 12,
},
},
{
{
EventId: 13,
},
{
EventId: 14,
},
},
}
task, _ := newReplicationTask(
s.clusterMetadata,
nil,
workflowKey,
nil,
nil,
eventSlices,
nil,
"",
nil,
false,
)
s.mockBranchMgr.EXPECT().
GetOrCreate(gomock.Any(), gomock.Any(), int64(11), gomock.Any()).Return(false, int32(0), nil).Times(1)
s.mockBranchMgr.EXPECT().
GetOrCreate(gomock.Any(), gomock.Any(), int64(13), gomock.Any()).Return(false, int32(0), nil).Times(1)
_, out, err := s.mutableStateMapper.GetOrCreateHistoryBranch(context.Background(), nil, nil, task)
s.NoError(err)
s.Equal(int32(0), out.BranchIndex)
s.Equal(0, out.EventsApplyIndex)
s.False(out.DoContinue)
}