mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 20:09:57 +08:00
947b223bae
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
182 lines
5.1 KiB
Go
182 lines
5.1 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 :=[] uint64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var _, err = SegmentInsert(segment, &ids, ×tamps, nil)
|
|
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 :=[] uint64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var _, err = SegmentDelete(segment, &ids, ×tamps)
|
|
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 :=[] uint64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var _, insertErr = SegmentInsert(segment, &ids, ×tamps, nil)
|
|
assert.NoError(t, insertErr)
|
|
|
|
var searchRes, searchErr = SegmentSearch(segment, "fake query string", ×tamps, 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 :=[] uint64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var _, err = SegmentInsert(segment, &ids, ×tamps, nil)
|
|
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 :=[] uint64{1, 2, 3}
|
|
timestamps :=[] uint64 {0, 0, 0}
|
|
|
|
var _, err = SegmentDelete(segment, &ids, ×tamps)
|
|
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)
|
|
}
|
|
|
|
func TestSegment_TimestampGetterAndSetter(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
const MinTimestamp = 100
|
|
const MaxTimestamp = 200
|
|
|
|
segment.SetMinTimestamp(MinTimestamp)
|
|
var minTimestamp = segment.GetMinTimestamp()
|
|
assert.Equal(t, minTimestamp, uint64(MinTimestamp))
|
|
|
|
segment.SetMaxTimestamp(MaxTimestamp)
|
|
var maxTimestamp = segment.GetMaxTimestamp()
|
|
assert.Equal(t, maxTimestamp, uint64(MaxTimestamp))
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|
|
|
|
func TestSegment_SegmentIDGetterAndSetter(t *testing.T) {
|
|
node := NewQueryNode(0, 0)
|
|
var collection = node.NewCollection("collection0", "fake schema")
|
|
var partition = collection.NewPartition("partition0")
|
|
var segment = partition.NewSegment(0)
|
|
|
|
const SegmentID = 1
|
|
|
|
segment.SetSegmentID(SegmentID)
|
|
var segmentID = segment.GetSegmentID()
|
|
assert.Equal(t, segmentID, uint64(SegmentID))
|
|
|
|
partition.DeleteSegment(segment)
|
|
collection.DeletePartition(partition)
|
|
node.DeleteCollection(collection)
|
|
}
|