Skip to content

Commit

Permalink
Merge branch 'master' into refactor/adding-mutable-state-builder-tests-i
Browse files Browse the repository at this point in the history
  • Loading branch information
davidporter-id-au committed Mar 7, 2024
2 parents addd9da + 65b45aa commit fe62c70
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions common/persistence/data_manager_interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,112 @@ func TestOnlyGetTypeTask(t *testing.T) {
}
}
}

func TestTransferTaskInfo(t *testing.T) {
timeNow := time.Now()
task := &TransferTaskInfo{
DomainID: "test-domain-id",
WorkflowID: "test-workflow-id",
RunID: "test-run-id",
TargetDomainIDs: map[string]struct{}{"test-target-domain-id": {}},
TaskType: TransferTaskTypeActivityTask,
TaskID: 1,
ScheduleID: 1,
Version: 1,
VisibilityTimestamp: timeNow,
}
expectedString := fmt.Sprintf("%#v", task)

assert.Equal(t, "test-domain-id", task.GetDomainID())
assert.Equal(t, "test-workflow-id", task.GetWorkflowID())
assert.Equal(t, "test-run-id", task.GetRunID())
assert.Equal(t, TransferTaskTypeActivityTask, task.GetTaskType())
assert.Equal(t, int64(1), task.GetTaskID())
assert.Equal(t, int64(1), task.GetVersion())
assert.Equal(t, timeNow, task.GetVisibilityTimestamp())
assert.Equal(t, map[string]struct{}{"test-target-domain-id": {}}, task.GetTargetDomainIDs())
assert.Equal(t, expectedString, task.String())
}

func TestReplicationTaskInfo(t *testing.T) {
task := &ReplicationTaskInfo{
DomainID: "test-domain-id",
WorkflowID: "test-workflow-id",
RunID: "test-run-id",
TaskType: ReplicationTaskTypeHistory,
TaskID: 1,
Version: 1,
FirstEventID: 1,
NextEventID: 2,
ScheduledID: 3,
}
assert.Equal(t, "test-domain-id", task.GetDomainID())
assert.Equal(t, "test-workflow-id", task.GetWorkflowID())
assert.Equal(t, "test-run-id", task.GetRunID())
assert.Equal(t, ReplicationTaskTypeHistory, task.GetTaskType())
assert.Equal(t, int64(1), task.GetTaskID())
assert.Equal(t, int64(1), task.GetVersion())
assert.Equal(t, time.Time{}, task.GetVisibilityTimestamp())
}

func TestTimeTaskInfo(t *testing.T) {
timeNow := time.Now()
task := &TimerTaskInfo{
VisibilityTimestamp: timeNow,
TaskType: 4,
TaskID: 3,
Version: 2,
RunID: "test-run-id",
DomainID: "test-domain-id",
WorkflowID: "test-workflow-id",
}
expectedString := fmt.Sprintf(
"{DomainID: %v, WorkflowID: %v, RunID: %v, VisibilityTimestamp: %v, TaskID: %v, TaskType: %v, TimeoutType: %v, EventID: %v, ScheduleAttempt: %v, Version: %v.}",
task.DomainID, task.WorkflowID, task.RunID, task.VisibilityTimestamp, task.TaskID, task.TaskType, task.TimeoutType, task.EventID, task.ScheduleAttempt, task.Version,
)
assert.Equal(t, 4, task.GetTaskType())
assert.Equal(t, int64(3), task.GetTaskID())
assert.Equal(t, int64(2), task.GetVersion())
assert.Equal(t, timeNow, task.GetVisibilityTimestamp())
assert.Equal(t, "test-run-id", task.GetRunID())
assert.Equal(t, "test-domain-id", task.GetDomainID())
assert.Equal(t, "test-workflow-id", task.GetWorkflowID())
assert.Equal(t, expectedString, task.String())
}

func TestShardInfoCopy(t *testing.T) {
info := &ShardInfo{
ShardID: 1,
RangeID: 2,
ClusterTransferAckLevel: map[string]int64{"test-cluster": 3},
ClusterTimerAckLevel: map[string]time.Time{"test-cluster": time.Now()},
ClusterReplicationLevel: map[string]int64{"test-cluster": 4},
ReplicationDLQAckLevel: map[string]int64{"test-cluster": 5},
}

infoCopy := info.Copy()
assert.Equal(t, info, infoCopy)
}

func TestSerializeAndDeserializeClusterConfigs(t *testing.T) {
configs := []*ClusterReplicationConfig{
{
ClusterName: "test-cluster1",
},
{
ClusterName: "test-cluster2",
},
}
serializedResult := SerializeClusterConfigs(configs)
deserializedResult := DeserializeClusterConfigs(serializedResult)

assert.Equal(t, configs, deserializedResult)

}

func TestTimeStampConvertion(t *testing.T) {
timeNow := time.Now()
milisSecond := UnixNanoToDBTimestamp(timeNow.UnixNano())
unixNanoTime := DBTimestampToUnixNano(milisSecond)
assert.Equal(t, timeNow.UnixNano()/(1000*1000), unixNanoTime/(1000*1000)) // unixNano to milisSecond will result in info loss
}

0 comments on commit fe62c70

Please sign in to comment.