package test

import (
	"fmt"
	"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/entity"
	"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/service/collector"
	"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/strategy"
	"testing"
)

func TestReplication(t *testing.T) {
	parts := []entity.Participant{
		{Name: "test1", Participant_id: 1},
		{Name: "test2", Participant_id: 2},
		{Name: "test3", Participant_id: 3},
	}
	rsc := []*collector.ResourceStats{
		{
			ClusterId: "1",
			Name:      "test1",
		},
		{
			ClusterId: "2",
			Name:      "test2"},
		{
			ClusterId: "3",
			Name:      "test3"},
	}
	tests := []struct {
		name    string
		replica int32
		ps      []entity.Participant
		res     []*collector.ResourceStats
	}{
		{
			name:    "test1",
			replica: 1,
			ps:      parts,
		},
		{
			name:    "test2",
			replica: 2,
			ps:      parts,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			var clusterIds []string
			for _, stats := range rsc {
				clusterIds = append(clusterIds, stats.ClusterId)
			}
			repl := strategy.NewReplicationStrategy(clusterIds, 0)
			schedule, err := repl.Schedule()
			if err != nil {
				return
			}
			for _, cluster := range schedule {
				fmt.Println(cluster)
			}

		})
	}

}

func TestStaticWeight(t *testing.T) {
	parts := map[string]int32{
		"test1": 6,
		"test2": 5,
		"test3": 2,
	}
	tests := []struct {
		name    string
		replica int32
		ps      map[string]int32
	}{
		{
			name:    "test1",
			replica: 1,
			ps:      parts,
		},
		{
			name:    "test2",
			replica: 5,
			ps:      parts,
		},
		{
			name:    "test2",
			replica: 6,
			ps:      parts,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			repl := strategy.NewStaticWeightStrategy(tt.ps, tt.replica)
			schedule, err := repl.Schedule()
			if err != nil {
				return
			}
			for _, cluster := range schedule {
				fmt.Println(cluster)
			}

		})
	}
}
