paging_util_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * EliasDB
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. */
  10. package paging
  11. import (
  12. "testing"
  13. "devt.de/krotik/eliasdb/storage/file"
  14. "devt.de/krotik/eliasdb/storage/paging/view"
  15. )
  16. func TestFreePhysicalSlotManagerScale(t *testing.T) {
  17. sf, err := file.NewDefaultStorageFile(DBDIR+"/test5", false)
  18. if err != nil {
  19. t.Error(err.Error())
  20. return
  21. }
  22. psf, err := NewPagedStorageFile(sf)
  23. if err != nil {
  24. t.Error(err)
  25. return
  26. }
  27. if pc, err := CountPages(psf, view.TypeDataPage); pc != 0 || err != nil {
  28. t.Error("Unexpected page count result:", pc, err)
  29. }
  30. for i := 0; i < 5; i++ {
  31. _, err := psf.AllocatePage(view.TypeDataPage)
  32. if err != nil {
  33. t.Error(err)
  34. }
  35. if pc, err := CountPages(psf, view.TypeDataPage); pc != i+1 || err != nil {
  36. t.Error("Unexpected page count result:", pc, err)
  37. }
  38. }
  39. if pc, err := CountPages(psf, view.TypeDataPage); pc != 5 || err != nil {
  40. t.Error("Unexpected page count result:", pc, err)
  41. }
  42. r, err := sf.Get(1)
  43. if err != nil {
  44. t.Error(err)
  45. return
  46. }
  47. if pc, err := CountPages(psf, view.TypeDataPage); pc != -1 || err != file.ErrAlreadyInUse {
  48. t.Error("Unexpected page count result:", pc, err)
  49. return
  50. }
  51. sf.ReleaseInUse(r)
  52. r, err = sf.Get(3)
  53. if err != nil {
  54. t.Error(err)
  55. return
  56. }
  57. if pc, err := CountPages(psf, view.TypeDataPage); pc != -1 || err != file.ErrAlreadyInUse {
  58. t.Error("Unexpected page count result:", pc, err)
  59. return
  60. }
  61. sf.ReleaseInUse(r)
  62. if err := psf.Close(); err != nil {
  63. t.Error(err)
  64. return
  65. }
  66. }