cubefs

Форк
0
/
task_pool_test.go 
71 строка · 1.8 Кб
1
// Copyright 2022 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 blobstore
16

17
import (
18
	"math/rand"
19
	"sync"
20
	"testing"
21
	"time"
22

23
	"github.com/cubefs/cubefs/proto"
24
	"github.com/stretchr/testify/assert"
25
)
26

27
func TestNew(t *testing.T) {
28
	objEks := make([]proto.ObjExtentKey, 0)
29
	eks := make([]proto.ExtentKey, 0)
30
	objEkLen := rand.Intn(20)
31
	expectedFileSize := 0
32
	for i := 0; i < objEkLen; i++ {
33
		size := rand.Intn(1000)
34
		objEks = append(objEks, proto.ObjExtentKey{Size: uint64(size), FileOffset: uint64(expectedFileSize)})
35
		eks = append(eks, proto.ExtentKey{FileOffset: uint64(expectedFileSize), Size: uint32(size)})
36
		expectedFileSize += size
37
	}
38

39
	rSlices := make([]rwSlice, 0)
40
	for i := 0; i < objEkLen; i++ {
41
		rSlices = append(rSlices, rwSlice{
42
			index:        0,
43
			fileOffset:   0,
44
			size:         uint32(expectedFileSize),
45
			rOffset:      0,
46
			rSize:        0,
47
			read:         0,
48
			Data:         nil,
49
			extentKey:    eks[i],
50
			objExtentKey: objEks[i],
51
		})
52
	}
53

54
	sliceSize := len(rSlices)
55

56
	assert.Equal(t, int(sliceSize), int(objEkLen))
57

58
	var wg sync.WaitGroup
59
	pool := New(3, sliceSize)
60
	wg.Add(sliceSize)
61
	for _, rs := range rSlices {
62
		// rs_ := rs
63
		pool.Execute(&rs, func(param *rwSlice) {
64
			// syslog.Printf("pool.Execute rs = %v", rs_)
65
			time.Sleep(1 * time.Second)
66
			wg.Done()
67
		})
68
	}
69
	wg.Wait()
70
	pool.Close()
71
}
72

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

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

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

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