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.5 KiB

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