You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.4 KiB

  1. //go:build rocksdb
  2. // +build rocksdb
  3. package rocksdb
  4. import (
  5. "context"
  6. "fmt"
  7. "os"
  8. "testing"
  9. "time"
  10. "github.com/chrislusf/seaweedfs/weed/filer"
  11. "github.com/chrislusf/seaweedfs/weed/util"
  12. )
  13. func TestCreateAndFind(t *testing.T) {
  14. testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
  15. dir := t.TempDir()
  16. store := &RocksDBStore{}
  17. store.initialize(dir)
  18. testFiler.SetStore(store)
  19. fullpath := util.FullPath("/home/chris/this/is/one/file1.jpg")
  20. ctx := context.Background()
  21. entry1 := &filer.Entry{
  22. FullPath: fullpath,
  23. Attr: filer.Attr{
  24. Mode: 0440,
  25. Uid: 1234,
  26. Gid: 5678,
  27. },
  28. }
  29. if err := testFiler.CreateEntry(ctx, entry1, false, false, nil, false); err != nil {
  30. t.Errorf("create entry %v: %v", entry1.FullPath, err)
  31. return
  32. }
  33. entry, err := testFiler.FindEntry(ctx, fullpath)
  34. if err != nil {
  35. t.Errorf("find entry: %v", err)
  36. return
  37. }
  38. if entry.FullPath != entry1.FullPath {
  39. t.Errorf("find wrong entry: %v", entry.FullPath)
  40. return
  41. }
  42. // checking one upper directory
  43. entries, _, _ := testFiler.ListDirectoryEntries(ctx, util.FullPath("/home/chris/this/is/one"), "", false, 100, "", "", "")
  44. if len(entries) != 1 {
  45. t.Errorf("list entries count: %v", len(entries))
  46. return
  47. }
  48. // checking one upper directory
  49. entries, _, _ = testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "", "", "")
  50. if len(entries) != 1 {
  51. t.Errorf("list entries count: %v", len(entries))
  52. return
  53. }
  54. }
  55. func TestEmptyRoot(t *testing.T) {
  56. testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
  57. dir := t.TempDir()
  58. store := &RocksDBStore{}
  59. store.initialize(dir)
  60. testFiler.SetStore(store)
  61. ctx := context.Background()
  62. // checking one upper directory
  63. entries, _, err := testFiler.ListDirectoryEntries(ctx, util.FullPath("/"), "", false, 100, "", "", "")
  64. if err != nil {
  65. t.Errorf("list entries: %v", err)
  66. return
  67. }
  68. if len(entries) != 0 {
  69. t.Errorf("list entries count: %v", len(entries))
  70. return
  71. }
  72. }
  73. func BenchmarkInsertEntry(b *testing.B) {
  74. testFiler := filer.NewFiler(nil, nil, "", 0, "", "", "", nil)
  75. dir := b.TempDir()
  76. store := &RocksDBStore{}
  77. store.initialize(dir)
  78. testFiler.SetStore(store)
  79. ctx := context.Background()
  80. b.ReportAllocs()
  81. for i := 0; i < b.N; i++ {
  82. entry := &filer.Entry{
  83. FullPath: util.FullPath(fmt.Sprintf("/file%d.txt", i)),
  84. Attr: filer.Attr{
  85. Crtime: time.Now(),
  86. Mtime: time.Now(),
  87. Mode: os.FileMode(0644),
  88. },
  89. }
  90. store.InsertEntry(ctx, entry)
  91. }
  92. }