diff --git a/internal/tso/global_allocator_test.go b/internal/tso/global_allocator_test.go index 0a0ff9f48f..cc39af6c9b 100644 --- a/internal/tso/global_allocator_test.go +++ b/internal/tso/global_allocator_test.go @@ -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) +} diff --git a/internal/util/typeutil/conversion_test.go b/internal/util/typeutil/conversion_test.go index dbb0afd185..b1f4946d48 100644 --- a/internal/util/typeutil/conversion_test.go +++ b/internal/util/typeutil/conversion_test.go @@ -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) { diff --git a/internal/util/typeutil/index.go b/internal/util/typeutil/index.go index 50d831adf6..7e7673884f 100644 --- a/internal/util/typeutil/index.go +++ b/internal/util/typeutil/index.go @@ -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 } } diff --git a/internal/util/typeutil/schema_test.go b/internal/util/typeutil/schema_test.go index fe676560f3..6cabf0fa1b 100644 --- a/internal/util/typeutil/schema_test.go +++ b/internal/util/typeutil/schema_test.go @@ -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) + }) +} diff --git a/internal/util/typeutil/time_test.go b/internal/util/typeutil/time_test.go index c975d947c3..d88e8ec5b9 100644 --- a/internal/util/typeutil/time_test.go +++ b/internal/util/typeutil/time_test.go @@ -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) {