Files
tasks/service/history/ndc/replication_task_test.go
Will DuanandGitHub 80d7757b91 Add ReplicateHistoryEvents API to accepting deserialized history events (#4859)
<!-- Describe what has changed in this PR -->
**What changed?**
Add ReplicateHistoryEvents History Engine API to accept deserialized
history events.

<!-- Tell your future self why have you made these changes -->
**Why?**
In order to implement the batching replication task functionality, we
will need to validate the events to decide if two tasks can be batched
or not. In order to validate the events, we will have to deserialize the
events. Adding this API will prevent us from doing deserializing ->
serializing -> deserializing when processing the replication events.

The newly added API will replace the ReplicateEventsV2 once the new API
is verified functioning properly.

<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
**How did you test it?**
The code is copying the logic from ReplicateEventsV2. No new logic
added.

<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
**Potential risks**
N/a. No component is using this API.

<!-- Is this PR a hotfix candidate or require that a notification be
sent to the broader community? (Yes/No) -->
**Is hotfix candidate?**
No.
2023-09-15 09:30:10 -07:00

139 lines
2.9 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package ndc
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
historypb "go.temporal.io/api/history/v1"
)
type (
replicationTaskSuite struct {
suite.Suite
*require.Assertions
}
)
func TestReplicationTaskSuite(t *testing.T) {
s := new(replicationTaskSuite)
suite.Run(t, s)
}
func (s *replicationTaskSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *replicationTaskSuite) TearDownSuite() {
}
func (s *replicationTaskSuite) TestValidateEventsSlice() {
eS1 := []*historypb.HistoryEvent{
{
EventId: 1,
Version: 2,
},
{
EventId: 2,
Version: 2,
},
}
eS2 := []*historypb.HistoryEvent{
{
EventId: 3,
Version: 2,
},
}
eS3 := []*historypb.HistoryEvent{
{
EventId: 4,
Version: 2,
},
}
v, err := validateEventsSlice(eS1, eS2)
s.Equal(int64(2), v)
s.Nil(err)
v, err = validateEventsSlice(eS1, eS3)
s.Equal(int64(0), v)
s.IsType(ErrEventSlicesNotConsecutive, err)
v, err = validateEventsSlice(eS1, nil)
s.Equal(int64(0), v)
s.IsType(ErrEmptyEventSlice, err)
}
func (s *replicationTaskSuite) TestValidateEvents() {
eS1 := []*historypb.HistoryEvent{
{
EventId: 1,
Version: 2,
},
{
EventId: 2,
Version: 2,
},
}
eS2 := []*historypb.HistoryEvent{
{
EventId: 1,
Version: 2,
},
{
EventId: 3,
Version: 2,
},
}
eS3 := []*historypb.HistoryEvent{
{
EventId: 1,
Version: 1,
},
{
EventId: 2,
Version: 2,
},
}
v, err := validateEvents(eS1)
s.Nil(err)
s.Equal(int64(2), v)
v, err = validateEvents(eS2)
s.Equal(int64(0), v)
s.IsType(ErrEventIDMismatch, err)
v, err = validateEvents(eS3)
s.Equal(int64(0), v)
s.IsType(ErrEventVersionMismatch, err)
}