mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
007e7ea858
Signed-off-by: zhenshan.cao <zhenshan.cao@zilliz.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package allocator
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/funcutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/zilliztech/milvus-distributed/internal/util/tsoutil"
|
|
)
|
|
|
|
var gTestIDAllocator *GlobalIDAllocator
|
|
|
|
func TestGlobalTSOAllocator_All(t *testing.T) {
|
|
etcdAddress := os.Getenv("ETCD_ADDRESS")
|
|
if etcdAddress == "" {
|
|
ip := funcutil.GetLocalIP()
|
|
etcdAddress = ip + ":2379"
|
|
}
|
|
gTestIDAllocator = NewGlobalIDAllocator("idTimestamp", tsoutil.NewTSOKVBase([]string{etcdAddress}, "/test/root/kv", "gidTest"))
|
|
|
|
t.Run("Initialize", func(t *testing.T) {
|
|
err := gTestIDAllocator.Initialize()
|
|
assert.Nil(t, err)
|
|
})
|
|
|
|
t.Run("AllocOne", func(t *testing.T) {
|
|
one, err := gTestIDAllocator.AllocOne()
|
|
assert.Nil(t, err)
|
|
ano, err := gTestIDAllocator.AllocOne()
|
|
assert.Nil(t, err)
|
|
assert.NotEqual(t, one, ano)
|
|
})
|
|
|
|
t.Run("Alloc", func(t *testing.T) {
|
|
count := uint32(2 << 10)
|
|
idStart, idEnd, err := gTestIDAllocator.Alloc(count)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, count, uint32(idEnd-idStart))
|
|
})
|
|
|
|
}
|