diff --git a/core/stores/mon/bulkinserter.go b/core/stores/mon/bulkinserter.go index 74cbb7d9..7ef15ca5 100644 --- a/core/stores/mon/bulkinserter.go +++ b/core/stores/mon/bulkinserter.go @@ -25,25 +25,15 @@ type ( } ) -// Deprecated. Use NewBatchInserter instead. -func NewBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter { - return newBulkInserter(coll, interval...) -} - -// NewBatchInserter returns a BulkInserter. -func NewBatchInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) { +// NewBulkInserter returns a BulkInserter. +func NewBulkInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) { cloneColl, err := coll.Clone() if err != nil { return nil, err } - return newBulkInserter(cloneColl, interval...), nil -} - -// newBulkInserter returns a BulkInserter. -func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter { inserter := &dbInserter{ - collection: coll, + collection: cloneColl, } duration := flushInterval @@ -54,7 +44,7 @@ func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkIns return &BulkInserter{ executor: executors.NewPeriodicalExecutor(duration, inserter), inserter: inserter, - } + }, nil } // Flush flushes the inserter, writes all pending records. diff --git a/core/stores/mon/bulkinserter_test.go b/core/stores/mon/bulkinserter_test.go index f2889d35..ebd0ec4a 100644 --- a/core/stores/mon/bulkinserter_test.go +++ b/core/stores/mon/bulkinserter_test.go @@ -15,24 +15,7 @@ func TestBulkInserter(t *testing.T) { mt.Run("test", func(mt *mtest.T) { mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...)) - bulk := NewBulkInserter(mt.Coll) - bulk.SetResultHandler(func(result *mongo.InsertManyResult, err error) { - assert.Nil(t, err) - assert.Equal(t, 2, len(result.InsertedIDs)) - }) - bulk.Insert(bson.D{{Key: "foo", Value: "bar"}}) - bulk.Insert(bson.D{{Key: "foo", Value: "baz"}}) - bulk.Flush() - }) -} - -func TestBatchInserter(t *testing.T) { - mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock)) - defer mt.Close() - - mt.Run("test", func(mt *mtest.T) { - mt.AddMockResponses(mtest.CreateSuccessResponse(bson.D{{Key: "ok", Value: 1}}...)) - bulk, err := NewBatchInserter(createModel(mt).Collection) + bulk, err := NewBulkInserter(createModel(mt).Collection) assert.Equal(t, err, nil) bulk.SetResultHandler(func(result *mongo.InsertManyResult, err error) { assert.Nil(t, err)