milvus/internal/master/global_allocator_test.go
zhenshan.cao 65ce1f97e7 Fix bug: pulsar dirty msg
Signed-off-by: zhenshan.cao <zhenshan.cao@zilliz.com>
2020-12-07 19:41:39 +08:00

73 lines
1.8 KiB
Go

package master
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/zilliztech/milvus-distributed/internal/util/tsoutil"
)
var gTestTsoAllocator Allocator
var gTestIDAllocator *GlobalIDAllocator
func TestGlobalTSOAllocator_Initialize(t *testing.T) {
err := gTestTsoAllocator.Initialize()
assert.Nil(t, err)
}
func TestGlobalTSOAllocator_GenerateTSO(t *testing.T) {
count := 1000
perCount := uint32(100)
startTs, err := gTestTsoAllocator.GenerateTSO(perCount)
assert.Nil(t, err)
lastPhysical, lastLogical := tsoutil.ParseTS(startTs)
for i := 0; i < count; i++ {
ts, _ := gTestTsoAllocator.GenerateTSO(perCount)
physical, logical := tsoutil.ParseTS(ts)
if lastPhysical.Equal(physical) {
diff := logical - lastLogical
assert.Equal(t, uint64(perCount), diff)
}
lastPhysical, lastLogical = physical, logical
}
}
func TestGlobalTSOAllocator_SetTSO(t *testing.T) {
curTime := time.Now()
nextTime := curTime.Add(2 * time.Second)
physical := nextTime.UnixNano() / int64(time.Millisecond)
logical := int64(0)
err := gTestTsoAllocator.SetTSO(tsoutil.ComposeTS(physical, logical))
assert.Nil(t, err)
}
func TestGlobalTSOAllocator_UpdateTSO(t *testing.T) {
err := gTestTsoAllocator.UpdateTSO()
assert.Nil(t, err)
}
func TestGlobalTSOAllocator_Reset(t *testing.T) {
gTestTsoAllocator.Reset()
}
func TestGlobalIdAllocator_Initialize(t *testing.T) {
err := gTestIDAllocator.Initialize()
assert.Nil(t, err)
}
func TestGlobalIdAllocator_AllocOne(t *testing.T) {
one, err := gTestIDAllocator.AllocOne()
assert.Nil(t, err)
ano, err := gTestIDAllocator.AllocOne()
assert.Nil(t, err)
assert.NotEqual(t, one, ano)
}
func TestGlobalIdAllocator_Alloc(t *testing.T) {
count := uint32(2 << 10)
idStart, idEnd, err := gTestIDAllocator.Alloc(count)
assert.Nil(t, err)
assert.Equal(t, count, uint32(idEnd-idStart))
}