mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
Improve codecov for paramtable and typeutil (#7471)
Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
This commit is contained in:
parent
960741ee16
commit
5a16236768
@ -143,3 +143,25 @@ func TestGlobalTSOAllocator_Fail(t *testing.T) {
|
||||
gTestTsoAllocator.Reset()
|
||||
})
|
||||
}
|
||||
|
||||
func TestGlobalTSOAllocator_Update(t *testing.T) {
|
||||
endpoints := os.Getenv("ETCD_ENDPOINTS")
|
||||
if endpoints == "" {
|
||||
endpoints = "localhost:2379"
|
||||
}
|
||||
etcdEndpoints := strings.Split(endpoints, ",")
|
||||
etcdKV, err := tsoutil.NewTSOKVBase(etcdEndpoints, "/test/root/kv", "tsoTest")
|
||||
assert.NoError(t, err)
|
||||
gTestTsoAllocator = NewGlobalTSOAllocator("timestamp", etcdKV)
|
||||
err = gTestTsoAllocator.Initialize()
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = gTestTsoAllocator.UpdateTSO()
|
||||
assert.Nil(t, err)
|
||||
time.Sleep(160 * time.Millisecond)
|
||||
err = gTestTsoAllocator.UpdateTSO()
|
||||
assert.Nil(t, err)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
err = gTestTsoAllocator.UpdateTSO()
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
@ -44,6 +44,9 @@ func TestConversion(t *testing.T) {
|
||||
comp(int64(-8654273))
|
||||
comp(int64(math.MaxInt64))
|
||||
comp(int64(math.MinInt64))
|
||||
|
||||
_, err := BytesToInt64([]byte("ab"))
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
t.Run("TestConvertUint64", func(t *testing.T) {
|
||||
@ -57,6 +60,9 @@ func TestConversion(t *testing.T) {
|
||||
comp(uint64(0))
|
||||
comp(uint64(75123348654273))
|
||||
comp(uint64(math.MaxUint64))
|
||||
|
||||
_, err := BytesToUint64([]byte("ab"))
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
t.Run("TestSliceRemoveDuplicate", func(t *testing.T) {
|
||||
|
@ -34,10 +34,7 @@ func CompareIndexParams(indexParam1 []*commonpb.KeyValuePair, indexParam2 []*com
|
||||
}
|
||||
|
||||
for k, v := range paramMap1 {
|
||||
if _, ok := paramMap2[k]; !ok {
|
||||
return false
|
||||
}
|
||||
if v != paramMap2[k] {
|
||||
if _, ok := paramMap2[k]; !ok || v != paramMap2[k] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,27 @@ func TestSchema(t *testing.T) {
|
||||
},
|
||||
{
|
||||
FieldID: 104,
|
||||
Name: "field_float",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 10,
|
||||
},
|
||||
{
|
||||
FieldID: 105,
|
||||
Name: "field_double",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 11,
|
||||
},
|
||||
{
|
||||
FieldID: 106,
|
||||
Name: "field_string",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 20,
|
||||
},
|
||||
{
|
||||
FieldID: 107,
|
||||
Name: "field_float_vector",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
@ -73,7 +94,7 @@ func TestSchema(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
FieldID: 105,
|
||||
FieldID: 108,
|
||||
Name: "field_binary_vector",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
@ -90,11 +111,14 @@ func TestSchema(t *testing.T) {
|
||||
|
||||
t.Run("EstimateSizePerRecord", func(t *testing.T) {
|
||||
size, err := EstimateSizePerRecord(schema)
|
||||
assert.Equal(t, 543, size)
|
||||
assert.Equal(t, 680, size)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("SchemaHelper", func(t *testing.T) {
|
||||
_, err := CreateSchemaHelper(nil)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
helper, err := CreateSchemaHelper(schema)
|
||||
assert.Nil(t, err)
|
||||
|
||||
@ -110,10 +134,10 @@ func TestSchema(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "field_int32", field2.Name)
|
||||
|
||||
dim, err := helper.GetVectorDimFromID(104)
|
||||
dim, err := helper.GetVectorDimFromID(107)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 128, dim)
|
||||
dim1, err := helper.GetVectorDimFromID(105)
|
||||
dim1, err := helper.GetVectorDimFromID(108)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 128, dim1)
|
||||
_, err = helper.GetVectorDimFromID(103)
|
||||
@ -155,3 +179,148 @@ func TestSchema(t *testing.T) {
|
||||
assert.False(t, IsFloatingType(schemapb.DataType_FloatVector))
|
||||
})
|
||||
}
|
||||
|
||||
func TestSchema_invalid(t *testing.T) {
|
||||
t.Run("Duplicate field name", func(t *testing.T) {
|
||||
schema := &schemapb.CollectionSchema{
|
||||
Name: "testColl",
|
||||
Description: "",
|
||||
AutoID: false,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
FieldID: 100,
|
||||
Name: "field_int8",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 2,
|
||||
},
|
||||
{
|
||||
FieldID: 101,
|
||||
Name: "field_int8",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := CreateSchemaHelper(schema)
|
||||
assert.NotNil(t, err)
|
||||
assert.EqualError(t, err, "duplicated fieldName: field_int8")
|
||||
})
|
||||
t.Run("Duplicate field id", func(t *testing.T) {
|
||||
schema := &schemapb.CollectionSchema{
|
||||
Name: "testColl",
|
||||
Description: "",
|
||||
AutoID: false,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
FieldID: 100,
|
||||
Name: "field_int8",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 2,
|
||||
},
|
||||
{
|
||||
FieldID: 100,
|
||||
Name: "field_int16",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := CreateSchemaHelper(schema)
|
||||
assert.NotNil(t, err)
|
||||
assert.EqualError(t, err, "duplicated fieldID: 100")
|
||||
})
|
||||
t.Run("Duplicated primary key", func(t *testing.T) {
|
||||
schema := &schemapb.CollectionSchema{
|
||||
Name: "testColl",
|
||||
Description: "",
|
||||
AutoID: false,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
FieldID: 100,
|
||||
Name: "field_int8",
|
||||
IsPrimaryKey: true,
|
||||
Description: "",
|
||||
DataType: 2,
|
||||
},
|
||||
{
|
||||
FieldID: 101,
|
||||
Name: "field_int16",
|
||||
IsPrimaryKey: true,
|
||||
Description: "",
|
||||
DataType: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := CreateSchemaHelper(schema)
|
||||
assert.NotNil(t, err)
|
||||
assert.EqualError(t, err, "primary key is not unique")
|
||||
})
|
||||
t.Run("field not exist", func(t *testing.T) {
|
||||
schema := &schemapb.CollectionSchema{
|
||||
Name: "testColl",
|
||||
Description: "",
|
||||
AutoID: false,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
FieldID: 100,
|
||||
Name: "field_int8",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
helper, err := CreateSchemaHelper(schema)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = helper.GetPrimaryKeyField()
|
||||
assert.NotNil(t, err)
|
||||
assert.EqualError(t, err, "no primary in schema")
|
||||
|
||||
_, err = helper.GetFieldFromName("none")
|
||||
assert.NotNil(t, err)
|
||||
assert.EqualError(t, err, "fieldName(none) not found")
|
||||
|
||||
_, err = helper.GetFieldFromID(101)
|
||||
assert.NotNil(t, err)
|
||||
assert.EqualError(t, err, "fieldID(101) not found")
|
||||
})
|
||||
t.Run("vector dim not exist", func(t *testing.T) {
|
||||
schema := &schemapb.CollectionSchema{
|
||||
Name: "testColl",
|
||||
Description: "",
|
||||
AutoID: false,
|
||||
Fields: []*schemapb.FieldSchema{
|
||||
{
|
||||
FieldID: 103,
|
||||
Name: "field_int64",
|
||||
IsPrimaryKey: true,
|
||||
Description: "",
|
||||
DataType: 5,
|
||||
},
|
||||
{
|
||||
FieldID: 107,
|
||||
Name: "field_float_vector",
|
||||
IsPrimaryKey: false,
|
||||
Description: "",
|
||||
DataType: 101,
|
||||
},
|
||||
},
|
||||
}
|
||||
helper, err := CreateSchemaHelper(schema)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = helper.GetVectorDimFromID(100)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
_, err = helper.GetVectorDimFromID(103)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
_, err = helper.GetVectorDimFromID(107)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ func TestParseTimestamp(t *testing.T) {
|
||||
ts, err := ParseTimestamp(Int64ToBytes(1000))
|
||||
t.Log(ts.String())
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, err = ParseTimestamp([]byte("ab"))
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestSubTimeByWallClock(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user