stats_service_test.go 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.

12
package querynode
13

D
dragondriver 已提交
14 15 16
import (
	"testing"

X
Xiangyu Wang 已提交
17
	"github.com/milvus-io/milvus/internal/msgstream"
Z
zhenshan.cao 已提交
18
	"github.com/stretchr/testify/assert"
D
dragondriver 已提交
19 20 21 22
)

// NOTE: start pulsar before test
func TestStatsService_start(t *testing.T) {
23
	node := newQueryNodeMock()
B
bigsheeper 已提交
24
	initTestMeta(t, node, 0, 0)
G
groot 已提交
25

X
Xiangyu Wang 已提交
26
	msFactory := msgstream.NewPmsFactory()
G
groot 已提交
27 28 29 30 31
	m := map[string]interface{}{
		"PulsarAddress":  Params.PulsarAddress,
		"ReceiveBufSize": 1024,
		"PulsarBufSize":  1024}
	msFactory.SetParams(m)
32 33
	node.historical.statsService = newStatsService(node.queryNodeLoopCtx, node.historical.replica, nil, msFactory)
	node.historical.statsService.start()
C
cai.zhang 已提交
34
	node.Stop()
D
dragondriver 已提交
35 36
}

X
XuanYang-cn 已提交
37
//NOTE: start pulsar before test
38
func TestSegmentManagement_sendSegmentStatistic(t *testing.T) {
39
	node := newQueryNodeMock()
B
bigsheeper 已提交
40
	initTestMeta(t, node, 0, 0)
D
dragondriver 已提交
41 42 43

	const receiveBufSize = 1024
	// start pulsar
44
	producerChannels := []string{Params.StatsChannelName}
D
dragondriver 已提交
45

X
Xiangyu Wang 已提交
46
	msFactory := msgstream.NewPmsFactory()
G
groot 已提交
47 48 49 50 51 52 53 54
	m := map[string]interface{}{
		"receiveBufSize": receiveBufSize,
		"pulsarAddress":  Params.PulsarAddress,
		"pulsarBufSize":  1024}
	err := msFactory.SetParams(m)
	assert.Nil(t, err)

	statsStream, err := msFactory.NewMsgStream(node.queryNodeLoopCtx)
Z
zhenshan.cao 已提交
55 56
	assert.Nil(t, err)
	statsStream.AsProducer(producerChannels)
D
dragondriver 已提交
57 58 59

	var statsMsgStream msgstream.MsgStream = statsStream

60 61 62
	node.historical.statsService = newStatsService(node.queryNodeLoopCtx, node.historical.replica, nil, msFactory)
	node.historical.statsService.statsStream = statsMsgStream
	node.historical.statsService.statsStream.Start()
D
dragondriver 已提交
63 64

	// send stats
65
	node.historical.statsService.publicStatistic(nil)
C
cai.zhang 已提交
66
	node.Stop()
D
dragondriver 已提交
67
}