From 12a093ffc59dffdb90ad2be8429273672321f14a Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 20 Dec 2023 00:36:13 +0100 Subject: [PATCH 1/6] Add unit tests for persistence serialization logic --- common/persistence/dataStoreInterfaces.go | 1 + .../serialization/domain_info_test.go | 95 +++ .../serialization/getters_fixtures_test.go | 703 ++++++++++++++++++ .../persistence/serialization/getters_test.go | 344 +++++++++ .../persistence/serialization/helpers_test.go | 9 + .../serialization/history_tree_info_test.go | 32 + common/persistence/serialization/parser.go | 4 - .../persistence/serialization/parser_test.go | 143 +++- .../serialization/persistence_mapper.go | 2 + .../serialization/persistence_mapper_test.go | 2 + .../serialization/proto_decoder.go | 91 --- .../serialization/proto_encoder.go | 97 --- .../persistence/serialization/shard_test.go | 68 ++ .../serialization/thrift_mapper.go | 1 + 14 files changed, 1391 insertions(+), 201 deletions(-) create mode 100644 common/persistence/serialization/domain_info_test.go create mode 100644 common/persistence/serialization/getters_fixtures_test.go create mode 100644 common/persistence/serialization/getters_test.go create mode 100644 common/persistence/serialization/helpers_test.go create mode 100644 common/persistence/serialization/history_tree_info_test.go delete mode 100644 common/persistence/serialization/proto_decoder.go delete mode 100644 common/persistence/serialization/proto_encoder.go create mode 100644 common/persistence/serialization/shard_test.go diff --git a/common/persistence/dataStoreInterfaces.go b/common/persistence/dataStoreInterfaces.go index 0cdf6f4d667..b08312d492d 100644 --- a/common/persistence/dataStoreInterfaces.go +++ b/common/persistence/dataStoreInterfaces.go @@ -332,6 +332,7 @@ type ( // attributes which are not related to mutable state at all HistorySize int64 + IsCron bool } // InternalWorkflowMutableState indicates workflow related state for Persistence Interface diff --git a/common/persistence/serialization/domain_info_test.go b/common/persistence/serialization/domain_info_test.go new file mode 100644 index 00000000000..304e1781498 --- /dev/null +++ b/common/persistence/serialization/domain_info_test.go @@ -0,0 +1,95 @@ +package serialization + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/uber/cadence/common" +) + +func TestDomain_empty_struct(t *testing.T) { + var d *DomainInfo + + assert.Equal(t, "", d.GetName()) + assert.Equal(t, "", d.GetDescription()) + assert.Equal(t, "", d.GetOwner()) + assert.Equal(t, int32(0), d.GetStatus()) + assert.Equal(t, time.Duration(0), d.GetRetention()) + assert.Equal(t, false, d.GetEmitMetric()) + assert.Equal(t, "", d.GetArchivalBucket()) + assert.Equal(t, int16(0), d.GetArchivalStatus()) + assert.Equal(t, int64(0), d.GetConfigVersion()) + assert.Equal(t, int64(0), d.GetFailoverVersion()) + assert.Equal(t, int64(0), d.GetNotificationVersion()) + assert.Equal(t, int64(0), d.GetFailoverNotificationVersion()) + assert.Equal(t, int64(0), d.GetPreviousFailoverVersion()) + assert.Equal(t, "", d.GetActiveClusterName()) + assert.Equal(t, emptySlice[string](), d.GetClusters()) + assert.Equal(t, emptyMap[string, string](), d.GetData()) + assert.Equal(t, emptySlice[uint8](), d.GetBadBinaries()) + assert.Equal(t, "", d.GetBadBinariesEncoding()) + assert.Equal(t, int16(0), d.GetHistoryArchivalStatus()) + assert.Equal(t, "", d.GetHistoryArchivalURI()) + assert.Equal(t, int16(0), d.GetVisibilityArchivalStatus()) + assert.Equal(t, "", d.GetVisibilityArchivalURI()) + assert.Equal(t, time.Unix(0, 0), d.GetFailoverEndTimestamp()) + assert.Equal(t, time.Unix(0, 0), d.GetLastUpdatedTimestamp()) +} + +func TestDomain_non_empty(t *testing.T) { + now := time.Now() + + d := DomainInfo{ + Name: "test_name", + Description: "test_description", + Owner: "test_owner", + Status: 1, + Retention: 2, + EmitMetric: true, + ArchivalBucket: "test_bucket", + ArchivalStatus: 3, + ConfigVersion: 4, + NotificationVersion: 5, + FailoverNotificationVersion: 6, + FailoverVersion: 7, + ActiveClusterName: "test_cluster_name", + Clusters: []string{"cluster1", "cluster2"}, + Data: map[string]string{"key1": "val1", "key2": "val2"}, + BadBinaries: []byte{1, 2, 3}, + BadBinariesEncoding: "test_encoding", + HistoryArchivalStatus: 8, + HistoryArchivalURI: "test_archival_uri", + VisibilityArchivalStatus: 9, + VisibilityArchivalURI: "test_visibility_uri", + FailoverEndTimestamp: common.TimePtr(now), + PreviousFailoverVersion: 10, + LastUpdatedTimestamp: now.Add(-1 * time.Second), + IsolationGroups: []byte{1, 2, 3}, + IsolationGroupsEncoding: "test_isolation_encoding", + } + assert.Equal(t, d.Name, d.GetName()) + assert.Equal(t, d.Description, d.GetDescription()) + assert.Equal(t, d.Owner, d.GetOwner()) + assert.Equal(t, d.Status, d.GetStatus()) + assert.Equal(t, d.Retention, d.GetRetention()) + assert.Equal(t, d.EmitMetric, d.GetEmitMetric()) + assert.Equal(t, d.ArchivalBucket, d.GetArchivalBucket()) + assert.Equal(t, d.ArchivalStatus, d.GetArchivalStatus()) + assert.Equal(t, d.ConfigVersion, d.GetConfigVersion()) + assert.Equal(t, d.FailoverVersion, d.GetFailoverVersion()) + assert.Equal(t, d.NotificationVersion, d.GetNotificationVersion()) + assert.Equal(t, d.FailoverNotificationVersion, d.GetFailoverNotificationVersion()) + assert.Equal(t, d.PreviousFailoverVersion, d.GetPreviousFailoverVersion()) + assert.Equal(t, d.ActiveClusterName, d.GetActiveClusterName()) + assert.Equal(t, d.Clusters, d.GetClusters()) + assert.Equal(t, d.Data, d.GetData()) + assert.Equal(t, d.BadBinaries, d.GetBadBinaries()) + assert.Equal(t, d.BadBinariesEncoding, d.GetBadBinariesEncoding()) + assert.Equal(t, d.HistoryArchivalStatus, d.GetHistoryArchivalStatus()) + assert.Equal(t, d.HistoryArchivalURI, d.GetHistoryArchivalURI()) + assert.Equal(t, d.VisibilityArchivalStatus, d.GetVisibilityArchivalStatus()) + assert.Equal(t, d.VisibilityArchivalURI, d.GetVisibilityArchivalURI()) + assert.Equal(t, *d.FailoverEndTimestamp, d.GetFailoverEndTimestamp()) + assert.Equal(t, d.LastUpdatedTimestamp, d.GetLastUpdatedTimestamp()) +} diff --git a/common/persistence/serialization/getters_fixtures_test.go b/common/persistence/serialization/getters_fixtures_test.go new file mode 100644 index 00000000000..c5b343f5501 --- /dev/null +++ b/common/persistence/serialization/getters_fixtures_test.go @@ -0,0 +1,703 @@ +package serialization + +import ( + "time" + + "github.com/uber/cadence/common/types" +) + +var ( + zeroUnix = time.Unix(0, 0) +) + +var expectedNil = map[string]map[string]any{ + "*serialization.WorkflowExecutionInfo": { + "GetAutoResetPoints": []uint8(nil), + "GetAutoResetPointsEncoding": "", + "GetCancelRequestID": "", + "GetCancelRequested": false, + "GetClientFeatureVersion": "", + "GetClientImpl": "", + "GetClientLibraryVersion": "", + "GetCloseStatus": int32(0), + "GetCompletionEvent": []uint8(nil), + "GetCompletionEventEncoding": "", + "GetCreateRequestID": "", + "GetCompletionEventBatchID": int64(0), + "GetCronSchedule": "", + "GetDecisionAttempt": int64(0), + "GetDecisionOriginalScheduledTimestamp": zeroUnix, + "GetDecisionRequestID": "", + "GetDecisionScheduleID": int64(0), + "GetDecisionScheduledTimestamp": zeroUnix, + "GetDecisionStartedID": int64(0), + "GetDecisionStartedTimestamp": zeroUnix, + "GetDecisionTaskTimeout": time.Duration(0), + "GetDecisionTimeout": time.Duration(0), + "GetLastFirstEventID": int64(0), + "GetLastProcessedEvent": int64(0), + "GetParentWorkflowID": "", + "GetStartVersion": int64(0), + "GetTaskList": "", + "GetDecisionVersion": int64(0), + "GetEventBranchToken": []uint8(nil), + "GetEventStoreVersion": int32(0), + "GetExecutionContext": []uint8(nil), + "GetFirstExecutionRunID": []uint8(nil), + "GetHasRetryPolicy": false, + "GetInitiatedID": int64(0), + "GetIsCron": false, + "GetLastEventTaskID": int64(0), + "GetLastUpdatedTimestamp": zeroUnix, + "GetLastWriteEventID": int64(0), + "GetMemo": map[string][]uint8(nil), + "GetParentDomainID": []uint8(nil), + "GetParentRunID": []uint8(nil), + "GetPartitionConfig": map[string]string(nil), + "GetHistorySize": int64(0), + "GetRetryAttempt": int64(0), + "GetRetryBackoffCoefficient": float64(0), + "GetRetryExpiration": time.Duration(0), + "GetRetryExpirationTimestamp": zeroUnix, + "GetRetryInitialInterval": time.Duration(0), + "GetRetryMaximumAttempts": int32(0), + "GetRetryMaximumInterval": time.Duration(0), + "GetRetryNonRetryableErrors": []string(nil), + "GetSearchAttributes": map[string][]uint8(nil), + "GetSignalCount": int64(0), + "GetStartTimestamp": zeroUnix, + "GetState": int32(0), + "GetStickyScheduleToStartTimeout": time.Duration(0), + "GetStickyTaskList": "", + "GetVersionHistories": []uint8(nil), + "GetVersionHistoriesEncoding": "", + "GetWorkflowTimeout": time.Duration(0), + "GetWorkflowTypeName": "", + }, + "*serialization.TimerTaskInfo": { + "GetDomainID": []uint8(nil), + "GetEventID": int64(0), + "GetRunID": []uint8(nil), + "GetScheduleAttempt": int64(0), + "GetTaskType": int16(0), + "GetTimeoutType": int16(0), + "GetVersion": int64(0), + "GetWorkflowID": "", + }, + "*serialization.ReplicationTaskInfo": { + "GetBranchToken": []uint8(nil), + "GetCreationTimestamp": zeroUnix, + "GetDomainID": []uint8(nil), + "GetEventStoreVersion": int32(0), + "GetFirstEventID": int64(0), + "GetNewRunBranchToken": []uint8(nil), + "GetNewRunEventStoreVersion": int32(0), + "GetNextEventID": int64(0), + "GetRunID": []uint8(nil), + "GetScheduledID": int64(0), + "GetTaskType": int16(0), + "GetVersion": int64(0), + "GetWorkflowID": "", + }, + "*serialization.TaskListInfo": { + "GetAckLevel": int64(0), + "GetExpiryTimestamp": zeroUnix, + "GetKind": int16(0), + "GetLastUpdated": zeroUnix, + }, + "*serialization.TaskInfo": { + "GetCreatedTimestamp": zeroUnix, + "GetExpiryTimestamp": zeroUnix, + "GetPartitionConfig": map[string]string(nil), + "GetRunID": []uint8(nil), + "GetScheduleID": int64(0), + "GetWorkflowID": "", + }, + "*serialization.TimerInfo": { + "GetExpiryTimestamp": zeroUnix, + "GetStartedID": int64(0), + "GetTaskID": int64(0), + "GetVersion": int64(0), + }, + "*serialization.RequestCancelInfo": { + "GetCancelRequestID": "", + "GetInitiatedEventBatchID": int64(0), + "GetVersion": int64(0), + }, + "*serialization.SignalInfo": { + "GetControl": []uint8(nil), + "GetInitiatedEventBatchID": int64(0), + "GetInput": []uint8(nil), + "GetName": "", + "GetRequestID": "", + "GetVersion": int64(0), + }, + "*serialization.ChildExecutionInfo": { + "GetCreateRequestID": "", + "GetDomainID": "", + "GetDomainNameDEPRECATED": "", + "GetInitiatedEvent": []uint8(nil), + "GetInitiatedEventBatchID": int64(0), + "GetInitiatedEventEncoding": "", + "GetParentClosePolicy": int32(0), + "GetStartedEvent": []uint8(nil), + "GetStartedEventEncoding": "", + "GetStartedID": int64(0), + "GetStartedRunID": []uint8(nil), + "GetStartedWorkflowID": "", + "GetVersion": int64(0), + "GetWorkflowTypeName": "", + }, + "*serialization.ActivityInfo": { + "GetActivityID": "", + "GetAttempt": int32(0), + "GetCancelRequestID": int64(0), + "GetCancelRequested": false, + "GetHasRetryPolicy": false, + "GetHeartbeatTimeout": time.Duration(0), + "GetRequestID": "", + "GetRetryBackoffCoefficient": float64(0), + "GetRetryExpirationTimestamp": zeroUnix, + "GetRetryInitialInterval": time.Duration(0), + "GetRetryLastFailureDetails": []uint8(nil), + "GetRetryLastFailureReason": "", + "GetRetryLastWorkerIdentity": "", + "GetRetryMaximumAttempts": int32(0), + "GetRetryMaximumInterval": time.Duration(0), + "GetRetryNonRetryableErrors": []string(nil), + "GetScheduleToCloseTimeout": time.Duration(0), + "GetScheduleToStartTimeout": time.Duration(0), + "GetScheduledEvent": []uint8(nil), + "GetScheduledEventBatchID": int64(0), + "GetScheduledEventEncoding": "", + "GetScheduledTimestamp": zeroUnix, + "GetStartToCloseTimeout": time.Duration(0), + "GetStartedEvent": []uint8(nil), + "GetStartedEventEncoding": "", + "GetStartedID": int64(0), + "GetStartedIdentity": "", + "GetStartedTimestamp": zeroUnix, + "GetTaskList": "", + "GetTimerTaskStatus": int32(0), + "GetVersion": int64(0), + }, + "*serialization.HistoryTreeInfo": { + "GetAncestors": []*types.HistoryBranchRange(nil), + "GetCreatedTimestamp": zeroUnix, + "GetInfo": "", + }, + "*serialization.DomainInfo": { + "GetActiveClusterName": "", + "GetArchivalBucket": "", + "GetArchivalStatus": int16(0), + "GetBadBinaries": []uint8(nil), + "GetBadBinariesEncoding": "", + "GetClusters": []string(nil), + "GetConfigVersion": int64(0), + "GetData": map[string]string(nil), + "GetDescription": "", + "GetEmitMetric": false, + "GetFailoverEndTimestamp": zeroUnix, + "GetFailoverNotificationVersion": int64(0), + "GetFailoverVersion": int64(0), + "GetHistoryArchivalStatus": int16(0), + "GetHistoryArchivalURI": "", + "GetLastUpdatedTimestamp": zeroUnix, + "GetName": "", + "GetNotificationVersion": int64(0), + "GetOwner": "", + "GetPreviousFailoverVersion": int64(0), + "GetRetention": time.Duration(0), + "GetStatus": int32(0), + "GetVisibilityArchivalStatus": int16(0), + "GetVisibilityArchivalURI": "", + }, + "*serialization.ShardInfo": { + "GetClusterReplicationLevel": map[string]int64(nil), + "GetClusterTimerAckLevel": map[string]time.Time(nil), + "GetClusterTransferAckLevel": map[string]int64(nil), + "GetCrossClusterProcessingQueueStates": []uint8(nil), + "GetCrossClusterProcessingQueueStatesEncoding": "", + "GetDomainNotificationVersion": int64(0), + "GetOwner": "", + "GetPendingFailoverMarkers": []uint8(nil), + "GetPendingFailoverMarkersEncoding": "", + "GetReplicationAckLevel": int64(0), + "GetReplicationDlqAckLevel": map[string]int64(nil), + "GetStolenSinceRenew": int32(0), + "GetTimerAckLevel": zeroUnix, + "GetTimerProcessingQueueStates": []uint8(nil), + "GetTimerProcessingQueueStatesEncoding": "", + "GetTransferAckLevel": int64(0), + "GetTransferProcessingQueueStates": []uint8(nil), + "GetTransferProcessingQueueStatesEncoding": "", + "GetUpdatedAt": zeroUnix, + }, +} + +var expectedEmpty = map[string]map[string]any{ + "*serialization.WorkflowExecutionInfo": { + "GetAutoResetPoints": []uint8(nil), + "GetAutoResetPointsEncoding": "", + "GetCancelRequestID": "", + "GetCancelRequested": false, + "GetClientFeatureVersion": "", + "GetClientImpl": "", + "GetClientLibraryVersion": "", + "GetCloseStatus": int32(0), + "GetCompletionEvent": []uint8(nil), + "GetCompletionEventEncoding": "", + "GetCreateRequestID": "", + "GetCompletionEventBatchID": int64(0), + "GetCronSchedule": "", + "GetDecisionAttempt": int64(0), + "GetDecisionOriginalScheduledTimestamp": zeroUnix, + "GetDecisionRequestID": "", + "GetDecisionScheduleID": int64(0), + "GetDecisionScheduledTimestamp": zeroUnix, + "GetDecisionStartedID": int64(0), + "GetDecisionStartedTimestamp": zeroUnix, + "GetDecisionTaskTimeout": time.Duration(0), + "GetDecisionTimeout": time.Duration(0), + "GetLastFirstEventID": int64(0), + "GetLastProcessedEvent": int64(0), + "GetParentWorkflowID": "", + "GetStartVersion": int64(0), + "GetTaskList": "", + "GetDecisionVersion": int64(0), + "GetEventBranchToken": []uint8(nil), + "GetEventStoreVersion": int32(0), + "GetExecutionContext": []uint8(nil), + "GetFirstExecutionRunID": []uint8(nil), + "GetHasRetryPolicy": false, + "GetInitiatedID": int64(0), + "GetIsCron": false, + "GetLastEventTaskID": int64(0), + "GetLastUpdatedTimestamp": zeroUnix, + "GetLastWriteEventID": int64(0), + "GetMemo": map[string][]uint8(nil), + "GetParentDomainID": []uint8(nil), + "GetParentRunID": []uint8(nil), + "GetPartitionConfig": map[string]string(nil), + "GetHistorySize": int64(0), + "GetRetryAttempt": int64(0), + "GetRetryBackoffCoefficient": float64(0), + "GetRetryExpiration": time.Duration(0), + "GetRetryExpirationTimestamp": zeroUnix, + "GetRetryInitialInterval": time.Duration(0), + "GetRetryMaximumAttempts": int32(0), + "GetRetryMaximumInterval": time.Duration(0), + "GetRetryNonRetryableErrors": []string(nil), + "GetSearchAttributes": map[string][]uint8(nil), + "GetSignalCount": int64(0), + "GetStartTimestamp": zeroUnix, + "GetState": int32(0), + "GetStickyScheduleToStartTimeout": time.Duration(0), + "GetStickyTaskList": "", + "GetVersionHistories": []uint8(nil), + "GetVersionHistoriesEncoding": "", + "GetWorkflowTimeout": time.Duration(0), + "GetWorkflowTypeName": "", + }, + "*serialization.TimerTaskInfo": { + "GetDomainID": []uint8(nil), + "GetEventID": int64(0), + "GetRunID": []uint8(nil), + "GetScheduleAttempt": int64(0), + "GetTaskType": int16(0), + "GetTimeoutType": int16(0), + "GetVersion": int64(0), + "GetWorkflowID": "", + }, + "*serialization.ReplicationTaskInfo": { + "GetBranchToken": []uint8(nil), + "GetCreationTimestamp": zeroUnix, + "GetDomainID": []uint8(nil), + "GetEventStoreVersion": int32(0), + "GetFirstEventID": int64(0), + "GetNewRunBranchToken": []uint8(nil), + "GetNewRunEventStoreVersion": int32(0), + "GetNextEventID": int64(0), + "GetRunID": []uint8(nil), + "GetScheduledID": int64(0), + "GetTaskType": int16(0), + "GetVersion": int64(0), + "GetWorkflowID": "", + }, + "*serialization.TaskListInfo": { + "GetAckLevel": int64(0), + "GetExpiryTimestamp": zeroUnix, + "GetKind": int16(0), + "GetLastUpdated": zeroUnix, + }, + "*serialization.TaskInfo": { + "GetCreatedTimestamp": zeroUnix, + "GetExpiryTimestamp": zeroUnix, + "GetPartitionConfig": map[string]string(nil), + "GetRunID": []uint8(nil), + "GetScheduleID": int64(0), + "GetWorkflowID": "", + }, + "*serialization.TimerInfo": { + "GetExpiryTimestamp": zeroUnix, + "GetStartedID": int64(0), + "GetTaskID": int64(0), + "GetVersion": int64(0), + }, + "*serialization.RequestCancelInfo": { + "GetCancelRequestID": "", + "GetInitiatedEventBatchID": int64(0), + "GetVersion": int64(0), + }, + "*serialization.SignalInfo": { + "GetControl": []uint8(nil), + "GetInitiatedEventBatchID": int64(0), + "GetInput": []uint8(nil), + "GetName": "", + "GetRequestID": "", + "GetVersion": int64(0), + }, + "*serialization.ChildExecutionInfo": { + "GetCreateRequestID": "", + "GetDomainID": "", + "GetDomainNameDEPRECATED": "", + "GetInitiatedEvent": []uint8(nil), + "GetInitiatedEventBatchID": int64(0), + "GetInitiatedEventEncoding": "", + "GetParentClosePolicy": int32(0), + "GetStartedEvent": []uint8(nil), + "GetStartedEventEncoding": "", + "GetStartedID": int64(0), + "GetStartedRunID": []uint8(nil), + "GetStartedWorkflowID": "", + "GetVersion": int64(0), + "GetWorkflowTypeName": "", + }, + "*serialization.ActivityInfo": { + "GetActivityID": "", + "GetAttempt": int32(0), + "GetCancelRequestID": int64(0), + "GetCancelRequested": false, + "GetHasRetryPolicy": false, + "GetHeartbeatTimeout": time.Duration(0), + "GetRequestID": "", + "GetRetryBackoffCoefficient": float64(0), + "GetRetryExpirationTimestamp": zeroUnix, + "GetRetryInitialInterval": time.Duration(0), + "GetRetryLastFailureDetails": []uint8(nil), + "GetRetryLastFailureReason": "", + "GetRetryLastWorkerIdentity": "", + "GetRetryMaximumAttempts": int32(0), + "GetRetryMaximumInterval": time.Duration(0), + "GetRetryNonRetryableErrors": []string(nil), + "GetScheduleToCloseTimeout": time.Duration(0), + "GetScheduleToStartTimeout": time.Duration(0), + "GetScheduledEvent": []uint8(nil), + "GetScheduledEventBatchID": int64(0), + "GetScheduledEventEncoding": "", + "GetScheduledTimestamp": zeroUnix, + "GetStartToCloseTimeout": time.Duration(0), + "GetStartedEvent": []uint8(nil), + "GetStartedEventEncoding": "", + "GetStartedID": int64(0), + "GetStartedIdentity": "", + "GetStartedTimestamp": zeroUnix, + "GetTaskList": "", + "GetTimerTaskStatus": int32(0), + "GetVersion": int64(0), + }, + "*serialization.HistoryTreeInfo": { + "GetAncestors": []*types.HistoryBranchRange(nil), + "GetCreatedTimestamp": zeroUnix, + "GetInfo": "", + }, + "*serialization.DomainInfo": { + "GetActiveClusterName": "", + "GetArchivalBucket": "", + "GetArchivalStatus": int16(0), + "GetBadBinaries": []uint8(nil), + "GetBadBinariesEncoding": "", + "GetClusters": []string(nil), + "GetConfigVersion": int64(0), + "GetData": map[string]string(nil), + "GetDescription": "", + "GetEmitMetric": false, + "GetFailoverEndTimestamp": zeroUnix, + "GetFailoverNotificationVersion": int64(0), + "GetFailoverVersion": int64(0), + "GetHistoryArchivalStatus": int16(0), + "GetHistoryArchivalURI": "", + "GetLastUpdatedTimestamp": zeroUnix, + "GetName": "", + "GetNotificationVersion": int64(0), + "GetOwner": "", + "GetPreviousFailoverVersion": int64(0), + "GetRetention": time.Duration(0), + "GetStatus": int32(0), + "GetVisibilityArchivalStatus": int16(0), + "GetVisibilityArchivalURI": "", + }, + "*serialization.ShardInfo": { + "GetClusterReplicationLevel": map[string]int64(nil), + "GetClusterTimerAckLevel": map[string]time.Time(nil), + "GetClusterTransferAckLevel": map[string]int64(nil), + "GetCrossClusterProcessingQueueStates": []uint8(nil), + "GetCrossClusterProcessingQueueStatesEncoding": "", + "GetDomainNotificationVersion": int64(0), + "GetOwner": "", + "GetPendingFailoverMarkers": []uint8(nil), + "GetPendingFailoverMarkersEncoding": "", + "GetReplicationAckLevel": int64(0), + "GetReplicationDlqAckLevel": map[string]int64(nil), + "GetStolenSinceRenew": int32(0), + "GetTimerAckLevel": zeroUnix, + "GetTimerProcessingQueueStates": []uint8(nil), + "GetTimerProcessingQueueStatesEncoding": "", + "GetTransferAckLevel": int64(0), + "GetTransferProcessingQueueStates": []uint8(nil), + "GetTransferProcessingQueueStatesEncoding": "", + "GetUpdatedAt": zeroUnix, + }, +} + +var expectedNonEmpty = map[string]map[string]any{ + "*serialization.WorkflowExecutionInfo": { + "GetAutoResetPoints": []byte("resetpoints"), + "GetAutoResetPointsEncoding": "", + "GetCancelRequestID": "", + "GetCancelRequested": false, + "GetClientFeatureVersion": "", + "GetClientImpl": "", + "GetClientLibraryVersion": "", + "GetCloseStatus": int32(6), + "GetCompletionEvent": []byte("completionEvent"), + "GetCompletionEventEncoding": "completionEventEncoding", + "GetCreateRequestID": "", + "GetCompletionEventBatchID": int64(2), + "GetCronSchedule": "", + "GetDecisionAttempt": int64(0), + "GetDecisionOriginalScheduledTimestamp": time.Time{}, + "GetDecisionRequestID": "", + "GetDecisionScheduleID": int64(0), + "GetDecisionScheduledTimestamp": time.Time{}, + "GetDecisionStartedID": int64(0), + "GetDecisionStartedTimestamp": time.Time{}, + "GetDecisionTaskTimeout": time.Duration(0), + "GetDecisionTimeout": time.Duration(4), + "GetLastFirstEventID": int64(7), + "GetLastProcessedEvent": int64(0), + "GetParentWorkflowID": "parentWorkflowID", + "GetStartVersion": int64(0), + "GetTaskList": "taskList", + "GetDecisionVersion": int64(0), + "GetEventBranchToken": []uint8(nil), + "GetEventStoreVersion": int32(0), + "GetExecutionContext": []byte("executionContext"), + "GetFirstExecutionRunID": []uint8(nil), + "GetHasRetryPolicy": false, + "GetInitiatedID": int64(1), + "GetIsCron": false, + "GetLastEventTaskID": int64(0), + "GetLastUpdatedTimestamp": time.Time{}, + "GetLastWriteEventID": int64(0), + "GetMemo": map[string][]uint8(nil), + "GetParentDomainID": []byte(parentDomainID), + "GetParentRunID": []byte(parentRunID), + "GetPartitionConfig": map[string]string(nil), + "GetHistorySize": int64(0), + "GetRetryAttempt": int64(0), + "GetRetryBackoffCoefficient": float64(0), + "GetRetryExpiration": time.Duration(0), + "GetRetryExpirationTimestamp": time.Time{}, + "GetRetryInitialInterval": time.Duration(0), + "GetRetryMaximumAttempts": int32(0), + "GetRetryMaximumInterval": time.Duration(0), + "GetRetryNonRetryableErrors": []string(nil), + "GetSearchAttributes": map[string][]uint8{ + "key": []byte("value"), + }, + "GetSignalCount": int64(0), + "GetStartTimestamp": time.Time{}, + "GetState": int32(5), + "GetStickyScheduleToStartTimeout": time.Duration(0), + "GetStickyTaskList": "", + "GetVersionHistories": []uint8(nil), + "GetVersionHistoriesEncoding": "", + "GetWorkflowTimeout": time.Duration(3), + "GetWorkflowTypeName": "workflowTypeName", + }, + "*serialization.TimerTaskInfo": { + "GetDomainID": []byte(taskDomainID), + "GetEventID": int64(5), + "GetRunID": []byte(taskRunID), + "GetScheduleAttempt": int64(4), + "GetTaskType": int16(1), + "GetTimeoutType": int16(2), + "GetVersion": int64(3), + "GetWorkflowID": "workflowID", + }, + "*serialization.ReplicationTaskInfo": { + "GetBranchToken": []byte("branchToken"), + "GetCreationTimestamp": replicationCreationTimestamp, + "GetDomainID": []uint8(replicationTaskDomainID), + "GetEventStoreVersion": int32(6), + "GetFirstEventID": int64(3), + "GetNewRunBranchToken": []byte("newRunBranchToken"), + "GetNewRunEventStoreVersion": int32(7), + "GetNextEventID": int64(4), + "GetRunID": []byte(replicationTaskRunID), + "GetScheduledID": int64(5), + "GetTaskType": int16(1), + "GetVersion": int64(2), + "GetWorkflowID": "workflowID", + }, + "*serialization.TaskListInfo": { + "GetAckLevel": int64(2), + "GetExpiryTimestamp": taskListInfoExpireTime, + "GetKind": int16(1), + "GetLastUpdated": taskListInfoLastUpdateTime, + }, + "*serialization.TaskInfo": { + "GetCreatedTimestamp": taskInfoCreateTime, + "GetExpiryTimestamp": taskInfoExpiryTime, + "GetPartitionConfig": map[string]string{"key": "value"}, + "GetRunID": []byte(taskInfoRunID), + "GetScheduleID": int64(1), + "GetWorkflowID": "workflowID", + }, + "*serialization.TimerInfo": { + "GetExpiryTimestamp": timerInfoExpireTime, + "GetStartedID": int64(2), + "GetTaskID": int64(3), + "GetVersion": int64(1), + }, + "*serialization.RequestCancelInfo": { + "GetCancelRequestID": "cancelRequestID", + "GetInitiatedEventBatchID": int64(2), + "GetVersion": int64(1), + }, + "*serialization.SignalInfo": { + "GetControl": []byte("signalControl"), + "GetInitiatedEventBatchID": int64(2), + "GetInput": []byte("signalInput"), + "GetName": "signalName", + "GetRequestID": "signalRequestID", + "GetVersion": int64(1), + }, + "*serialization.ChildExecutionInfo": { + "GetCreateRequestID": "createRequestID", + "GetDomainID": "domainID", + "GetDomainNameDEPRECATED": "", + "GetInitiatedEvent": []byte("initiatedEvent"), + "GetInitiatedEventBatchID": int64(2), + "GetInitiatedEventEncoding": "initiatedEventEncoding", + "GetParentClosePolicy": int32(1), + "GetStartedEvent": []byte("startedEvent"), + "GetStartedEventEncoding": "startedEventEncoding", + "GetStartedID": int64(3), + "GetStartedRunID": []byte(childExecutionInfoStartedRunID), + "GetStartedWorkflowID": "startedWorkflowID", + "GetVersion": int64(1), + "GetWorkflowTypeName": "workflowTypeName", + }, + "*serialization.ActivityInfo": { + "GetActivityID": "activityID", + "GetAttempt": int32(6), + "GetCancelRequestID": int64(4), + "GetCancelRequested": true, + "GetHasRetryPolicy": true, + "GetHeartbeatTimeout": time.Duration(4), + "GetRequestID": "requestID", + "GetRetryBackoffCoefficient": float64(8), + "GetRetryExpirationTimestamp": activeInfoRetryExpirationTime, + "GetRetryInitialInterval": time.Duration(5), + "GetRetryLastFailureDetails": []byte("retryLastFailureDetails"), + "GetRetryLastFailureReason": "retryLastFailureReason", + "GetRetryLastWorkerIdentity": "retryLastWorkerIdentity", + "GetRetryMaximumAttempts": int32(7), + "GetRetryMaximumInterval": time.Duration(6), + "GetRetryNonRetryableErrors": []string{"error1", "error2"}, + "GetScheduleToCloseTimeout": time.Duration(1), + "GetScheduleToStartTimeout": time.Duration(2), + "GetScheduledEvent": []byte("scheduledEvent"), + "GetScheduledEventBatchID": int64(2), + "GetScheduledEventEncoding": "scheduledEventEncoding", + "GetScheduledTimestamp": activityInfoScheduledTime, + "GetStartToCloseTimeout": time.Duration(3), + "GetStartedEvent": []byte("startedEvent"), + "GetStartedEventEncoding": "startedEventEncoding", + "GetStartedID": int64(3), + "GetStartedIdentity": "startedIdentity", + "GetStartedTimestamp": activeInfoStartedTime, + "GetTaskList": "taskList", + "GetTimerTaskStatus": int32(5), + "GetVersion": int64(1), + }, + "*serialization.HistoryTreeInfo": { + "GetAncestors": []*types.HistoryBranchRange{ + { + BranchID: "branchID1", + }, + { + BranchID: "branchID2", + }, + }, + "GetCreatedTimestamp": historyTreeEventCreatedTime, + "GetInfo": "historyTreeInfo", + }, + "*serialization.DomainInfo": { + "GetActiveClusterName": "cluster1", + "GetArchivalBucket": "archivalBucket", + "GetArchivalStatus": int16(2), + "GetBadBinaries": []byte("badBinaries"), + "GetBadBinariesEncoding": "badBinariesEncoding", + "GetClusters": []string{"cluster1", "cluster2"}, + "GetConfigVersion": int64(3), + "GetData": map[string]string{"datakey": "datavalue"}, + "GetDescription": "description", + "GetEmitMetric": true, + "GetFailoverEndTimestamp": domainInfoFailoverEndTimestamp, + "GetFailoverNotificationVersion": int64(5), + "GetFailoverVersion": int64(6), + "GetHistoryArchivalStatus": int16(7), + "GetHistoryArchivalURI": "historyArchivalURI", + "GetLastUpdatedTimestamp": domainInfoLastUpdatedTimestamp, + "GetName": "name", + "GetNotificationVersion": int64(4), + "GetOwner": "owner", + "GetPreviousFailoverVersion": int64(9), + "GetRetention": time.Duration(1), + "GetStatus": int32(1), + "GetVisibilityArchivalStatus": int16(8), + "GetVisibilityArchivalURI": "visibilityArchivalURI", + }, + "*serialization.ShardInfo": { + "GetClusterReplicationLevel": map[string]int64{ + "cluster1": 6, + }, + "GetClusterTimerAckLevel": map[string]time.Time{ + "cluster1": shardInfoTimerAckLevel, + }, + "GetClusterTransferAckLevel": map[string]int64{ + "cluster1": 5, + }, + "GetCrossClusterProcessingQueueStates": []byte("crossClusterProcessingQueueStates"), + "GetCrossClusterProcessingQueueStatesEncoding": "crossClusterProcessingQueueStatesEncoding", + "GetDomainNotificationVersion": int64(4), + "GetOwner": "owner", + "GetPendingFailoverMarkers": []byte("pendingFailoverMarkers"), + "GetPendingFailoverMarkersEncoding": "pendingFailoverMarkersEncoding", + "GetReplicationAckLevel": int64(2), + "GetReplicationDlqAckLevel": map[string]int64{ + "cluster1": 7, + }, + "GetStolenSinceRenew": int32(1), + "GetTimerAckLevel": shardInfoTimerAckLevel, + "GetTimerProcessingQueueStates": []byte("timerProcessingQueueStates"), + "GetTimerProcessingQueueStatesEncoding": "timerProcessingQueueStatesEncoding", + "GetTransferAckLevel": int64(3), + "GetTransferProcessingQueueStates": []byte("transferProcessingQueueStates"), + "GetTransferProcessingQueueStatesEncoding": "transferProcessingQueueStatesEncoding", + "GetUpdatedAt": shardInfoUpdatedTime, + }, +} diff --git a/common/persistence/serialization/getters_test.go b/common/persistence/serialization/getters_test.go new file mode 100644 index 00000000000..c8d6360710f --- /dev/null +++ b/common/persistence/serialization/getters_test.go @@ -0,0 +1,344 @@ +package serialization + +import ( + "reflect" + "strings" + "testing" + "time" + + "github.com/google/go-cmp/cmp" + "github.com/stretchr/testify/require" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +func TestGettersForAllNilInfos(t *testing.T) { + for _, info := range []any{ + &WorkflowExecutionInfo{}, + &TimerTaskInfo{}, + &ReplicationTaskInfo{}, + &TaskListInfo{}, + &TaskInfo{}, + &TimerInfo{}, + &RequestCancelInfo{}, + &SignalInfo{}, + &ChildExecutionInfo{}, + &ActivityInfo{}, + &HistoryTreeInfo{}, + &DomainInfo{}, + &ShardInfo{}, + } { + name := reflect.TypeOf(info).String() + t.Run(name, func(t *testing.T) { + res := emptyView(info) + if diff := cmp.Diff(expectedNil[name], res); diff != "" { + t.Errorf("nilValue mismatch (-want +got):\n%s", diff) + } + }) + } +} + +func TestGettersForEmptyInfos(t *testing.T) { + for _, info := range []any{ + &WorkflowExecutionInfo{}, + &TimerTaskInfo{}, + &ReplicationTaskInfo{}, + &TaskListInfo{}, + &TaskInfo{}, + &TimerInfo{}, + &RequestCancelInfo{}, + &SignalInfo{}, + &ChildExecutionInfo{}, + &ActivityInfo{}, + &HistoryTreeInfo{}, + &DomainInfo{}, + &ShardInfo{}, + } { + name := reflect.TypeOf(info).String() + t.Run(name, func(t *testing.T) { + res := emptyView(info) + if diff := cmp.Diff(expectedEmpty[name], res); diff != "" { + t.Errorf("emptyValue mismatch (-want +got):\n%s", diff) + } + }) + } +} + +var ( + parentDomainID = MustParseUUID("00000000-0000-0000-0000-000000000001") + parentRunID = MustParseUUID("00000000-0000-0000-0000-000000000002") + + taskDomainID = MustParseUUID("00000000-0000-0000-0000-000000000003") + taskRunID = MustParseUUID("00000000-0000-0000-0000-000000000004") + + replicationTaskDomainID = MustParseUUID("00000000-0000-0000-0000-000000000005") + replicationTaskRunID = MustParseUUID("00000000-0000-0000-0000-000000000006") + replicationCreationTimestamp = time.Unix(10, 0) + + taskListInfoExpireTime = time.Unix(20, 0) + taskListInfoLastUpdateTime = time.Unix(30, 0) + + taskInfoRunID = MustParseUUID("00000000-0000-0000-0000-000000000007") + taskInfoExpiryTime = time.Unix(40, 0) + taskInfoCreateTime = time.Unix(50, 0) + + timerInfoExpireTime = time.Unix(60, 0) + + signalInfoInput = []byte("signalInput") + signalInfoControl = []byte("signalControl") + + childExecutionInfoInitiatedEvent = []byte("initiatedEvent") + childExecutionInfoStartedRunID = MustParseUUID("00000000-0000-0000-0000-000000000008") + childExecutionInfoStartedEvent = []byte("startedEvent") + + activityInfoScheduledTime = time.Unix(70, 0) + activeInfoStartedTime = time.Unix(80, 0) + activeInfoRetryExpirationTime = time.Unix(90, 0) + + historyTreeEventCreatedTime = time.Unix(100, 0) + + domainInfoFailoverEndTimestamp = time.Unix(110, 0) + domainInfoLastUpdatedTimestamp = time.Unix(120, 0) + + shardInfoUpdatedTime = time.Unix(130, 0) + shardInfoTimerAckLevel = time.Unix(140, 0) +) + +func TestGettersForInfos(t *testing.T) { + for _, info := range []any{ + &WorkflowExecutionInfo{ + ParentDomainID: parentDomainID, + ParentWorkflowID: "parentWorkflowID", + ParentRunID: parentRunID, + InitiatedID: 1, + CompletionEventBatchID: common.Int64Ptr(2), + CompletionEvent: []byte("completionEvent"), + CompletionEventEncoding: "completionEventEncoding", + TaskList: "taskList", + WorkflowTypeName: "workflowTypeName", + WorkflowTimeout: 3, + DecisionTimeout: 4, + ExecutionContext: []byte("executionContext"), + State: 5, + CloseStatus: 6, + LastFirstEventID: 7, + AutoResetPoints: []byte("resetpoints"), + SearchAttributes: map[string][]byte{"key": []byte("value")}, + }, + &TimerTaskInfo{ + DomainID: taskDomainID, + WorkflowID: "workflowID", + RunID: taskRunID, + TaskType: 1, + TimeoutType: common.Int16Ptr(2), + Version: 3, + ScheduleAttempt: 4, + EventID: 5, + }, + &ReplicationTaskInfo{ + DomainID: replicationTaskDomainID, + WorkflowID: "workflowID", + RunID: replicationTaskRunID, + TaskType: 1, + Version: 2, + FirstEventID: 3, + NextEventID: 4, + ScheduledID: 5, + EventStoreVersion: 6, + NewRunEventStoreVersion: 7, + BranchToken: []byte("branchToken"), + NewRunBranchToken: []byte("newRunBranchToken"), + CreationTimestamp: replicationCreationTimestamp, + }, + &TaskListInfo{ + Kind: 1, + AckLevel: 2, + ExpiryTimestamp: taskListInfoExpireTime, + LastUpdated: taskListInfoLastUpdateTime, + }, + &TaskInfo{ + WorkflowID: "workflowID", + RunID: taskInfoRunID, + ScheduleID: 1, + ExpiryTimestamp: taskInfoExpiryTime, + CreatedTimestamp: taskInfoCreateTime, + PartitionConfig: map[string]string{ + "key": "value", + }, + }, + &TimerInfo{ + Version: 1, + StartedID: 2, + ExpiryTimestamp: timerInfoExpireTime, + TaskID: 3, + }, + &RequestCancelInfo{ + Version: 1, + InitiatedEventBatchID: 2, + CancelRequestID: "cancelRequestID", + }, + &SignalInfo{ + Version: 1, + InitiatedEventBatchID: 2, + RequestID: "signalRequestID", + Name: "signalName", + Input: signalInfoInput, + Control: signalInfoControl, + }, + &ChildExecutionInfo{ + Version: 1, + InitiatedEventBatchID: 2, + StartedID: 3, + InitiatedEvent: childExecutionInfoInitiatedEvent, + InitiatedEventEncoding: "initiatedEventEncoding", + StartedWorkflowID: "startedWorkflowID", + StartedRunID: childExecutionInfoStartedRunID, + StartedEvent: childExecutionInfoStartedEvent, + StartedEventEncoding: "startedEventEncoding", + CreateRequestID: "createRequestID", + DomainID: "domainID", + WorkflowTypeName: "workflowTypeName", + ParentClosePolicy: 1, + }, + &ActivityInfo{ + Version: 1, + ScheduledEventBatchID: 2, + ScheduledEvent: []byte("scheduledEvent"), + ScheduledEventEncoding: "scheduledEventEncoding", + ScheduledTimestamp: activityInfoScheduledTime, + StartedID: 3, + StartedEvent: []byte("startedEvent"), + StartedEventEncoding: "startedEventEncoding", + StartedTimestamp: activeInfoStartedTime, + ActivityID: "activityID", + RequestID: "requestID", + ScheduleToCloseTimeout: time.Duration(1), + ScheduleToStartTimeout: time.Duration(2), + StartToCloseTimeout: time.Duration(3), + HeartbeatTimeout: time.Duration(4), + CancelRequested: true, + CancelRequestID: 4, + TimerTaskStatus: 5, + Attempt: 6, + TaskList: "taskList", + StartedIdentity: "startedIdentity", + HasRetryPolicy: true, + RetryInitialInterval: time.Duration(5), + RetryMaximumInterval: time.Duration(6), + RetryMaximumAttempts: 7, + RetryExpirationTimestamp: activeInfoRetryExpirationTime, + RetryBackoffCoefficient: 8, + RetryNonRetryableErrors: []string{"error1", "error2"}, + RetryLastWorkerIdentity: "retryLastWorkerIdentity", + RetryLastFailureReason: "retryLastFailureReason", + RetryLastFailureDetails: []byte("retryLastFailureDetails"), + }, + &HistoryTreeInfo{ + CreatedTimestamp: historyTreeEventCreatedTime, + Ancestors: []*types.HistoryBranchRange{ + { + BranchID: "branchID1", + }, + { + BranchID: "branchID2", + }, + }, + Info: "historyTreeInfo", + }, + &DomainInfo{ + Name: "name", + Description: "description", + Owner: "owner", + Status: 1, + Retention: time.Duration(1), + EmitMetric: true, + ArchivalBucket: "archivalBucket", + ArchivalStatus: 2, + ConfigVersion: 3, + NotificationVersion: 4, + FailoverNotificationVersion: 5, + FailoverVersion: 6, + ActiveClusterName: "cluster1", + Clusters: []string{"cluster1", "cluster2"}, + Data: map[string]string{ + "datakey": "datavalue", + }, + BadBinaries: []byte("badBinaries"), + BadBinariesEncoding: "badBinariesEncoding", + HistoryArchivalStatus: 7, + HistoryArchivalURI: "historyArchivalURI", + VisibilityArchivalStatus: 8, + VisibilityArchivalURI: "visibilityArchivalURI", + FailoverEndTimestamp: &domainInfoFailoverEndTimestamp, + PreviousFailoverVersion: 9, + LastUpdatedTimestamp: domainInfoLastUpdatedTimestamp, + IsolationGroups: []byte("isolationGroups"), + IsolationGroupsEncoding: "isolationGroupsEncoding", + }, + &ShardInfo{ + StolenSinceRenew: 1, + UpdatedAt: shardInfoUpdatedTime, + ReplicationAckLevel: 2, + TransferAckLevel: 3, + TimerAckLevel: shardInfoTimerAckLevel, + DomainNotificationVersion: 4, + ClusterTransferAckLevel: map[string]int64{ + "cluster1": 5, + }, + ClusterTimerAckLevel: map[string]time.Time{ + "cluster1": shardInfoTimerAckLevel, + }, + Owner: "owner", + ClusterReplicationLevel: map[string]int64{ + "cluster1": 6, + }, + PendingFailoverMarkers: []byte("pendingFailoverMarkers"), + PendingFailoverMarkersEncoding: "pendingFailoverMarkersEncoding", + ReplicationDlqAckLevel: map[string]int64{ + "cluster1": 7, + }, + TransferProcessingQueueStates: []byte("transferProcessingQueueStates"), + TransferProcessingQueueStatesEncoding: "transferProcessingQueueStatesEncoding", + TimerProcessingQueueStates: []byte("timerProcessingQueueStates"), + TimerProcessingQueueStatesEncoding: "timerProcessingQueueStatesEncoding", + CrossClusterProcessingQueueStates: []byte("crossClusterProcessingQueueStates"), + CrossClusterProcessingQueueStatesEncoding: "crossClusterProcessingQueueStatesEncoding", + }, + } { + name := reflect.TypeOf(info).String() + t.Run(name, func(t *testing.T) { + val := infoView(info) + require.Equal(t, expectedNonEmpty[name], val) + }) + } +} + +func emptyView(info any) map[string]any { + infoVal := reflect.ValueOf(info) + infoT := reflect.TypeOf(infoVal.Interface()) + v := reflect.Zero(infoT) + res := make(map[string]any) + for i := 0; i < infoT.NumMethod(); i++ { + method := infoT.Method(i) + if strings.HasPrefix(method.Name, "Get") { + res[method.Name] = v.MethodByName(method.Name).Call(nil)[0].Interface() + } + } + + return res +} + +func infoView(info any) map[string]any { + v := reflect.ValueOf(info) + infoT := reflect.TypeOf(v.Interface()) + res := make(map[string]any) + for i := 0; i < infoT.NumMethod(); i++ { + method := infoT.Method(i) + if strings.HasPrefix(method.Name, "Get") { + resVal := v.MethodByName(method.Name).Call(nil)[0] + res[method.Name] = resVal.Interface() + } + } + + return res +} diff --git a/common/persistence/serialization/helpers_test.go b/common/persistence/serialization/helpers_test.go new file mode 100644 index 00000000000..4701b4aab92 --- /dev/null +++ b/common/persistence/serialization/helpers_test.go @@ -0,0 +1,9 @@ +package serialization + +func emptyMap[K comparable, V any]() map[K]V { + return map[K]V(nil) +} + +func emptySlice[K any]() []K { + return []K(nil) +} diff --git a/common/persistence/serialization/history_tree_info_test.go b/common/persistence/serialization/history_tree_info_test.go new file mode 100644 index 00000000000..b06e5c89c06 --- /dev/null +++ b/common/persistence/serialization/history_tree_info_test.go @@ -0,0 +1,32 @@ +package serialization + +import ( + "testing" + "time" + + fuzz "github.com/google/gofuzz" + "github.com/stretchr/testify/assert" +) + +func TestHistoryTreeInfoEmpty(t *testing.T) { + // Create a nil HistoryTree + var nilInfo *HistoryTreeInfo + + // Use assertions to check the values + assert.Equal(t, time.Unix(0, 0), nilInfo.GetCreatedTimestamp(), "CreatedTimestamp should be zero time") + assert.Nil(t, nilInfo.GetAncestors(), "Ancestors should be nil") + assert.Empty(t, nilInfo.GetInfo(), "Info should be empty string") +} + +func TestHistoryTreeInfoFilled(t *testing.T) { + filledInfo := HistoryTreeInfo{} + + f := fuzz.New() + + f.Fuzz(&filledInfo) + + // Use assertions to check the values + assert.Equal(t, filledInfo.CreatedTimestamp, filledInfo.GetCreatedTimestamp(), "CreatedTimestamp should match") + assert.Equal(t, filledInfo.Ancestors, filledInfo.GetAncestors(), "Ancestors should match") + assert.Equal(t, filledInfo.Info, filledInfo.GetInfo(), "Info should match") +} diff --git a/common/persistence/serialization/parser.go b/common/persistence/serialization/parser.go index 9c5b9b4ce45..261d281e0ff 100644 --- a/common/persistence/serialization/parser.go +++ b/common/persistence/serialization/parser.go @@ -353,8 +353,6 @@ func getDecoder(encoding common.EncodingType) (decoder, error) { switch encoding { case common.EncodingTypeThriftRW: return newThriftDecoder(), nil - case common.EncodingTypeProto: - return newProtoDecoder(), nil default: return nil, unsupportedEncodingError(encoding) } @@ -364,8 +362,6 @@ func getEncoder(encoding common.EncodingType) (encoder, error) { switch encoding { case common.EncodingTypeThriftRW: return newThriftEncoder(), nil - case common.EncodingTypeProto: - return newProtoEncoder(), nil default: return nil, unsupportedEncodingError(encoding) } diff --git a/common/persistence/serialization/parser_test.go b/common/persistence/serialization/parser_test.go index 1e27bd18b7b..443ce9cc197 100644 --- a/common/persistence/serialization/parser_test.go +++ b/common/persistence/serialization/parser_test.go @@ -23,24 +23,149 @@ package serialization import ( + "fmt" + "reflect" + "regexp" "testing" + "time" + fuzz "github.com/google/gofuzz" "github.com/stretchr/testify/assert" - + "github.com/stretchr/testify/require" "github.com/uber/cadence/common" + "github.com/uber/cadence/common/persistence" ) -func TestParse(t *testing.T) { +func TestParserRoundTrip(t *testing.T) { thriftParser, err := NewParser(common.EncodingTypeThriftRW, common.EncodingTypeThriftRW) assert.NoError(t, err) - domainInfo := &DomainInfo{ - Name: "test_name", - Data: map[string]string{"test_key": "test_value"}, + f := fuzz.New().Funcs(func(e *time.Time, c fuzz.Continue) { + *e = time.Unix(c.Int63n(1000000), 0) + }, func(e *time.Duration, c fuzz.Continue) { + *e = time.Duration(common.DurationToDays(time.Duration(c.Int63n(1000000)))) + }, func(e *UUID, c fuzz.Continue) { + *e = MustParseUUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8") + }).NilChance(0).NumElements(0, 10). + // IsCron is dynamic fields that is connected to CronSchedule, so we need to skip it and test separately. + SkipFieldsWithPattern(regexp.MustCompile("IsCron|CronSchedule")) + + for _, testCase := range []any{ + &ShardInfo{}, + &DomainInfo{}, + &HistoryTreeInfo{}, + &WorkflowExecutionInfo{}, + &ActivityInfo{}, + &ChildExecutionInfo{}, + &SignalInfo{}, + &RequestCancelInfo{}, + &TimerInfo{}, + &TaskInfo{}, + &TaskListInfo{}, + &TransferTaskInfo{}, + &TimerTaskInfo{}, + &ReplicationTaskInfo{}, + } { + t.Run(reflect.TypeOf(testCase).String(), func(t *testing.T) { + f.Fuzz(testCase) + blob := parse(t, thriftParser, testCase) + result := unparse(t, thriftParser, blob, testCase) + assert.Equal(t, testCase, result) + }) + } +} + +func parse(t *testing.T, parser Parser, data any) persistence.DataBlob { + var ( + blob persistence.DataBlob + err error + ) + switch v := data.(type) { + case *ShardInfo: + blob, err = parser.ShardInfoToBlob(v) + case *DomainInfo: + blob, err = parser.DomainInfoToBlob(v) + case *HistoryTreeInfo: + blob, err = parser.HistoryTreeInfoToBlob(v) + case *WorkflowExecutionInfo: + blob, err = parser.WorkflowExecutionInfoToBlob(v) + case *ActivityInfo: + blob, err = parser.ActivityInfoToBlob(v) + case *ChildExecutionInfo: + blob, err = parser.ChildExecutionInfoToBlob(v) + case *SignalInfo: + blob, err = parser.SignalInfoToBlob(v) + case *RequestCancelInfo: + blob, err = parser.RequestCancelInfoToBlob(v) + case *TimerInfo: + blob, err = parser.TimerInfoToBlob(v) + case *TaskInfo: + blob, err = parser.TaskInfoToBlob(v) + case *TaskListInfo: + blob, err = parser.TaskListInfoToBlob(v) + case *TransferTaskInfo: + blob, err = parser.TransferTaskInfoToBlob(v) + case *TimerTaskInfo: + blob, err = parser.TimerTaskInfoToBlob(v) + case *ReplicationTaskInfo: + blob, err = parser.ReplicationTaskInfoToBlob(v) + default: + err = fmt.Errorf("unknown type %T", v) } - db, err := thriftParser.DomainInfoToBlob(domainInfo) assert.NoError(t, err) - assert.NotNil(t, db.Data) - decodedDomainInfo, err := thriftParser.DomainInfoFromBlob(db.Data, string(db.Encoding)) + return blob +} + +func unparse(t *testing.T, parser Parser, blob persistence.DataBlob, result any) any { + var ( + data any + err error + ) + switch v := result.(type) { + case *ShardInfo: + data, err = parser.ShardInfoFromBlob(blob.Data, string(blob.Encoding)) + case *DomainInfo: + data, err = parser.DomainInfoFromBlob(blob.Data, string(blob.Encoding)) + case *HistoryTreeInfo: + data, err = parser.HistoryTreeInfoFromBlob(blob.Data, string(blob.Encoding)) + case *WorkflowExecutionInfo: + data, err = parser.WorkflowExecutionInfoFromBlob(blob.Data, string(blob.Encoding)) + case *ActivityInfo: + data, err = parser.ActivityInfoFromBlob(blob.Data, string(blob.Encoding)) + case *ChildExecutionInfo: + data, err = parser.ChildExecutionInfoFromBlob(blob.Data, string(blob.Encoding)) + case *SignalInfo: + data, err = parser.SignalInfoFromBlob(blob.Data, string(blob.Encoding)) + case *RequestCancelInfo: + data, err = parser.RequestCancelInfoFromBlob(blob.Data, string(blob.Encoding)) + case *TimerInfo: + data, err = parser.TimerInfoFromBlob(blob.Data, string(blob.Encoding)) + case *TaskInfo: + data, err = parser.TaskInfoFromBlob(blob.Data, string(blob.Encoding)) + case *TaskListInfo: + data, err = parser.TaskListInfoFromBlob(blob.Data, string(blob.Encoding)) + case *TransferTaskInfo: + data, err = parser.TransferTaskInfoFromBlob(blob.Data, string(blob.Encoding)) + case *TimerTaskInfo: + data, err = parser.TimerTaskInfoFromBlob(blob.Data, string(blob.Encoding)) + case *ReplicationTaskInfo: + data, err = parser.ReplicationTaskInfoFromBlob(blob.Data, string(blob.Encoding)) + default: + err = fmt.Errorf("unknown type %T", v) + } assert.NoError(t, err) - assert.Equal(t, domainInfo, decodedDomainInfo) + return data +} + +func TestParser_WorkflowExecution_with_cron(t *testing.T) { + info := &WorkflowExecutionInfo{ + CronSchedule: "@every 1m", + IsCron: true, + } + parser, err := NewParser(common.EncodingTypeThriftRW, common.EncodingTypeThriftRW) + require.NoError(t, err) + blob, err := parser.WorkflowExecutionInfoToBlob(info) + require.NoError(t, err) + result, err := parser.WorkflowExecutionInfoFromBlob(blob.Data, string(blob.Encoding)) + require.NoError(t, err) + assert.Equal(t, info, result) } diff --git a/common/persistence/serialization/persistence_mapper.go b/common/persistence/serialization/persistence_mapper.go index 918fce8a03f..5ba94b13a49 100644 --- a/common/persistence/serialization/persistence_mapper.go +++ b/common/persistence/serialization/persistence_mapper.go @@ -74,6 +74,7 @@ func ToInternalWorkflowExecutionInfo(info *WorkflowExecutionInfo) *persistence.I HistorySize: info.GetHistorySize(), FirstExecutionRunID: info.FirstExecutionRunID.String(), PartitionConfig: info.PartitionConfig, + IsCron: info.IsCron, } if info.ParentDomainID != nil { result.ParentDomainID = info.ParentDomainID.String() @@ -156,6 +157,7 @@ func FromInternalWorkflowExecutionInfo(executionInfo *persistence.InternalWorkfl InitiatedID: common.EmptyEventID, FirstExecutionRunID: MustParseUUID(executionInfo.FirstExecutionRunID), PartitionConfig: executionInfo.PartitionConfig, + IsCron: executionInfo.IsCron, } if executionInfo.CompletionEvent != nil { diff --git a/common/persistence/serialization/persistence_mapper_test.go b/common/persistence/serialization/persistence_mapper_test.go index 425d0b587a2..12930260417 100644 --- a/common/persistence/serialization/persistence_mapper_test.go +++ b/common/persistence/serialization/persistence_mapper_test.go @@ -89,6 +89,7 @@ func TestInternalWorkflowExecutionInfo(t *testing.T) { SearchAttributes: map[string][]byte{"key_1": []byte("SearchAttributes")}, HistorySize: int64(rand.Intn(1000)), PartitionConfig: map[string]string{"zone": "dca1"}, + IsCron: true, } actual := ToInternalWorkflowExecutionInfo(FromInternalWorkflowExecutionInfo(expected)) assert.Equal(t, expected.ParentDomainID, actual.ParentDomainID) @@ -144,4 +145,5 @@ func TestInternalWorkflowExecutionInfo(t *testing.T) { assert.Equal(t, expected.SearchAttributes, actual.SearchAttributes) assert.Equal(t, expected.HistorySize, actual.HistorySize) assert.Equal(t, expected.PartitionConfig, actual.PartitionConfig) + assert.Equal(t, expected.IsCron, actual.IsCron) } diff --git a/common/persistence/serialization/proto_decoder.go b/common/persistence/serialization/proto_decoder.go deleted file mode 100644 index 2d6144c8d19..00000000000 --- a/common/persistence/serialization/proto_decoder.go +++ /dev/null @@ -1,91 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2017-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 serialization - -type ( - protoDecoder struct{} -) - -func newProtoDecoder() decoder { - return &protoDecoder{} -} - -func (d *protoDecoder) shardInfoFromBlob(data []byte) (*ShardInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) domainInfoFromBlob(data []byte) (*DomainInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) historyTreeInfoFromBlob(data []byte) (*HistoryTreeInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) workflowExecutionInfoFromBlob(data []byte) (*WorkflowExecutionInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) activityInfoFromBlob(data []byte) (*ActivityInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) childExecutionInfoFromBlob(data []byte) (*ChildExecutionInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) signalInfoFromBlob(data []byte) (*SignalInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) requestCancelInfoFromBlob(data []byte) (*RequestCancelInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) timerInfoFromBlob(data []byte) (*TimerInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) taskInfoFromBlob(data []byte) (*TaskInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) taskListInfoFromBlob(data []byte) (*TaskListInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) transferTaskInfoFromBlob(data []byte) (*TransferTaskInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) crossClusterTaskInfoFromBlob(data []byte) (*CrossClusterTaskInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) timerTaskInfoFromBlob(data []byte) (*TimerTaskInfo, error) { - panic("not implemented") -} - -func (d *protoDecoder) replicationTaskInfoFromBlob(data []byte) (*ReplicationTaskInfo, error) { - panic("not implemented") -} diff --git a/common/persistence/serialization/proto_encoder.go b/common/persistence/serialization/proto_encoder.go deleted file mode 100644 index ee7d0c96b63..00000000000 --- a/common/persistence/serialization/proto_encoder.go +++ /dev/null @@ -1,97 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2017-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 serialization - -import ( - "github.com/uber/cadence/common" -) - -type protoEncoder struct{} - -func newProtoEncoder() encoder { - return &protoEncoder{} -} - -func (e *protoEncoder) shardInfoToBlob(*ShardInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) domainInfoToBlob(*DomainInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) historyTreeInfoToBlob(*HistoryTreeInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) workflowExecutionInfoToBlob(*WorkflowExecutionInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) activityInfoToBlob(*ActivityInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) childExecutionInfoToBlob(*ChildExecutionInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) signalInfoToBlob(*SignalInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) requestCancelInfoToBlob(*RequestCancelInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) timerInfoToBlob(*TimerInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) taskInfoToBlob(*TaskInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) taskListInfoToBlob(*TaskListInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) transferTaskInfoToBlob(*TransferTaskInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) crossClusterTaskInfoToBlob(*CrossClusterTaskInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) timerTaskInfoToBlob(*TimerTaskInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) replicationTaskInfoToBlob(*ReplicationTaskInfo) ([]byte, error) { - panic("not implemented") -} - -func (e *protoEncoder) encodingType() common.EncodingType { - return common.EncodingTypeProto -} diff --git a/common/persistence/serialization/shard_test.go b/common/persistence/serialization/shard_test.go new file mode 100644 index 00000000000..c6b1f68fb99 --- /dev/null +++ b/common/persistence/serialization/shard_test.go @@ -0,0 +1,68 @@ +package serialization + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestShard_empty_struct(t *testing.T) { + var s *ShardInfo + assert.Equal(t, int32(0), s.GetStolenSinceRenew()) + assert.Equal(t, time.Unix(0, 0), s.GetUpdatedAt()) + assert.Equal(t, int64(0), s.GetReplicationAckLevel()) + assert.Equal(t, int64(0), s.GetTransferAckLevel()) + assert.Equal(t, time.Unix(0, 0), s.GetTimerAckLevel()) + assert.Equal(t, int64(0), s.GetDomainNotificationVersion()) + assert.Equal(t, emptyMap[string, int64](), s.GetClusterTransferAckLevel()) + assert.Equal(t, emptyMap[string, time.Time](), s.GetClusterTimerAckLevel()) + assert.Equal(t, "", s.GetOwner()) + assert.Equal(t, emptyMap[string, int64](), s.GetClusterReplicationLevel()) + assert.Equal(t, emptySlice[uint8](), s.GetPendingFailoverMarkers()) + assert.Equal(t, "", s.GetPendingFailoverMarkersEncoding()) + assert.Equal(t, emptyMap[string, int64](), s.GetReplicationDlqAckLevel()) + assert.Equal(t, emptySlice[uint8](), s.GetTransferProcessingQueueStates()) + assert.Equal(t, "", s.GetTransferProcessingQueueStatesEncoding()) + assert.Equal(t, emptySlice[uint8](), s.GetCrossClusterProcessingQueueStates()) + assert.Equal(t, "", s.GetCrossClusterProcessingQueueStatesEncoding()) + assert.Equal(t, emptySlice[uint8](), s.GetTimerProcessingQueueStates()) + assert.Equal(t, "", s.GetTimerProcessingQueueStatesEncoding()) +} + +func TestShard_non_empty(t *testing.T) { + now := time.Now() + s := ShardInfo{ + StolenSinceRenew: 1, + UpdatedAt: now, + ReplicationAckLevel: 3, + TransferAckLevel: 4, + TimerAckLevel: now.Add(time.Second), + DomainNotificationVersion: 6, + ClusterTransferAckLevel: map[string]int64{"key1": 1, "key2": 2}, + ClusterTimerAckLevel: map[string]time.Time{"key1": now, "key2": now}, + Owner: "test_owner", + ClusterReplicationLevel: map[string]int64{"key1": 1, "key2": 2}, + PendingFailoverMarkers: []byte{1, 2, 3}, + PendingFailoverMarkersEncoding: "test_encoding", + ReplicationDlqAckLevel: map[string]int64{"key1": 1, "key2": 2}, + TransferProcessingQueueStates: []byte{1, 2, 3}, + TransferProcessingQueueStatesEncoding: "test_encoding", + CrossClusterProcessingQueueStates: []byte{1, 2, 3}, + CrossClusterProcessingQueueStatesEncoding: "test_encoding", + TimerProcessingQueueStates: []byte{1, 2, 3}, + TimerProcessingQueueStatesEncoding: "test_encoding", + } + assert.Equal(t, int32(1), s.GetStolenSinceRenew()) + assert.Equal(t, now, s.GetUpdatedAt()) + assert.Equal(t, int64(3), s.GetReplicationAckLevel()) + assert.Equal(t, int64(4), s.GetTransferAckLevel()) + assert.Equal(t, now.Add(time.Second), s.GetTimerAckLevel()) + assert.Equal(t, int64(6), s.GetDomainNotificationVersion()) + assert.Equal(t, map[string]int64{"key1": 1, "key2": 2}, s.GetClusterTransferAckLevel()) + assert.Equal(t, map[string]time.Time{"key1": now, "key2": now}, s.GetClusterTimerAckLevel()) + assert.Equal(t, "test_owner", s.GetOwner()) + assert.Equal(t, map[string]int64{"key1": 1, "key2": 2}, s.GetClusterReplicationLevel()) + assert.Equal(t, []byte{1, 2, 3}, s.GetPendingFailoverMarkers()) + assert.Equal(t, "test_encoding", s.GetPendingFailoverMarkersEncoding()) +} diff --git a/common/persistence/serialization/thrift_mapper.go b/common/persistence/serialization/thrift_mapper.go index d54ed646aae..c6e0c2f611e 100644 --- a/common/persistence/serialization/thrift_mapper.go +++ b/common/persistence/serialization/thrift_mapper.go @@ -320,6 +320,7 @@ func workflowExecutionInfoFromThrift(info *sqlblobs.WorkflowExecutionInfo) *Work VersionHistoriesEncoding: info.GetVersionHistoriesEncoding(), FirstExecutionRunID: info.FirstExecutionRunID, PartitionConfig: info.PartitionConfig, + IsCron: info.GetCronSchedule() != "", } } From 9ca0e368744c744e037f973dd7efc95722d7b023 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 20 Dec 2023 00:40:47 +0100 Subject: [PATCH 2/6] copyright and fmt --- .../serialization/domain_info_test.go | 23 +++++++++++++++++++ .../serialization/getters_fixtures_test.go | 22 ++++++++++++++++++ .../persistence/serialization/getters_test.go | 23 +++++++++++++++++++ .../persistence/serialization/helpers_test.go | 22 ++++++++++++++++++ .../serialization/history_tree_info_test.go | 22 ++++++++++++++++++ .../persistence/serialization/parser_test.go | 1 + .../persistence/serialization/shard_test.go | 22 ++++++++++++++++++ 7 files changed, 135 insertions(+) diff --git a/common/persistence/serialization/domain_info_test.go b/common/persistence/serialization/domain_info_test.go index 304e1781498..ca2a49a043d 100644 --- a/common/persistence/serialization/domain_info_test.go +++ b/common/persistence/serialization/domain_info_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 serialization import ( @@ -5,6 +27,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/uber/cadence/common" ) diff --git a/common/persistence/serialization/getters_fixtures_test.go b/common/persistence/serialization/getters_fixtures_test.go index c5b343f5501..e2b21bbbe99 100644 --- a/common/persistence/serialization/getters_fixtures_test.go +++ b/common/persistence/serialization/getters_fixtures_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 serialization import ( diff --git a/common/persistence/serialization/getters_test.go b/common/persistence/serialization/getters_test.go index c8d6360710f..a0f8ea80d99 100644 --- a/common/persistence/serialization/getters_test.go +++ b/common/persistence/serialization/getters_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 serialization import ( @@ -8,6 +30,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "github.com/uber/cadence/common" "github.com/uber/cadence/common/types" ) diff --git a/common/persistence/serialization/helpers_test.go b/common/persistence/serialization/helpers_test.go index 4701b4aab92..c58cc1d3442 100644 --- a/common/persistence/serialization/helpers_test.go +++ b/common/persistence/serialization/helpers_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 serialization func emptyMap[K comparable, V any]() map[K]V { diff --git a/common/persistence/serialization/history_tree_info_test.go b/common/persistence/serialization/history_tree_info_test.go index b06e5c89c06..536e21b89db 100644 --- a/common/persistence/serialization/history_tree_info_test.go +++ b/common/persistence/serialization/history_tree_info_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 serialization import ( diff --git a/common/persistence/serialization/parser_test.go b/common/persistence/serialization/parser_test.go index 443ce9cc197..a20421d149a 100644 --- a/common/persistence/serialization/parser_test.go +++ b/common/persistence/serialization/parser_test.go @@ -32,6 +32,7 @@ import ( fuzz "github.com/google/gofuzz" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/uber/cadence/common" "github.com/uber/cadence/common/persistence" ) diff --git a/common/persistence/serialization/shard_test.go b/common/persistence/serialization/shard_test.go index c6b1f68fb99..33ad2fb09ce 100644 --- a/common/persistence/serialization/shard_test.go +++ b/common/persistence/serialization/shard_test.go @@ -1,3 +1,25 @@ +// The MIT License (MIT) + +// Copyright (c) 2017-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 serialization import ( From 39afd35ee45a30654f44001cca2b4958961230a3 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 20 Dec 2023 00:47:35 +0100 Subject: [PATCH 3/6] remove unused --- .../serialization/domain_info_test.go | 118 ------------------ .../serialization/history_tree_info_test.go | 54 -------- .../persistence/serialization/shard_test.go | 90 ------------- go.mod | 5 +- go.sum | 1 + 5 files changed, 5 insertions(+), 263 deletions(-) delete mode 100644 common/persistence/serialization/domain_info_test.go delete mode 100644 common/persistence/serialization/history_tree_info_test.go delete mode 100644 common/persistence/serialization/shard_test.go diff --git a/common/persistence/serialization/domain_info_test.go b/common/persistence/serialization/domain_info_test.go deleted file mode 100644 index ca2a49a043d..00000000000 --- a/common/persistence/serialization/domain_info_test.go +++ /dev/null @@ -1,118 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2017-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 serialization - -import ( - "testing" - "time" - - "github.com/stretchr/testify/assert" - - "github.com/uber/cadence/common" -) - -func TestDomain_empty_struct(t *testing.T) { - var d *DomainInfo - - assert.Equal(t, "", d.GetName()) - assert.Equal(t, "", d.GetDescription()) - assert.Equal(t, "", d.GetOwner()) - assert.Equal(t, int32(0), d.GetStatus()) - assert.Equal(t, time.Duration(0), d.GetRetention()) - assert.Equal(t, false, d.GetEmitMetric()) - assert.Equal(t, "", d.GetArchivalBucket()) - assert.Equal(t, int16(0), d.GetArchivalStatus()) - assert.Equal(t, int64(0), d.GetConfigVersion()) - assert.Equal(t, int64(0), d.GetFailoverVersion()) - assert.Equal(t, int64(0), d.GetNotificationVersion()) - assert.Equal(t, int64(0), d.GetFailoverNotificationVersion()) - assert.Equal(t, int64(0), d.GetPreviousFailoverVersion()) - assert.Equal(t, "", d.GetActiveClusterName()) - assert.Equal(t, emptySlice[string](), d.GetClusters()) - assert.Equal(t, emptyMap[string, string](), d.GetData()) - assert.Equal(t, emptySlice[uint8](), d.GetBadBinaries()) - assert.Equal(t, "", d.GetBadBinariesEncoding()) - assert.Equal(t, int16(0), d.GetHistoryArchivalStatus()) - assert.Equal(t, "", d.GetHistoryArchivalURI()) - assert.Equal(t, int16(0), d.GetVisibilityArchivalStatus()) - assert.Equal(t, "", d.GetVisibilityArchivalURI()) - assert.Equal(t, time.Unix(0, 0), d.GetFailoverEndTimestamp()) - assert.Equal(t, time.Unix(0, 0), d.GetLastUpdatedTimestamp()) -} - -func TestDomain_non_empty(t *testing.T) { - now := time.Now() - - d := DomainInfo{ - Name: "test_name", - Description: "test_description", - Owner: "test_owner", - Status: 1, - Retention: 2, - EmitMetric: true, - ArchivalBucket: "test_bucket", - ArchivalStatus: 3, - ConfigVersion: 4, - NotificationVersion: 5, - FailoverNotificationVersion: 6, - FailoverVersion: 7, - ActiveClusterName: "test_cluster_name", - Clusters: []string{"cluster1", "cluster2"}, - Data: map[string]string{"key1": "val1", "key2": "val2"}, - BadBinaries: []byte{1, 2, 3}, - BadBinariesEncoding: "test_encoding", - HistoryArchivalStatus: 8, - HistoryArchivalURI: "test_archival_uri", - VisibilityArchivalStatus: 9, - VisibilityArchivalURI: "test_visibility_uri", - FailoverEndTimestamp: common.TimePtr(now), - PreviousFailoverVersion: 10, - LastUpdatedTimestamp: now.Add(-1 * time.Second), - IsolationGroups: []byte{1, 2, 3}, - IsolationGroupsEncoding: "test_isolation_encoding", - } - assert.Equal(t, d.Name, d.GetName()) - assert.Equal(t, d.Description, d.GetDescription()) - assert.Equal(t, d.Owner, d.GetOwner()) - assert.Equal(t, d.Status, d.GetStatus()) - assert.Equal(t, d.Retention, d.GetRetention()) - assert.Equal(t, d.EmitMetric, d.GetEmitMetric()) - assert.Equal(t, d.ArchivalBucket, d.GetArchivalBucket()) - assert.Equal(t, d.ArchivalStatus, d.GetArchivalStatus()) - assert.Equal(t, d.ConfigVersion, d.GetConfigVersion()) - assert.Equal(t, d.FailoverVersion, d.GetFailoverVersion()) - assert.Equal(t, d.NotificationVersion, d.GetNotificationVersion()) - assert.Equal(t, d.FailoverNotificationVersion, d.GetFailoverNotificationVersion()) - assert.Equal(t, d.PreviousFailoverVersion, d.GetPreviousFailoverVersion()) - assert.Equal(t, d.ActiveClusterName, d.GetActiveClusterName()) - assert.Equal(t, d.Clusters, d.GetClusters()) - assert.Equal(t, d.Data, d.GetData()) - assert.Equal(t, d.BadBinaries, d.GetBadBinaries()) - assert.Equal(t, d.BadBinariesEncoding, d.GetBadBinariesEncoding()) - assert.Equal(t, d.HistoryArchivalStatus, d.GetHistoryArchivalStatus()) - assert.Equal(t, d.HistoryArchivalURI, d.GetHistoryArchivalURI()) - assert.Equal(t, d.VisibilityArchivalStatus, d.GetVisibilityArchivalStatus()) - assert.Equal(t, d.VisibilityArchivalURI, d.GetVisibilityArchivalURI()) - assert.Equal(t, *d.FailoverEndTimestamp, d.GetFailoverEndTimestamp()) - assert.Equal(t, d.LastUpdatedTimestamp, d.GetLastUpdatedTimestamp()) -} diff --git a/common/persistence/serialization/history_tree_info_test.go b/common/persistence/serialization/history_tree_info_test.go deleted file mode 100644 index 536e21b89db..00000000000 --- a/common/persistence/serialization/history_tree_info_test.go +++ /dev/null @@ -1,54 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2017-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 serialization - -import ( - "testing" - "time" - - fuzz "github.com/google/gofuzz" - "github.com/stretchr/testify/assert" -) - -func TestHistoryTreeInfoEmpty(t *testing.T) { - // Create a nil HistoryTree - var nilInfo *HistoryTreeInfo - - // Use assertions to check the values - assert.Equal(t, time.Unix(0, 0), nilInfo.GetCreatedTimestamp(), "CreatedTimestamp should be zero time") - assert.Nil(t, nilInfo.GetAncestors(), "Ancestors should be nil") - assert.Empty(t, nilInfo.GetInfo(), "Info should be empty string") -} - -func TestHistoryTreeInfoFilled(t *testing.T) { - filledInfo := HistoryTreeInfo{} - - f := fuzz.New() - - f.Fuzz(&filledInfo) - - // Use assertions to check the values - assert.Equal(t, filledInfo.CreatedTimestamp, filledInfo.GetCreatedTimestamp(), "CreatedTimestamp should match") - assert.Equal(t, filledInfo.Ancestors, filledInfo.GetAncestors(), "Ancestors should match") - assert.Equal(t, filledInfo.Info, filledInfo.GetInfo(), "Info should match") -} diff --git a/common/persistence/serialization/shard_test.go b/common/persistence/serialization/shard_test.go deleted file mode 100644 index 33ad2fb09ce..00000000000 --- a/common/persistence/serialization/shard_test.go +++ /dev/null @@ -1,90 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2017-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 serialization - -import ( - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestShard_empty_struct(t *testing.T) { - var s *ShardInfo - assert.Equal(t, int32(0), s.GetStolenSinceRenew()) - assert.Equal(t, time.Unix(0, 0), s.GetUpdatedAt()) - assert.Equal(t, int64(0), s.GetReplicationAckLevel()) - assert.Equal(t, int64(0), s.GetTransferAckLevel()) - assert.Equal(t, time.Unix(0, 0), s.GetTimerAckLevel()) - assert.Equal(t, int64(0), s.GetDomainNotificationVersion()) - assert.Equal(t, emptyMap[string, int64](), s.GetClusterTransferAckLevel()) - assert.Equal(t, emptyMap[string, time.Time](), s.GetClusterTimerAckLevel()) - assert.Equal(t, "", s.GetOwner()) - assert.Equal(t, emptyMap[string, int64](), s.GetClusterReplicationLevel()) - assert.Equal(t, emptySlice[uint8](), s.GetPendingFailoverMarkers()) - assert.Equal(t, "", s.GetPendingFailoverMarkersEncoding()) - assert.Equal(t, emptyMap[string, int64](), s.GetReplicationDlqAckLevel()) - assert.Equal(t, emptySlice[uint8](), s.GetTransferProcessingQueueStates()) - assert.Equal(t, "", s.GetTransferProcessingQueueStatesEncoding()) - assert.Equal(t, emptySlice[uint8](), s.GetCrossClusterProcessingQueueStates()) - assert.Equal(t, "", s.GetCrossClusterProcessingQueueStatesEncoding()) - assert.Equal(t, emptySlice[uint8](), s.GetTimerProcessingQueueStates()) - assert.Equal(t, "", s.GetTimerProcessingQueueStatesEncoding()) -} - -func TestShard_non_empty(t *testing.T) { - now := time.Now() - s := ShardInfo{ - StolenSinceRenew: 1, - UpdatedAt: now, - ReplicationAckLevel: 3, - TransferAckLevel: 4, - TimerAckLevel: now.Add(time.Second), - DomainNotificationVersion: 6, - ClusterTransferAckLevel: map[string]int64{"key1": 1, "key2": 2}, - ClusterTimerAckLevel: map[string]time.Time{"key1": now, "key2": now}, - Owner: "test_owner", - ClusterReplicationLevel: map[string]int64{"key1": 1, "key2": 2}, - PendingFailoverMarkers: []byte{1, 2, 3}, - PendingFailoverMarkersEncoding: "test_encoding", - ReplicationDlqAckLevel: map[string]int64{"key1": 1, "key2": 2}, - TransferProcessingQueueStates: []byte{1, 2, 3}, - TransferProcessingQueueStatesEncoding: "test_encoding", - CrossClusterProcessingQueueStates: []byte{1, 2, 3}, - CrossClusterProcessingQueueStatesEncoding: "test_encoding", - TimerProcessingQueueStates: []byte{1, 2, 3}, - TimerProcessingQueueStatesEncoding: "test_encoding", - } - assert.Equal(t, int32(1), s.GetStolenSinceRenew()) - assert.Equal(t, now, s.GetUpdatedAt()) - assert.Equal(t, int64(3), s.GetReplicationAckLevel()) - assert.Equal(t, int64(4), s.GetTransferAckLevel()) - assert.Equal(t, now.Add(time.Second), s.GetTimerAckLevel()) - assert.Equal(t, int64(6), s.GetDomainNotificationVersion()) - assert.Equal(t, map[string]int64{"key1": 1, "key2": 2}, s.GetClusterTransferAckLevel()) - assert.Equal(t, map[string]time.Time{"key1": now, "key2": now}, s.GetClusterTimerAckLevel()) - assert.Equal(t, "test_owner", s.GetOwner()) - assert.Equal(t, map[string]int64{"key1": 1, "key2": 2}, s.GetClusterReplicationLevel()) - assert.Equal(t, []byte{1, 2, 3}, s.GetPendingFailoverMarkers()) - assert.Equal(t, "test_encoding", s.GetPendingFailoverMarkersEncoding()) -} diff --git a/go.mod b/go.mod index 59522e94618..3d80879f444 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,10 @@ require ( gopkg.in/yaml.v2 v2.3.0 ) -require github.com/google/go-cmp v0.5.8 +require ( + github.com/google/go-cmp v0.5.8 + github.com/google/gofuzz v1.0.0 +) require ( cloud.google.com/go v0.102.1 // indirect diff --git a/go.sum b/go.sum index f9c61a8ef4a..8ffef540e79 100644 --- a/go.sum +++ b/go.sum @@ -287,6 +287,7 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= From c813a0b6e3b7a169227c7135516a1518a8672dd0 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 20 Dec 2023 00:48:34 +0100 Subject: [PATCH 4/6] proper gofuzz version --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 3d80879f444..c06fbcf39c4 100644 --- a/go.mod +++ b/go.mod @@ -68,7 +68,7 @@ require ( require ( github.com/google/go-cmp v0.5.8 - github.com/google/gofuzz v1.0.0 + github.com/google/gofuzz v1.2.0 ) require ( diff --git a/go.sum b/go.sum index 8ffef540e79..1f542a3ac92 100644 --- a/go.sum +++ b/go.sum @@ -289,6 +289,8 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= From 34166adcb737cb0e0c19b0a9f588b1363ef76648 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 20 Dec 2023 00:50:28 +0100 Subject: [PATCH 5/6] delete unused --- .../persistence/serialization/helpers_test.go | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 common/persistence/serialization/helpers_test.go diff --git a/common/persistence/serialization/helpers_test.go b/common/persistence/serialization/helpers_test.go deleted file mode 100644 index c58cc1d3442..00000000000 --- a/common/persistence/serialization/helpers_test.go +++ /dev/null @@ -1,31 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2017-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 serialization - -func emptyMap[K comparable, V any]() map[K]V { - return map[K]V(nil) -} - -func emptySlice[K any]() []K { - return []K(nil) -} From 5a14b3aba334ee630773bd96084c9b913f077b08 Mon Sep 17 00:00:00 2001 From: Ilya Ozherelyev Date: Wed, 20 Dec 2023 01:06:27 +0100 Subject: [PATCH 6/6] separate nil and empty cases --- .../serialization/getters_fixtures_test.go | 38 +++++++++---------- .../persistence/serialization/getters_test.go | 18 ++++++++- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/common/persistence/serialization/getters_fixtures_test.go b/common/persistence/serialization/getters_fixtures_test.go index e2b21bbbe99..444b5dad824 100644 --- a/common/persistence/serialization/getters_fixtures_test.go +++ b/common/persistence/serialization/getters_fixtures_test.go @@ -273,12 +273,12 @@ var expectedEmpty = map[string]map[string]any{ "GetCompletionEventBatchID": int64(0), "GetCronSchedule": "", "GetDecisionAttempt": int64(0), - "GetDecisionOriginalScheduledTimestamp": zeroUnix, + "GetDecisionOriginalScheduledTimestamp": time.Time{}, "GetDecisionRequestID": "", "GetDecisionScheduleID": int64(0), - "GetDecisionScheduledTimestamp": zeroUnix, + "GetDecisionScheduledTimestamp": time.Time{}, "GetDecisionStartedID": int64(0), - "GetDecisionStartedTimestamp": zeroUnix, + "GetDecisionStartedTimestamp": time.Time{}, "GetDecisionTaskTimeout": time.Duration(0), "GetDecisionTimeout": time.Duration(0), "GetLastFirstEventID": int64(0), @@ -295,7 +295,7 @@ var expectedEmpty = map[string]map[string]any{ "GetInitiatedID": int64(0), "GetIsCron": false, "GetLastEventTaskID": int64(0), - "GetLastUpdatedTimestamp": zeroUnix, + "GetLastUpdatedTimestamp": time.Time{}, "GetLastWriteEventID": int64(0), "GetMemo": map[string][]uint8(nil), "GetParentDomainID": []uint8(nil), @@ -305,14 +305,14 @@ var expectedEmpty = map[string]map[string]any{ "GetRetryAttempt": int64(0), "GetRetryBackoffCoefficient": float64(0), "GetRetryExpiration": time.Duration(0), - "GetRetryExpirationTimestamp": zeroUnix, + "GetRetryExpirationTimestamp": time.Time{}, "GetRetryInitialInterval": time.Duration(0), "GetRetryMaximumAttempts": int32(0), "GetRetryMaximumInterval": time.Duration(0), "GetRetryNonRetryableErrors": []string(nil), "GetSearchAttributes": map[string][]uint8(nil), "GetSignalCount": int64(0), - "GetStartTimestamp": zeroUnix, + "GetStartTimestamp": time.Time{}, "GetState": int32(0), "GetStickyScheduleToStartTimeout": time.Duration(0), "GetStickyTaskList": "", @@ -333,7 +333,7 @@ var expectedEmpty = map[string]map[string]any{ }, "*serialization.ReplicationTaskInfo": { "GetBranchToken": []uint8(nil), - "GetCreationTimestamp": zeroUnix, + "GetCreationTimestamp": time.Time{}, "GetDomainID": []uint8(nil), "GetEventStoreVersion": int32(0), "GetFirstEventID": int64(0), @@ -348,20 +348,20 @@ var expectedEmpty = map[string]map[string]any{ }, "*serialization.TaskListInfo": { "GetAckLevel": int64(0), - "GetExpiryTimestamp": zeroUnix, + "GetExpiryTimestamp": time.Time{}, "GetKind": int16(0), - "GetLastUpdated": zeroUnix, + "GetLastUpdated": time.Time{}, }, "*serialization.TaskInfo": { - "GetCreatedTimestamp": zeroUnix, - "GetExpiryTimestamp": zeroUnix, + "GetCreatedTimestamp": time.Time{}, + "GetExpiryTimestamp": time.Time{}, "GetPartitionConfig": map[string]string(nil), "GetRunID": []uint8(nil), "GetScheduleID": int64(0), "GetWorkflowID": "", }, "*serialization.TimerInfo": { - "GetExpiryTimestamp": zeroUnix, + "GetExpiryTimestamp": time.Time{}, "GetStartedID": int64(0), "GetTaskID": int64(0), "GetVersion": int64(0), @@ -404,7 +404,7 @@ var expectedEmpty = map[string]map[string]any{ "GetHeartbeatTimeout": time.Duration(0), "GetRequestID": "", "GetRetryBackoffCoefficient": float64(0), - "GetRetryExpirationTimestamp": zeroUnix, + "GetRetryExpirationTimestamp": time.Time{}, "GetRetryInitialInterval": time.Duration(0), "GetRetryLastFailureDetails": []uint8(nil), "GetRetryLastFailureReason": "", @@ -417,20 +417,20 @@ var expectedEmpty = map[string]map[string]any{ "GetScheduledEvent": []uint8(nil), "GetScheduledEventBatchID": int64(0), "GetScheduledEventEncoding": "", - "GetScheduledTimestamp": zeroUnix, + "GetScheduledTimestamp": time.Time{}, "GetStartToCloseTimeout": time.Duration(0), "GetStartedEvent": []uint8(nil), "GetStartedEventEncoding": "", "GetStartedID": int64(0), "GetStartedIdentity": "", - "GetStartedTimestamp": zeroUnix, + "GetStartedTimestamp": time.Time{}, "GetTaskList": "", "GetTimerTaskStatus": int32(0), "GetVersion": int64(0), }, "*serialization.HistoryTreeInfo": { "GetAncestors": []*types.HistoryBranchRange(nil), - "GetCreatedTimestamp": zeroUnix, + "GetCreatedTimestamp": time.Time{}, "GetInfo": "", }, "*serialization.DomainInfo": { @@ -449,7 +449,7 @@ var expectedEmpty = map[string]map[string]any{ "GetFailoverVersion": int64(0), "GetHistoryArchivalStatus": int16(0), "GetHistoryArchivalURI": "", - "GetLastUpdatedTimestamp": zeroUnix, + "GetLastUpdatedTimestamp": time.Time{}, "GetName": "", "GetNotificationVersion": int64(0), "GetOwner": "", @@ -472,13 +472,13 @@ var expectedEmpty = map[string]map[string]any{ "GetReplicationAckLevel": int64(0), "GetReplicationDlqAckLevel": map[string]int64(nil), "GetStolenSinceRenew": int32(0), - "GetTimerAckLevel": zeroUnix, + "GetTimerAckLevel": time.Time{}, "GetTimerProcessingQueueStates": []uint8(nil), "GetTimerProcessingQueueStatesEncoding": "", "GetTransferAckLevel": int64(0), "GetTransferProcessingQueueStates": []uint8(nil), "GetTransferProcessingQueueStatesEncoding": "", - "GetUpdatedAt": zeroUnix, + "GetUpdatedAt": time.Time{}, }, } diff --git a/common/persistence/serialization/getters_test.go b/common/persistence/serialization/getters_test.go index a0f8ea80d99..74297fcd399 100644 --- a/common/persistence/serialization/getters_test.go +++ b/common/persistence/serialization/getters_test.go @@ -53,7 +53,7 @@ func TestGettersForAllNilInfos(t *testing.T) { } { name := reflect.TypeOf(info).String() t.Run(name, func(t *testing.T) { - res := emptyView(info) + res := nilView(info) if diff := cmp.Diff(expectedNil[name], res); diff != "" { t.Errorf("nilValue mismatch (-want +got):\n%s", diff) } @@ -336,7 +336,7 @@ func TestGettersForInfos(t *testing.T) { } } -func emptyView(info any) map[string]any { +func nilView(info any) map[string]any { infoVal := reflect.ValueOf(info) infoT := reflect.TypeOf(infoVal.Interface()) v := reflect.Zero(infoT) @@ -351,6 +351,20 @@ func emptyView(info any) map[string]any { return res } +func emptyView(info any) map[string]any { + infoVal := reflect.ValueOf(info) + infoT := reflect.TypeOf(infoVal.Interface()) + res := make(map[string]any) + for i := 0; i < infoT.NumMethod(); i++ { + method := infoT.Method(i) + if strings.HasPrefix(method.Name, "Get") { + res[method.Name] = infoVal.MethodByName(method.Name).Call(nil)[0].Interface() + } + } + + return res +} + func infoView(info any) map[string]any { v := reflect.ValueOf(info) infoT := reflect.TypeOf(v.Interface())