Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
refactor: refactor by cr
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuLiangWang committed Jul 4, 2023
1 parent 8980f4b commit 8c41835
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,50 @@ func TestBatchProcedure(t *testing.T) {

// Procedures with same type and version.
for i := 0; i < 3; i++ {
procedures = createMockProcedure(i, 0, 0, 0, procedures)
shardWithVersion := map[storage.ShardID]uint64{}
shardWithVersion[storage.ShardID(i)] = 0
p := CreateMockProcedure(storage.ClusterID(0), 0, 0, shardWithVersion)
procedures = append(procedures, p)
}
_, err := transferleader.NewBatchTransferLeaderProcedure(0, procedures)
re.NoError(err)

// Procedure with different clusterID
for i := 0; i < 3; i++ {
createMockProcedure(i, uint64(i), 0, procedure.TransferLeader, procedures)
shardWithVersion := map[storage.ShardID]uint64{}
shardWithVersion[storage.ShardID(i)] = 0
p := CreateMockProcedure(storage.ClusterID(i), 0, procedure.TransferLeader, shardWithVersion)
procedures = append(procedures, p)
}
_, err = transferleader.NewBatchTransferLeaderProcedure(0, procedures)
re.Error(err)

// Procedures with different type.
for i := 0; i < 3; i++ {
createMockProcedure(i, 0, 0, procedure.Typ(i), procedures)
shardWithVersion := map[storage.ShardID]uint64{}
shardWithVersion[storage.ShardID(i)] = 0
p := CreateMockProcedure(0, 0, procedure.Typ(i), shardWithVersion)
procedures = append(procedures, p)
}
_, err = transferleader.NewBatchTransferLeaderProcedure(0, procedures)
re.Error(err)

// Procedures with different version.
for i := 0; i < 3; i++ {
createMockProcedure(0, 0, 0, procedure.Typ(i), procedures)
shardWithVersion := map[storage.ShardID]uint64{}
shardWithVersion[storage.ShardID(0)] = uint64(i)
p := CreateMockProcedure(0, 0, procedure.Typ(i), shardWithVersion)
procedures = append(procedures, p)
}
_, err = transferleader.NewBatchTransferLeaderProcedure(0, procedures)
re.Error(err)
}

func createMockProcedure(shardID int, clusterID uint64, clusterVersion uint64, typ procedure.Typ, procedures []procedure.Procedure) []procedure.Procedure {
shardWithVersion := map[storage.ShardID]uint64{}
shardWithVersion[storage.ShardID(shardID)] = 0
p := mockProcedure{
ClusterID: storage.ClusterID(clusterID),
func CreateMockProcedure(clusterID storage.ClusterID, clusterVersion uint64, typ procedure.Typ, shardWithVersion map[storage.ShardID]uint64) procedure.Procedure {
return mockProcedure{
ClusterID: clusterID,
clusterVersion: clusterVersion,
typ: typ,
ShardWithVersion: shardWithVersion,
}
procedures = append(procedures, p)
return procedures
}

0 comments on commit 8c41835

Please sign in to comment.