Put a lot of data to move some data to disk. WARNING: This test might take a while but it should pass!
(t *testing.T)
| 582 | // Put a lot of data to move some data to disk. |
| 583 | // WARNING: This test might take a while but it should pass! |
| 584 | func TestExistsMore(t *testing.T) { |
| 585 | test := func(t *testing.T, db *DB) { |
| 586 | // n := 500000 |
| 587 | n := 10000 |
| 588 | m := 45 |
| 589 | for i := 0; i < n; i += m { |
| 590 | if (i % 1000) == 0 { |
| 591 | t.Logf("Putting i=%d\n", i) |
| 592 | } |
| 593 | txn := db.NewTransaction(true) |
| 594 | for j := i; j < i+m && j < n; j++ { |
| 595 | require.NoError(t, txn.SetEntry(NewEntry([]byte(fmt.Sprintf("%09d", j)), |
| 596 | []byte(fmt.Sprintf("%09d", j))))) |
| 597 | } |
| 598 | require.NoError(t, txn.Commit()) |
| 599 | } |
| 600 | db.validate() |
| 601 | |
| 602 | for i := 0; i < n; i++ { |
| 603 | if (i % 1000) == 0 { |
| 604 | fmt.Printf("Testing i=%d\n", i) |
| 605 | } |
| 606 | k := fmt.Sprintf("%09d", i) |
| 607 | require.NoError(t, db.View(func(txn *Txn) error { |
| 608 | _, err := txn.Get([]byte(k)) |
| 609 | require.NoError(t, err) |
| 610 | return nil |
| 611 | })) |
| 612 | } |
| 613 | require.NoError(t, db.View(func(txn *Txn) error { |
| 614 | _, err := txn.Get([]byte("non-exists")) |
| 615 | require.Error(t, err) |
| 616 | return nil |
| 617 | })) |
| 618 | |
| 619 | // "Delete" key. |
| 620 | for i := 0; i < n; i += m { |
| 621 | if (i % 1000) == 0 { |
| 622 | fmt.Printf("Deleting i=%d\n", i) |
| 623 | } |
| 624 | txn := db.NewTransaction(true) |
| 625 | for j := i; j < i+m && j < n; j++ { |
| 626 | require.NoError(t, txn.Delete([]byte(fmt.Sprintf("%09d", j)))) |
| 627 | } |
| 628 | require.NoError(t, txn.Commit()) |
| 629 | } |
| 630 | db.validate() |
| 631 | for i := 0; i < n; i++ { |
| 632 | if (i % 10000) == 0 { |
| 633 | // Display some progress. Right now, it's not very fast with no caching. |
| 634 | fmt.Printf("Testing i=%d\n", i) |
| 635 | } |
| 636 | k := fmt.Sprintf("%09d", i) |
| 637 | |
| 638 | require.NoError(t, db.View(func(txn *Txn) error { |
| 639 | _, err := txn.Get([]byte(k)) |
| 640 | require.Error(t, err) |
| 641 | return nil |
nothing calls this directly
no test coverage detected
searching dependent graphs…