(t *testing.T)
| 658 | } |
| 659 | |
| 660 | func TestIterate2Basic(t *testing.T) { |
| 661 | test := func(t *testing.T, db *DB) { |
| 662 | bkey := func(i int) []byte { |
| 663 | return []byte(fmt.Sprintf("%09d", i)) |
| 664 | } |
| 665 | bval := func(i int) []byte { |
| 666 | return []byte(fmt.Sprintf("%025d", i)) |
| 667 | } |
| 668 | |
| 669 | // n := 500000 |
| 670 | n := 10000 |
| 671 | for i := 0; i < n; i++ { |
| 672 | if (i % 1000) == 0 { |
| 673 | t.Logf("Put i=%d\n", i) |
| 674 | } |
| 675 | txnSet(t, db, bkey(i), bval(i), byte(i%127)) |
| 676 | } |
| 677 | |
| 678 | opt := IteratorOptions{} |
| 679 | opt.PrefetchValues = true |
| 680 | opt.PrefetchSize = 10 |
| 681 | |
| 682 | txn := db.NewTransaction(false) |
| 683 | it := txn.NewIterator(opt) |
| 684 | { |
| 685 | var count int |
| 686 | rewind := true |
| 687 | t.Log("Starting first basic iteration") |
| 688 | for it.Rewind(); it.Valid(); it.Next() { |
| 689 | item := it.Item() |
| 690 | key := item.Key() |
| 691 | if rewind && count == 5000 { |
| 692 | // Rewind would skip /head/ key, and it.Next() would skip 0. |
| 693 | count = 1 |
| 694 | it.Rewind() |
| 695 | t.Log("Rewinding from 5000 to zero.") |
| 696 | rewind = false |
| 697 | continue |
| 698 | } |
| 699 | require.EqualValues(t, bkey(count), string(key)) |
| 700 | val := getItemValue(t, item) |
| 701 | require.EqualValues(t, bval(count), string(val)) |
| 702 | require.Equal(t, byte(count%127), item.UserMeta()) |
| 703 | count++ |
| 704 | } |
| 705 | require.EqualValues(t, n, count) |
| 706 | } |
| 707 | |
| 708 | { |
| 709 | t.Log("Starting second basic iteration") |
| 710 | idx := 5030 |
| 711 | for it.Seek(bkey(idx)); it.Valid(); it.Next() { |
| 712 | item := it.Item() |
| 713 | require.EqualValues(t, bkey(idx), string(item.Key())) |
| 714 | require.EqualValues(t, bval(idx), string(getItemValue(t, item))) |
| 715 | idx++ |
| 716 | } |
| 717 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…