(t *testing.T)
| 689 | } |
| 690 | |
| 691 | func TestWriteBatchDuplicate(t *testing.T) { |
| 692 | N := 10 |
| 693 | k := []byte("key") |
| 694 | v := []byte("val") |
| 695 | readVerify := func(t *testing.T, db *DB, n int, versions []int) { |
| 696 | err := db.View(func(txn *Txn) error { |
| 697 | iopt := DefaultIteratorOptions |
| 698 | iopt.AllVersions = true |
| 699 | itr := txn.NewIterator(iopt) |
| 700 | defer itr.Close() |
| 701 | |
| 702 | i := 0 |
| 703 | for itr.Rewind(); itr.Valid(); itr.Next() { |
| 704 | item := itr.Item() |
| 705 | require.Equal(t, k, item.Key()) |
| 706 | require.Equal(t, uint64(versions[i]), item.Version()) |
| 707 | err := item.Value(func(val []byte) error { |
| 708 | require.Equal(t, v, val) |
| 709 | return nil |
| 710 | }) |
| 711 | require.NoError(t, err) |
| 712 | i++ |
| 713 | } |
| 714 | require.Equal(t, n, i) |
| 715 | return nil |
| 716 | }) |
| 717 | require.NoError(t, err) |
| 718 | } |
| 719 | |
| 720 | t.Run("writebatch", func(t *testing.T) { |
| 721 | opt := DefaultOptions("") |
| 722 | opt.MaxTableSize = 1 << 15 // This would create multiple transactions in write batch. |
| 723 | |
| 724 | runBadgerTest(t, &opt, func(t *testing.T, db *DB) { |
| 725 | wb := db.NewWriteBatch() |
| 726 | defer wb.Cancel() |
| 727 | |
| 728 | for i := uint64(0); i < uint64(N); i++ { |
| 729 | // Multiple versions of the same key. |
| 730 | require.NoError(t, wb.SetEntry(&Entry{Key: k, Value: v})) |
| 731 | } |
| 732 | require.NoError(t, wb.Flush()) |
| 733 | readVerify(t, db, 1, []int{1}) |
| 734 | }) |
| 735 | }) |
| 736 | t.Run("writebatch at", func(t *testing.T) { |
| 737 | opt := DefaultOptions("") |
| 738 | opt.MaxTableSize = 1 << 15 // This would create multiple transactions in write batch. |
| 739 | opt.managedTxns = true |
| 740 | |
| 741 | runBadgerTest(t, &opt, func(t *testing.T, db *DB) { |
| 742 | wb := db.NewWriteBatchAt(10) |
| 743 | defer wb.Cancel() |
| 744 | |
| 745 | for i := uint64(0); i < uint64(N); i++ { |
| 746 | // Multiple versions of the same key. |
| 747 | require.NoError(t, wb.SetEntry(&Entry{Key: k, Value: v})) |
| 748 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…