@@ -1554,3 +1554,68 @@ func (s *workflowReplicatorSuite) Test_bringLocalEventsUpToSourceCurrentBranch_C
15541554 s .Equal (forkedBranchToken , localVersionHistoryies .Histories [2 ].BranchToken )
15551555 s .Equal (int32 (2 ), localVersionHistoryies .CurrentVersionHistoryIndex )
15561556}
1557+
1558+ func (s * workflowReplicatorSuite ) Test_backfillHistory_EventIDMismatch () {
1559+ namespaceID := uuid .New ()
1560+ branchInfo := & persistencespb.HistoryBranch {
1561+ TreeId : s .runID ,
1562+ BranchId : uuid .New (),
1563+ Ancestors : nil ,
1564+ }
1565+ historyBranch , err := serialization .HistoryBranchToBlob (branchInfo )
1566+ s .NoError (err )
1567+
1568+ nsEntry := namespace .NewNamespaceForTest (& persistencespb.NamespaceInfo {Name : "ns" }, nil , false , nil , 0 )
1569+ s .mockNamespaceCache .EXPECT ().GetNamespaceByID (namespace .ID (namespaceID )).Return (nsEntry , nil ).AnyTimes ()
1570+
1571+ mutableState := workflow .NewMutableState (
1572+ s .mockShard ,
1573+ s .mockShard .GetEventsCache (),
1574+ s .logger ,
1575+ nsEntry ,
1576+ s .workflowID ,
1577+ s .runID ,
1578+ s .now ,
1579+ )
1580+ mutableState .GetExecutionInfo ().NamespaceId = namespaceID
1581+ mutableState .GetExecutionInfo ().WorkflowId = s .workflowID
1582+ mutableState .GetExecutionInfo ().VersionHistories = & historyspb.VersionHistories {
1583+ CurrentVersionHistoryIndex : 0 ,
1584+ Histories : []* historyspb.VersionHistory {
1585+ {
1586+ BranchToken : historyBranch .GetData (),
1587+ Items : []* historyspb.VersionHistoryItem {{EventId : 4 , Version : 1 }},
1588+ },
1589+ },
1590+ }
1591+ serializer := serialization .NewSerializer ()
1592+ blob1 , err := serializer .SerializeEvents ([]* historypb.HistoryEvent {{EventId : 1 , Version : 1 }}, enumspb .ENCODING_TYPE_PROTO3 )
1593+ s .NoError (err )
1594+ blob2 , err := serializer .SerializeEvents ([]* historypb.HistoryEvent {{EventId : 3 , Version : 1 }}, enumspb .ENCODING_TYPE_PROTO3 )
1595+ s .NoError (err )
1596+
1597+ s .mockExecutionManager .EXPECT ().ReadHistoryBranchByBatch (gomock .Any (), gomock .Any ()).Return (nil , serviceerror .NewNotFound ("not found" )).AnyTimes ()
1598+ mockShard := historyi .NewMockShardContext (s .controller )
1599+ mockShard .EXPECT ().GenerateTaskID ().Return (int64 (1 ), nil ).AnyTimes ()
1600+ mockShard .EXPECT ().GetRemoteAdminClient ("test-cluster" ).Return (s .mockRemoteAdminClient , nil ).AnyTimes ()
1601+ mockShard .EXPECT ().GetShardID ().Return (int32 (0 )).AnyTimes ()
1602+ mockShard .EXPECT ().GetExecutionManager ().Return (s .mockExecutionManager ).AnyTimes ()
1603+ s .workflowStateReplicator .shardContext = mockShard
1604+ s .mockRemoteAdminClient .EXPECT ().GetWorkflowExecutionRawHistoryV2 (gomock .Any (), gomock .Any ()).Return (& adminservice.GetWorkflowExecutionRawHistoryV2Response {
1605+ HistoryBatches : []* commonpb.DataBlob {blob1 , blob2 },
1606+ HistoryNodeIds : []int64 {1 , 3 },
1607+ }, nil )
1608+ s .mockExecutionManager .EXPECT ().AppendRawHistoryNodes (gomock .Any (), gomock .Any ()).Return (nil , nil ).AnyTimes ()
1609+
1610+ err = s .workflowStateReplicator .backfillHistory (
1611+ context .Background (),
1612+ "test-cluster" ,
1613+ namespace .ID (namespaceID ),
1614+ s .workflowID ,
1615+ s .runID ,
1616+ mutableState ,
1617+ true ,
1618+ )
1619+ var internalErr * serviceerror.Internal
1620+ s .ErrorAs (err , & internalErr )
1621+ }
0 commit comments