milvus/internal/querynode/shard_cluster_service_test.go
congqixia b99b65c26e
Add segment reference count and handles change info in ShardCluster (#16620)
Resolves #16619
Add reference count for each search/query request
For SegmentChangeInfo
- Wait all segments in OnlineList to be loaded
- Add handoff event into pending list
- Wait all segments in OfflineList is not used (reference count = 0)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2022-04-25 11:51:46 +08:00

53 lines
1.7 KiB
Go

package querynode
import (
"context"
"testing"
"github.com/milvus-io/milvus/internal/proto/querypb"
"github.com/milvus-io/milvus/internal/util/sessionutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3client"
)
func TestShardClusterService(t *testing.T) {
client := v3client.New(embedetcdServer.Server)
defer client.Close()
session := sessionutil.NewSession(context.Background(), "/by-dev/sessions/unittest/querynode/", client)
clusterService := newShardClusterService(client, session, nil)
assert.NotPanics(t, func() {
clusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
})
shardCluster, ok := clusterService.getShardCluster(defaultDMLChannel)
assert.True(t, ok)
assert.NotNil(t, shardCluster)
_, ok = clusterService.getShardCluster("non-exist-channel")
assert.False(t, ok)
err := clusterService.releaseShardCluster(defaultDMLChannel)
assert.NoError(t, err)
err = clusterService.releaseShardCluster("non-exist-channel")
assert.Error(t, err)
}
func TestShardClusterService_HandoffSegments(t *testing.T) {
qn, err := genSimpleQueryNode(context.Background())
require.NoError(t, err)
client := v3client.New(embedetcdServer.Server)
defer client.Close()
session := sessionutil.NewSession(context.Background(), "/by-dev/sessions/unittest/querynode/", client)
clusterService := newShardClusterService(client, session, qn)
clusterService.addShardCluster(defaultCollectionID, defaultReplicaID, defaultDMLChannel)
//TODO change shardCluster to interface to mock test behavior
assert.NotPanics(t, func() {
clusterService.HandoffSegments(defaultCollectionID, &querypb.SegmentChangeInfo{})
})
}