cubefs

Форк
0
/
data_partition_test.go 
76 строк · 1.8 Кб
1
// Copyright 2020 The CubeFS Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package wrapper
16

17
import (
18
	"fmt"
19
	"math/rand"
20
	"testing"
21
	"time"
22
)
23

24
func TestKmin(t *testing.T) {
25
	partitions := make([]*DataPartition, 0)
26

27
	rand.Seed(time.Now().UnixNano())
28
	length := rand.Intn(100) + 2
29

30
	for i := 0; i < length; i++ {
31
		rand.Seed(time.Now().UnixNano())
32
		i := rand.Int63n(100)
33

34
		dp := new(DataPartition)
35
		dp.Metrics = new(DataPartitionMetrics)
36
		dp.Metrics.AvgWriteLatencyNano = i
37
		partitions = append(partitions, dp)
38
	}
39
	fmt.Printf("%-20s", "origin partitions:")
40
	for _, v := range partitions {
41
		fmt.Printf("%v ", v.GetAvgWrite())
42
	}
43
	fmt.Println()
44

45
	kth := selectKminDataPartition(partitions, (length-1)*80/100+1)
46

47
	kmin := partitions[kth].GetAvgWrite()
48

49
	fmt.Printf("%-20s%v/%v", "kth of length:", kth, length)
50
	fmt.Println()
51

52
	fmt.Printf("%-20s%v", "kmin:", kmin)
53
	fmt.Println()
54

55
	fmt.Printf("%-20s", "faster partitions:")
56
	for _, v := range partitions[:kth] {
57
		if v.GetAvgWrite() > kmin {
58
			fmt.Println()
59
			fmt.Println("select error!")
60
			t.Fail()
61
		}
62
		fmt.Printf("%v ", v.GetAvgWrite())
63
	}
64
	fmt.Println()
65

66
	fmt.Printf("%-20s", "slower partitions:")
67
	for _, v := range partitions[kth:] {
68
		fmt.Printf("%v ", v.GetAvgWrite())
69
		if v.GetAvgWrite() < kmin {
70
			fmt.Println()
71
			fmt.Println("select error!")
72
			t.Fail()
73
		}
74
	}
75
	fmt.Println()
76
}
77

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.