You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

strategy_test.go 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package test
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/entity"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/service/collector"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/strategy"
  7. "testing"
  8. )
  9. func TestReplication(t *testing.T) {
  10. parts := []entity.Participant{
  11. {Name: "test1", Participant_id: 1},
  12. {Name: "test2", Participant_id: 2},
  13. {Name: "test3", Participant_id: 3},
  14. }
  15. rsc := []*collector.ResourceStats{
  16. {
  17. ClusterId: "1",
  18. Name: "test1",
  19. },
  20. {
  21. ClusterId: "2",
  22. Name: "test2"},
  23. {
  24. ClusterId: "3",
  25. Name: "test3"},
  26. }
  27. tests := []struct {
  28. name string
  29. replica int32
  30. ps []entity.Participant
  31. res []*collector.ResourceStats
  32. }{
  33. {
  34. name: "test1",
  35. replica: 1,
  36. ps: parts,
  37. },
  38. {
  39. name: "test2",
  40. replica: 2,
  41. ps: parts,
  42. },
  43. }
  44. for _, tt := range tests {
  45. t.Run(tt.name, func(t *testing.T) {
  46. var clusterIds []string
  47. for _, stats := range rsc {
  48. clusterIds = append(clusterIds, stats.ClusterId)
  49. }
  50. repl := strategy.NewReplicationStrategy(clusterIds, 0)
  51. schedule, err := repl.Schedule()
  52. if err != nil {
  53. return
  54. }
  55. for _, cluster := range schedule {
  56. fmt.Println(cluster)
  57. }
  58. })
  59. }
  60. }
  61. func TestStaticWeight(t *testing.T) {
  62. parts := map[string]int32{
  63. "test1": 6,
  64. "test2": 5,
  65. "test3": 2,
  66. }
  67. tests := []struct {
  68. name string
  69. replica int32
  70. ps map[string]int32
  71. }{
  72. {
  73. name: "test1",
  74. replica: 1,
  75. ps: parts,
  76. },
  77. {
  78. name: "test2",
  79. replica: 5,
  80. ps: parts,
  81. },
  82. {
  83. name: "test2",
  84. replica: 6,
  85. ps: parts,
  86. },
  87. }
  88. for _, tt := range tests {
  89. t.Run(tt.name, func(t *testing.T) {
  90. repl := strategy.NewStaticWeightStrategy(tt.ps, tt.replica)
  91. schedule, err := repl.Schedule()
  92. if err != nil {
  93. return
  94. }
  95. for _, cluster := range schedule {
  96. fmt.Println(cluster)
  97. }
  98. })
  99. }
  100. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.