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.

82 lines
2.2 KiB

3 years ago
  1. package needle
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/storage/backend"
  5. "io"
  6. "os"
  7. "testing"
  8. "github.com/seaweedfs/seaweedfs/weed/storage/types"
  9. )
  10. func TestPageRead(t *testing.T) {
  11. baseFileName := "43"
  12. offset := int64(8)
  13. size := types.Size(1153890) // actual file size 1153862
  14. datFile, err := os.OpenFile(baseFileName+".dat", os.O_RDONLY, 0644)
  15. if err != nil {
  16. t.Fatalf("Open Volume Data File [ERROR]: %v", err)
  17. }
  18. datBackend := backend.NewDiskFile(datFile)
  19. defer datBackend.Close()
  20. {
  21. n := new(Needle)
  22. bytes, err := ReadNeedleBlob(datBackend, offset, size, Version3)
  23. if err != nil {
  24. t.Fatalf("readNeedleBlob: %v", err)
  25. }
  26. if err = n.ReadBytes(bytes, offset, size, Version3); err != nil {
  27. t.Fatalf("readNeedleBlob: %v", err)
  28. }
  29. fmt.Printf("bytes len %d\n", len(bytes))
  30. fmt.Printf("name %s size %d\n", n.Name, n.Size)
  31. fmt.Printf("id %d\n", n.Id)
  32. fmt.Printf("DataSize %d\n", n.DataSize)
  33. fmt.Printf("Flags %v\n", n.Flags)
  34. fmt.Printf("NameSize %d\n", n.NameSize)
  35. fmt.Printf("MimeSize %d\n", n.MimeSize)
  36. fmt.Printf("PairsSize %d\n", n.PairsSize)
  37. fmt.Printf("LastModified %d\n", n.LastModified)
  38. fmt.Printf("AppendAtNs %d\n", n.AppendAtNs)
  39. fmt.Printf("Checksum %d\n", n.Checksum)
  40. }
  41. {
  42. n, bytes, bodyLength, err := ReadNeedleHeader(datBackend, Version3, offset)
  43. if err != nil {
  44. t.Fatalf("ReadNeedleHeader: %v", err)
  45. }
  46. fmt.Printf("bytes len %d\n", len(bytes))
  47. fmt.Printf("name %s size %d bodyLength:%d\n", n.Name, n.Size, bodyLength)
  48. }
  49. {
  50. n := new(Needle)
  51. err := n.ReadNeedleMeta(datBackend, offset, size, Version3)
  52. if err != nil {
  53. t.Fatalf("ReadNeedleHeader: %v", err)
  54. }
  55. fmt.Printf("name %s size %d\n", n.Name, n.Size)
  56. fmt.Printf("id %d\n", n.Id)
  57. fmt.Printf("DataSize %d\n", n.DataSize)
  58. fmt.Printf("Flags %v\n", n.Flags)
  59. fmt.Printf("NameSize %d\n", n.NameSize)
  60. fmt.Printf("MimeSize %d\n", n.MimeSize)
  61. fmt.Printf("PairsSize %d\n", n.PairsSize)
  62. fmt.Printf("LastModified %d\n", n.LastModified)
  63. fmt.Printf("AppendAtNs %d\n", n.AppendAtNs)
  64. fmt.Printf("Checksum %d\n", n.Checksum)
  65. buf := make([]byte, 1024)
  66. if err = n.ReadNeedleDataInto(datBackend, offset, buf, io.Discard, 0, int64(n.DataSize)); err != nil {
  67. t.Fatalf("ReadNeedleDataInto: %v", err)
  68. }
  69. }
  70. }