github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/test/testcases/flush_test.go (about) 1 //go:build L0 2 3 package testcases 4 5 import ( 6 "strconv" 7 "testing" 8 "time" 9 10 "github.com/milvus-io/milvus-sdk-go/v2/test/common" 11 "github.com/stretchr/testify/require" 12 ) 13 14 // test flush collection 15 func TestFlushCollection(t *testing.T) { 16 ctx := createContext(t, time.Second*common.DefaultTimeout) 17 // connect 18 mc := createMilvusClient(ctx, t) 19 20 // create default collection 21 collName := createDefaultCollection(ctx, t, mc, false, common.DefaultShards) 22 23 // insert 24 intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, common.DefaultNb, common.DefaultDim) 25 ids, errInsert := mc.Insert(ctx, collName, "", intColumn, floatColumn, vecColumn) 26 common.CheckErr(t, errInsert, true) 27 common.CheckInsertResult(t, ids, intColumn) 28 29 // flush and check row count 30 errFlush := mc.Flush(ctx, collName, false) 31 common.CheckErr(t, errFlush, true) 32 stats, _ := mc.GetCollectionStatistics(ctx, collName) 33 require.Equal(t, strconv.Itoa(common.DefaultNb), stats[common.RowCount]) 34 } 35 36 // test flush empty collection 37 func TestFlushEmptyCollection(t *testing.T) { 38 ctx := createContext(t, time.Second*common.DefaultTimeout) 39 // connect 40 mc := createMilvusClient(ctx, t) 41 42 // create default collection 43 collName := createDefaultCollection(ctx, t, mc, false, common.DefaultShards) 44 45 // flush and check row count 46 errFlush := mc.Flush(ctx, collName, false) 47 common.CheckErr(t, errFlush, true) 48 stats, _ := mc.GetCollectionStatistics(ctx, collName) 49 require.Equal(t, "0", stats[common.RowCount]) 50 } 51 52 // test flush not existed collection 53 func TestFlushNotExistedCollection(t *testing.T) { 54 ctx := createContext(t, time.Second*common.DefaultTimeout) 55 // connect 56 mc := createMilvusClient(ctx, t) 57 58 // flush and check row count 59 errFlush := mc.Flush(ctx, "collName", false) 60 common.CheckErr(t, errFlush, false, "collection collName does not exist") 61 } 62 63 // test flush async 64 func TestFlushAsync(t *testing.T) { 65 ctx := createContext(t, time.Second*common.DefaultTimeout) 66 // connect 67 mc := createMilvusClient(ctx, t) 68 69 // create default collection 70 collName := createDefaultCollection(ctx, t, mc, false, common.DefaultShards) 71 72 // insert 73 intColumn, floatColumn, vecColumn := common.GenDefaultColumnData(0, common.DefaultNb, common.DefaultDim) 74 ids, errInsert := mc.Insert(ctx, collName, "", intColumn, floatColumn, vecColumn) 75 common.CheckErr(t, errInsert, true) 76 common.CheckInsertResult(t, ids, intColumn) 77 78 // flush and check row count 79 errFlush := mc.Flush(ctx, collName, true) 80 common.CheckErr(t, errFlush, true) 81 mc.GetCollectionStatistics(ctx, collName) 82 83 // wait flush done 84 for { 85 time.Sleep(time.Second * 1) 86 stats, errStatist := mc.GetCollectionStatistics(ctx, collName) 87 if errStatist == nil { 88 if strconv.Itoa(common.DefaultNb) == stats[common.RowCount] { 89 break 90 } 91 } else { 92 t.FailNow() 93 } 94 } 95 }