mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 10:59:32 +08:00
41d638abb5
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
143 lines
4.0 KiB
Go
143 lines
4.0 KiB
Go
package reader
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestConstructorAndDestructor(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegmentInsert(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
ids :=[] int64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var err = segment.SegmentInsert(&ids, ×tamps, nil, 0, 0)
|
|
assert.NoError(t, err)
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegmentDelete(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
ids :=[] int64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var err = segment.SegmentDelete(&ids, ×tamps, 0, 0)
|
|
assert.NoError(t, err)
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegmentSearch(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
ids :=[] int64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var insertErr = segment.SegmentInsert(&ids, ×tamps, nil, 0, 0)
|
|
assert.NoError(t, insertErr)
|
|
|
|
var searchRes, searchErr = segment.SegmentSearch("fake query string", timestamps[0], nil)
|
|
assert.NoError(t, searchErr)
|
|
fmt.Println(searchRes)
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegment_GetStatus(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
var status = segment.GetStatus()
|
|
assert.Equal(t, status, SegmentOpened)
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegment_Close(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
var err = segment.Close()
|
|
assert.NoError(t, err)
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegment_GetRowCount(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
ids :=[] int64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var err = segment.SegmentInsert(&ids, ×tamps, nil, 0, 0)
|
|
assert.NoError(t, err)
|
|
|
|
var rowCount = segment.GetRowCount()
|
|
assert.Equal(t, rowCount, int64(len(ids)))
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegment_GetDeletedCount(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
ids :=[] int64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var err = segment.SegmentDelete(&ids, ×tamps, 0, 0)
|
|
assert.NoError(t, err)
|
|
|
|
var deletedCount = segment.GetDeletedCount()
|
|
// TODO: assert.Equal(t, deletedCount, len(ids))
|
|
assert.Equal(t, deletedCount, int64(0))
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|