queryservice_test.go 2.2 KB
Newer Older
X
xige-16 已提交
1 2 3 4 5 6 7
package queryservice

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
8

G
groot 已提交
9
	"github.com/zilliztech/milvus-distributed/internal/msgstream/pulsarms"
10 11
	"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
	"github.com/zilliztech/milvus-distributed/internal/proto/querypb"
X
xige-16 已提交
12 13 14
)

func TestQueryService_Init(t *testing.T) {
G
godchen 已提交
15
	ctx := context.Background()
G
groot 已提交
16 17
	msFactory := pulsarms.NewFactory()
	service, err := NewQueryService(context.Background(), msFactory)
X
xige-16 已提交
18 19 20 21 22
	assert.Nil(t, err)
	service.Init()
	service.Start()

	t.Run("Test create channel", func(t *testing.T) {
G
godchen 已提交
23
		response, err := service.CreateQueryChannel(ctx)
X
xige-16 已提交
24 25 26 27 28 29
		assert.Nil(t, err)
		assert.Equal(t, response.RequestChannel, "query-0")
		assert.Equal(t, response.ResultChannel, "queryResult-0")
	})

	t.Run("Test Get statistics channel", func(t *testing.T) {
G
godchen 已提交
30
		response, err := service.GetStatisticsChannel(ctx)
X
xige-16 已提交
31 32 33 34 35
		assert.Nil(t, err)
		assert.Equal(t, response, "query-node-stats")
	})

	t.Run("Test Get timeTick channel", func(t *testing.T) {
G
godchen 已提交
36
		response, err := service.GetTimeTickChannel(ctx)
X
xige-16 已提交
37 38 39 40 41 42
		assert.Nil(t, err)
		assert.Equal(t, response, "queryTimeTick")
	})

	service.Stop()
}
43 44

func TestQueryService_load(t *testing.T) {
G
godchen 已提交
45
	ctx := context.Background()
G
groot 已提交
46 47
	msFactory := pulsarms.NewFactory()
	service, err := NewQueryService(context.Background(), msFactory)
48 49 50
	assert.Nil(t, err)
	service.Init()
	service.Start()
X
xige-16 已提交
51 52
	service.SetMasterService(NewMasterMock())
	service.SetDataService(NewDataMock())
53 54 55
	registerNodeRequest := &querypb.RegisterNodeRequest{
		Address: &commonpb.Address{},
	}
G
godchen 已提交
56
	service.RegisterNode(ctx, registerNodeRequest)
57 58 59 60 61

	t.Run("Test LoadSegment", func(t *testing.T) {
		loadCollectionRequest := &querypb.LoadCollectionRequest{
			CollectionID: 1,
		}
G
godchen 已提交
62
		response, err := service.LoadCollection(ctx, loadCollectionRequest)
63
		assert.Nil(t, err)
Q
quicksilver 已提交
64
		assert.Equal(t, response.ErrorCode, commonpb.ErrorCode_ERROR_CODE_SUCCESS)
65 66 67 68 69 70 71
	})

	t.Run("Test LoadPartition", func(t *testing.T) {
		loadPartitionRequest := &querypb.LoadPartitionRequest{
			CollectionID: 1,
			PartitionIDs: []UniqueID{1},
		}
G
godchen 已提交
72
		response, err := service.LoadPartitions(ctx, loadPartitionRequest)
73
		assert.Nil(t, err)
Q
quicksilver 已提交
74
		assert.Equal(t, response.ErrorCode, commonpb.ErrorCode_ERROR_CODE_SUCCESS)
75 76
	})
}