milvus/internal/datacoord/segment_allocation_policy_test.go
sunby 6e34f4c7f1
Add a seal policy which restrict the lifetime of a segment (#7172)
issue: #7164
Signed-off-by: sunby <bingyi.sun@zilliz.com>
2021-08-20 15:42:12 +08:00

36 lines
913 B
Go

package datacoord
import (
"testing"
"time"
"github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/util/tsoutil"
"github.com/stretchr/testify/assert"
)
func TestSealSegmentPolicy(t *testing.T) {
t.Run("test seal segment by lifetime", func(t *testing.T) {
lifetime := 2 * time.Second
now := time.Now()
curTS := now.UnixNano() / int64(time.Millisecond)
nosealTs := (now.Add(lifetime / 2)).UnixNano() / int64(time.Millisecond)
sealTs := (now.Add(lifetime)).UnixNano() / int64(time.Millisecond)
p := sealByLifetimePolicy(lifetime)
segment := &SegmentInfo{
SegmentInfo: &datapb.SegmentInfo{
ID: 1,
LastExpireTime: tsoutil.ComposeTS(curTS, 0),
},
}
shouldSeal := p(segment, tsoutil.ComposeTS(nosealTs, 0))
assert.False(t, shouldSeal)
shouldSeal = p(segment, tsoutil.ComposeTS(sealTs, 0))
assert.True(t, shouldSeal)
})
}