2021-11-29 20:13:50 +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-04-19 13:47:10 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-29 20:13:50 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 13:47:10 +08:00
|
|
|
//
|
2021-11-29 20:13:50 +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-04-19 13:47:10 +08:00
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-10-24 10:45:57 +08:00
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
import (
|
2020-11-12 12:04:12 +08:00
|
|
|
"testing"
|
|
|
|
|
2020-11-12 11:18:23 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCollection_newCollection(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2021-01-18 10:38:41 +08:00
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_deleteCollection(t *testing.T) {
|
2020-12-08 14:41:04 +08:00
|
|
|
collectionID := UniqueID(0)
|
2021-02-03 11:52:19 +08:00
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
2020-12-07 15:22:20 +08:00
|
|
|
|
2021-01-18 10:38:41 +08:00
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2020-12-10 16:31:09 +08:00
|
|
|
assert.Equal(t, collection.ID(), collectionID)
|
2020-11-12 11:18:23 +08:00
|
|
|
deleteCollection(collection)
|
|
|
|
}
|
2021-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
func TestCollection_schema(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
schema := collection.Schema()
|
|
|
|
assert.Equal(t, collectionMeta.Schema.Name, schema.Name)
|
|
|
|
assert.Equal(t, len(collectionMeta.Schema.Fields), len(schema.Fields))
|
|
|
|
deleteCollection(collection)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_vChannel(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2021-12-17 20:12:42 +08:00
|
|
|
collection.addVChannels([]Channel{defaultDMLChannel})
|
|
|
|
collection.addVChannels([]Channel{defaultDMLChannel})
|
2021-11-26 01:33:16 +08:00
|
|
|
collection.addVChannels([]Channel{"TestCollection_addVChannel_channel"})
|
2021-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
channels := collection.getVChannels()
|
|
|
|
assert.Equal(t, 2, len(channels))
|
2021-11-26 01:33:16 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
collection.removeVChannel(defaultDMLChannel)
|
2021-11-26 01:33:16 +08:00
|
|
|
channels = collection.getVChannels()
|
|
|
|
assert.Equal(t, 1, len(channels))
|
2021-09-07 15:45:59 +08:00
|
|
|
}
|
|
|
|
|
2021-11-09 09:27:04 +08:00
|
|
|
func TestCollection_vDeltaChannel(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2021-12-17 20:12:42 +08:00
|
|
|
collection.addVDeltaChannels([]Channel{defaultDeltaChannel})
|
|
|
|
collection.addVDeltaChannels([]Channel{defaultDeltaChannel})
|
2021-11-26 01:33:16 +08:00
|
|
|
collection.addVDeltaChannels([]Channel{"TestCollection_addVDeltaChannel_channel"})
|
2021-11-09 09:27:04 +08:00
|
|
|
|
|
|
|
channels := collection.getVDeltaChannels()
|
|
|
|
assert.Equal(t, 2, len(channels))
|
2021-11-26 01:33:16 +08:00
|
|
|
|
2021-12-17 20:12:42 +08:00
|
|
|
collection.removeVDeltaChannel(defaultDeltaChannel)
|
2021-11-26 01:33:16 +08:00
|
|
|
channels = collection.getVDeltaChannels()
|
|
|
|
assert.Equal(t, 1, len(channels))
|
2021-11-09 09:27:04 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
func TestCollection_pChannel(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2021-11-26 01:33:16 +08:00
|
|
|
collection.addPChannels([]Channel{"TestCollection_addPChannel_channel-0"})
|
|
|
|
collection.addPChannels([]Channel{"TestCollection_addPChannel_channel-0"})
|
|
|
|
collection.addPChannels([]Channel{"TestCollection_addPChannel_channel-1"})
|
2021-09-07 15:45:59 +08:00
|
|
|
|
|
|
|
channels := collection.getPChannels()
|
|
|
|
assert.Equal(t, 2, len(channels))
|
|
|
|
}
|
|
|
|
|
2021-11-09 09:27:04 +08:00
|
|
|
func TestCollection_pDeltaChannel(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
2021-11-26 01:33:16 +08:00
|
|
|
collection.addPDeltaChannels([]Channel{"TestCollection_addPDeltaChannel_channel-0"})
|
|
|
|
collection.addPDeltaChannels([]Channel{"TestCollection_addPDeltaChannel_channel-0"})
|
|
|
|
collection.addPDeltaChannels([]Channel{"TestCollection_addPDeltaChannel_channel-1"})
|
2021-11-09 09:27:04 +08:00
|
|
|
|
|
|
|
channels := collection.getPDeltaChannels()
|
|
|
|
assert.Equal(t, 2, len(channels))
|
|
|
|
}
|
|
|
|
|
2021-09-07 15:45:59 +08:00
|
|
|
func TestCollection_releaseTime(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
t0 := Timestamp(1000)
|
|
|
|
collection.setReleaseTime(t0)
|
|
|
|
t1 := collection.getReleaseTime()
|
|
|
|
assert.Equal(t, t0, t1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_loadType(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionMeta := genTestCollectionMeta(collectionID, false)
|
|
|
|
|
|
|
|
collection := newCollection(collectionMeta.ID, collectionMeta.Schema)
|
|
|
|
collection.setLoadType(loadTypeCollection)
|
|
|
|
lt := collection.getLoadType()
|
|
|
|
assert.Equal(t, loadTypeCollection, lt)
|
|
|
|
|
|
|
|
collection.setLoadType(loadTypePartition)
|
|
|
|
lt = collection.getLoadType()
|
|
|
|
assert.Equal(t, loadTypePartition, lt)
|
|
|
|
}
|