milvus/internal/proxy/channels_mgr_test.go
Cai Yudong 2926a78968
Rename proxynode to proxy (#5961)
* rename package name from proxynode to proxy

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>

* move distributed/proxynode to distributed/proxy

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>

* move internal/proxynode to internal/proxy

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>

* rename proxynode to proxy

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
2021-06-22 14:40:07 +08:00

235 lines
6.8 KiB
Go

// 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.
package proxy
import (
"testing"
"github.com/milvus-io/milvus/internal/msgstream"
"github.com/stretchr/testify/assert"
)
func TestNaiveUniqueIntGenerator_get(t *testing.T) {
exists := make(map[int]bool)
num := 10
generator := newNaiveUniqueIntGenerator()
for i := 0; i < num; i++ {
g := generator.get()
_, ok := exists[g]
assert.False(t, ok)
exists[g] = true
}
}
func TestChannelsMgrImpl_getChannels(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getChannels(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDMLMsgStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getChannels(collID)
assert.Equal(t, nil, err)
}
func TestChannelsMgrImpl_getVChannels(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getVChannels(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDMLMsgStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getVChannels(collID)
assert.Equal(t, nil, err)
}
func TestChannelsMgrImpl_createDMLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getChannels(collID)
assert.NotEqual(t, nil, err)
_, err = mgr.getVChannels(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDMLMsgStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getChannels(collID)
assert.Equal(t, nil, err)
_, err = mgr.getVChannels(collID)
assert.Equal(t, nil, err)
}
func TestChannelsMgrImpl_getDMLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getDMLStream(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDMLMsgStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getDMLStream(collID)
assert.Equal(t, nil, err)
}
func TestChannelsMgrImpl_removeDMLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getDMLStream(collID)
assert.NotEqual(t, nil, err)
err = mgr.removeDMLStream(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDMLMsgStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getDMLStream(collID)
assert.Equal(t, nil, err)
err = mgr.removeDMLStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getDMLStream(collID)
assert.NotEqual(t, nil, err)
}
func TestChannelsMgrImpl_removeAllDMLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
num := 10
for i := 0; i < num; i++ {
collID := UniqueID(getUniqueIntGeneratorIns().get())
err := mgr.createDMLMsgStream(collID)
assert.Equal(t, nil, err)
}
}
func TestChannelsMgrImpl_createDQLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getChannels(collID)
assert.NotEqual(t, nil, err)
_, err = mgr.getVChannels(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDQLStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getChannels(collID)
assert.Equal(t, nil, err)
_, err = mgr.getVChannels(collID)
assert.Equal(t, nil, err)
}
func TestChannelsMgrImpl_getDQLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getDQLStream(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDQLStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getDQLStream(collID)
assert.Equal(t, nil, err)
}
func TestChannelsMgrImpl_removeDQLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
collID := UniqueID(getUniqueIntGeneratorIns().get())
_, err := mgr.getDQLStream(collID)
assert.NotEqual(t, nil, err)
err = mgr.removeDQLStream(collID)
assert.NotEqual(t, nil, err)
err = mgr.createDQLStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getDQLStream(collID)
assert.Equal(t, nil, err)
err = mgr.removeDQLStream(collID)
assert.Equal(t, nil, err)
_, err = mgr.getDQLStream(collID)
assert.NotEqual(t, nil, err)
}
func TestChannelsMgrImpl_removeAllDQLMsgStream(t *testing.T) {
master := newMockGetChannelsService()
query := newMockGetChannelsService()
factory := msgstream.NewSimpleMsgStreamFactory()
mgr := newChannelsMgr(master.GetChannels, nil, query.GetChannels, nil, factory)
defer mgr.removeAllDMLStream()
num := 10
for i := 0; i < num; i++ {
collID := UniqueID(getUniqueIntGeneratorIns().get())
err := mgr.createDQLStream(collID)
assert.Equal(t, nil, err)
}
}