2021-11-10 23:57:08 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-06-22 14:40:07 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-10 23:57:08 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-22 14:40:07 +08:00
|
|
|
//
|
2021-11-10 23:57:08 +08:00
|
|
|
// 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.
|
2021-06-22 14:40:07 +08:00
|
|
|
|
|
|
|
package proxy
|
2021-05-21 09:52:20 +08:00
|
|
|
|
|
|
|
import (
|
2021-09-13 11:58:11 +08:00
|
|
|
"sync"
|
2021-05-21 09:52:20 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/uniquegenerator"
|
2021-05-21 09:52:20 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestChannelsMgrImpl_getChannels(t *testing.T) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-21 09:52:20 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-21 09:52:20 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-21 09:52:20 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-21 09:52:20 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-21 09:52:20 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-21 09:52:20 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-21 09:52:20 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-21 09:52:20 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-21 09:52:20 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-21 09:52:20 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-21 09:52:20 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
|
|
|
|
|
|
|
num := 10
|
|
|
|
for i := 0; i < num; i++ {
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-21 09:52:20 +08:00
|
|
|
err := mgr.createDMLMsgStream(collID)
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
}
|
|
|
|
}
|
2021-05-29 15:09:30 +08:00
|
|
|
|
|
|
|
func TestChannelsMgrImpl_createDQLMsgStream(t *testing.T) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-31 17:28:31 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
2021-05-29 15:09:30 +08:00
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-29 15:09:30 +08:00
|
|
|
|
2021-08-31 10:25:59 +08:00
|
|
|
err := mgr.createDQLStream(collID)
|
2021-05-29 15:09:30 +08:00
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestChannelsMgrImpl_getDQLMsgStream(t *testing.T) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-31 17:28:31 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
2021-05-29 15:09:30 +08:00
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-29 15:09:30 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-31 17:28:31 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
2021-05-29 15:09:30 +08:00
|
|
|
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-29 15:09:30 +08:00
|
|
|
_, 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) {
|
2021-05-31 17:28:31 +08:00
|
|
|
master := newMockGetChannelsService()
|
|
|
|
query := newMockGetChannelsService()
|
2021-09-09 19:02:08 +08:00
|
|
|
factory := newSimpleMockMsgStreamFactory()
|
2021-08-31 10:25:59 +08:00
|
|
|
mgr := newChannelsMgrImpl(master.GetChannels, nil, query.GetChannels, nil, factory)
|
2021-05-31 17:28:31 +08:00
|
|
|
defer mgr.removeAllDMLStream()
|
2021-05-29 15:09:30 +08:00
|
|
|
|
|
|
|
num := 10
|
|
|
|
for i := 0; i < num; i++ {
|
2021-09-09 10:06:29 +08:00
|
|
|
collID := UniqueID(uniquegenerator.GetUniqueIntGeneratorIns().GetInt())
|
2021-05-29 15:09:30 +08:00
|
|
|
err := mgr.createDQLStream(collID)
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
}
|
|
|
|
}
|
2021-09-13 11:58:11 +08:00
|
|
|
|
|
|
|
func TestGetAllKeysAndGetAllValues(t *testing.T) {
|
|
|
|
chanMapping := make(map[vChan]pChan)
|
|
|
|
chanMapping["v1"] = "p1"
|
|
|
|
chanMapping["v2"] = "p2"
|
|
|
|
|
|
|
|
t.Run("getAllKeys", func(t *testing.T) {
|
|
|
|
vChans := getAllKeys(chanMapping)
|
|
|
|
assert.Equal(t, 2, len(vChans))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("getAllValues", func(t *testing.T) {
|
|
|
|
pChans := getAllValues(chanMapping)
|
|
|
|
assert.Equal(t, 2, len(pChans))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteVChansByVID(t *testing.T) {
|
|
|
|
mgr := singleTypeChannelsMgr{
|
|
|
|
id2vchansMtx: sync.RWMutex{},
|
|
|
|
id2vchans: map[int][]vChan{
|
|
|
|
10: {"v1"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr.deleteVChansByVID(10)
|
|
|
|
}
|