result_test.go 3.4 KB
Newer Older
Z
zhenshan.cao 已提交
1 2 3
package reader

import (
4
	"context"
5 6
	"github.com/zilliztech/milvus-distributed/internal/conf"
	"github.com/zilliztech/milvus-distributed/internal/msgclient"
7
	"strconv"
8
	"testing"
9
	"time"
10

11 12
	masterPb "github.com/zilliztech/milvus-distributed/internal/proto/master"
	msgPb "github.com/zilliztech/milvus-distributed/internal/proto/message"
Z
zhenshan.cao 已提交
13 14
)

15
// NOTE: start pulsar before test
Z
zhenshan.cao 已提交
16
func TestResult_PublishSearchResult(t *testing.T) {
17 18 19 20 21 22 23 24 25 26 27 28 29 30
	conf.LoadConfig("config.yaml")

	d := time.Now().Add(ctxTimeInMillisecond * time.Millisecond)
	ctx, _ := context.WithDeadline(context.Background(), d)

	mc := msgclient.ReaderMessageClient{}
	pulsarAddr := "pulsar://"
	pulsarAddr += conf.Config.Pulsar.Address
	pulsarAddr += ":"
	pulsarAddr += strconv.FormatInt(int64(conf.Config.Pulsar.Port), 10)
	mc.InitClient(ctx, pulsarAddr)

	node := CreateQueryNode(ctx, 0, 0, &mc)

Z
zhenshan.cao 已提交
31
	// Construct node, collection, partition and segment
32
	var collection = node.NewCollection(0, "collection0", "")
Z
zhenshan.cao 已提交
33 34 35 36 37
	var partition = collection.NewPartition("partition0")
	var segment = partition.NewSegment(0)
	node.SegmentsMap[0] = segment

	const N = 10
38
	var entityIDs = msgPb.Entities{
Z
zhenshan.cao 已提交
39 40
		Ids: make([]int64, N),
	}
41 42
	var result = msgPb.QueryResult{
		Entities:  &entityIDs,
Z
zhenshan.cao 已提交
43 44 45
		Distances: make([]float32, N),
	}
	for i := 0; i < N; i++ {
46 47
		result.Entities.Ids = append(result.Entities.Ids, int64(i))
		result.Distances = append(result.Distances, float32(i))
Z
zhenshan.cao 已提交
48
	}
49
	node.PublishSearchResult(&result)
50
	node.Close()
51 52
}

53
// NOTE: start pulsar before test
54
func TestResult_PublishFailedSearchResult(t *testing.T) {
55 56 57 58 59 60 61 62 63 64 65 66 67 68
	conf.LoadConfig("config.yaml")

	d := time.Now().Add(ctxTimeInMillisecond * time.Millisecond)
	ctx, _ := context.WithDeadline(context.Background(), d)

	mc := msgclient.ReaderMessageClient{}
	pulsarAddr := "pulsar://"
	pulsarAddr += conf.Config.Pulsar.Address
	pulsarAddr += ":"
	pulsarAddr += strconv.FormatInt(int64(conf.Config.Pulsar.Port), 10)
	mc.InitClient(ctx, pulsarAddr)

	node := CreateQueryNode(ctx, 0, 0, &mc)

69
	// Construct node, collection, partition and segment
70
	var collection = node.NewCollection(0, "collection0", "")
71 72 73 74 75 76
	var partition = collection.NewPartition("partition0")
	var segment = partition.NewSegment(0)
	node.SegmentsMap[0] = segment

	// TODO: start pulsar server
	node.PublishFailedSearchResult()
77 78

	node.Close()
79 80
}

81
// NOTE: start pulsar before test
82
func TestResult_PublicStatistic(t *testing.T) {
83 84 85 86 87 88 89 90 91 92 93 94 95 96
	conf.LoadConfig("config.yaml")

	d := time.Now().Add(ctxTimeInMillisecond * time.Millisecond)
	ctx, _ := context.WithDeadline(context.Background(), d)

	mc := msgclient.ReaderMessageClient{}
	pulsarAddr := "pulsar://"
	pulsarAddr += conf.Config.Pulsar.Address
	pulsarAddr += ":"
	pulsarAddr += strconv.FormatInt(int64(conf.Config.Pulsar.Port), 10)
	mc.InitClient(ctx, pulsarAddr)

	node := CreateQueryNode(ctx, 0, 0, &mc)

97
	// Construct node, collection, partition and segment
98
	var collection = node.NewCollection(0, "collection0", "")
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	var partition = collection.NewPartition("partition0")
	var segment = partition.NewSegment(0)
	node.SegmentsMap[0] = segment

	var statisticData = make([]masterPb.SegmentStat, 0)

	for segmentID, segment := range node.SegmentsMap {
		currentMemSize := segment.GetMemSize()
		memIncreaseRate := float32(0)
		stat := masterPb.SegmentStat{
			SegmentId:  uint64(segmentID),
			MemorySize: currentMemSize,
			MemoryRate: memIncreaseRate,
		}
		statisticData = append(statisticData, stat)
	}

	// TODO: start pulsar server
	node.PublicStatistic(&statisticData)
118 119

	node.Close()
Z
zhenshan.cao 已提交
120
}