2021-01-19 03:37:16 +00:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"go.etcd.io/etcd/clientv3"
|
|
|
|
|
2021-01-22 11:36:09 +00:00
|
|
|
etcdkv "github.com/zilliztech/milvus-distributed/internal/kv/etcd"
|
2021-01-19 03:37:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func makeNewChannelNames(names []string, suffix string) []string {
|
|
|
|
var ret []string
|
|
|
|
for _, name := range names {
|
|
|
|
ret = append(ret, name+suffix)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func refreshChannelNames() {
|
2021-01-24 13:20:11 +00:00
|
|
|
Params.DDChannelNames = []string{"datanode-test"}
|
|
|
|
Params.SegmentStatisticsChannelName = "segtment-statistics"
|
|
|
|
Params.CompleteFlushChannelName = "flush-completed"
|
2021-01-26 06:46:54 +00:00
|
|
|
Params.InsertChannelNames = []string{"intsert-a-1", "insert-b-1"}
|
2021-01-24 13:20:11 +00:00
|
|
|
Params.TimeTickChannelName = "hard-timetick"
|
2021-01-19 03:37:16 +00:00
|
|
|
suffix := "-test-data-node" + strconv.FormatInt(rand.Int63n(100), 10)
|
|
|
|
Params.DDChannelNames = makeNewChannelNames(Params.DDChannelNames, suffix)
|
|
|
|
Params.InsertChannelNames = makeNewChannelNames(Params.InsertChannelNames, suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
Params.Init()
|
2021-01-22 11:36:09 +00:00
|
|
|
|
2021-01-19 03:37:16 +00:00
|
|
|
refreshChannelNames()
|
|
|
|
exitCode := m.Run()
|
|
|
|
os.Exit(exitCode)
|
|
|
|
}
|
|
|
|
|
2021-01-22 11:36:09 +00:00
|
|
|
func newMetaTable() *metaTable {
|
|
|
|
etcdClient, _ := clientv3.New(clientv3.Config{Endpoints: []string{Params.EtcdAddress}})
|
|
|
|
|
|
|
|
etcdKV := etcdkv.NewEtcdKV(etcdClient, Params.MetaRootPath)
|
|
|
|
mt, _ := NewMetaTable(etcdKV)
|
|
|
|
return mt
|
2021-01-19 03:37:16 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 11:36:09 +00:00
|
|
|
func clearEtcd(rootPath string) error {
|
|
|
|
etcdAddr := Params.EtcdAddress
|
|
|
|
etcdClient, err := clientv3.New(clientv3.Config{Endpoints: []string{etcdAddr}})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-21 01:55:25 +00:00
|
|
|
}
|
2021-01-22 11:36:09 +00:00
|
|
|
etcdKV := etcdkv.NewEtcdKV(etcdClient, rootPath)
|
2021-01-21 01:55:25 +00:00
|
|
|
|
2021-01-22 11:36:09 +00:00
|
|
|
err = etcdKV.RemoveWithPrefix("writer/segment")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-21 01:55:25 +00:00
|
|
|
}
|
2021-01-22 11:36:09 +00:00
|
|
|
_, _, err = etcdKV.LoadWithPrefix("writer/segment")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-21 01:55:25 +00:00
|
|
|
}
|
2021-01-22 11:36:09 +00:00
|
|
|
log.Println("Clear ETCD with prefix writer/segment ")
|
2021-01-21 01:55:25 +00:00
|
|
|
|
2021-01-22 11:36:09 +00:00
|
|
|
err = etcdKV.RemoveWithPrefix("writer/ddl")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-21 01:55:25 +00:00
|
|
|
}
|
2021-01-22 11:36:09 +00:00
|
|
|
_, _, err = etcdKV.LoadWithPrefix("writer/ddl")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-21 01:55:25 +00:00
|
|
|
}
|
2021-01-22 11:36:09 +00:00
|
|
|
log.Println("Clear ETCD with prefix writer/ddl")
|
|
|
|
return nil
|
2021-01-21 01:55:25 +00:00
|
|
|
|
|
|
|
}
|