1
// Copyright 2022 The CubeFS Authors.
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
23
"github.com/cubefs/cubefs/proto"
24
"github.com/stretchr/testify/assert"
27
func TestNew(t *testing.T) {
28
objEks := make([]proto.ObjExtentKey, 0)
29
eks := make([]proto.ExtentKey, 0)
30
objEkLen := rand.Intn(20)
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
39
rSlices := make([]rwSlice, 0)
40
for i := 0; i < objEkLen; i++ {
41
rSlices = append(rSlices, rwSlice{
44
size: uint32(expectedFileSize),
50
objExtentKey: objEks[i],
54
sliceSize := len(rSlices)
56
assert.Equal(t, int(sliceSize), int(objEkLen))
59
pool := New(3, sliceSize)
61
for _, rs := range rSlices {
63
pool.Execute(&rs, func(param *rwSlice) {
64
// syslog.Printf("pool.Execute rs = %v", rs_)
65
time.Sleep(1 * time.Second)