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.

47 lines
1.2 KiB

  1. package segment
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/message_fbs"
  4. flatbuffers "github.com/google/flatbuffers/go"
  5. "github.com/stretchr/testify/assert"
  6. "testing"
  7. )
  8. func TestMessageSerde(t *testing.T) {
  9. b := flatbuffers.NewBuilder(1024)
  10. prop := make(map[string]string)
  11. prop["n1"] = "v1"
  12. prop["n2"] = "v2"
  13. CreateMessage(b, 1, 2, 3, 4, 5, 6, prop,
  14. []byte("the primary key"), []byte("body is here"))
  15. buf := b.FinishedBytes()
  16. println("serialized size", len(buf))
  17. m := message_fbs.GetRootAsMessage(buf, 0)
  18. assert.Equal(t, int32(1), m.ProducerId())
  19. assert.Equal(t, int64(2), m.ProducerSeq())
  20. assert.Equal(t, int32(3), m.SegmentId())
  21. assert.Equal(t, int64(4), m.SegmentSeq())
  22. assert.Equal(t, int64(5), m.EventTsNs())
  23. assert.Equal(t, int64(6), m.RecvTsNs())
  24. assert.Equal(t, 2, m.PropertiesLength())
  25. nv := &message_fbs.NameValue{}
  26. m.Properties(nv, 0)
  27. assert.Equal(t, "n1", string(nv.Name()))
  28. assert.Equal(t, "v1", string(nv.Value()))
  29. m.Properties(nv, 1)
  30. assert.Equal(t, "n2", string(nv.Name()))
  31. assert.Equal(t, "v2", string(nv.Value()))
  32. assert.Equal(t, []byte("the primary key"), m.Key())
  33. assert.Equal(t, []byte("body is here"), m.Data())
  34. m.MutateSegmentSeq(123)
  35. assert.Equal(t, int64(123), m.SegmentSeq())
  36. }