package notify import "testing" func TestEncodeDecodeRecordBatchFrameV1(t *testing.T) { batch := []recordOutboundMessage{ {Seq: 7, Payload: []byte("alpha")}, {Seq: 8, Payload: []byte("beta")}, } payload, err := encodeRecordBatchFrame(batch, 0, false) if err != nil { t.Fatalf("encodeRecordBatchFrame v1 failed: %v", err) } frame, err := decodeRecordFrame(payload) if err != nil { t.Fatalf("decodeRecordFrame v1 failed: %v", err) } if got, want := frame.Version, uint8(recordFrameVersionV1); got != want { t.Fatalf("frame version = %d, want %d", got, want) } if got, want := frame.Type, recordFrameTypeBatch; got != want { t.Fatalf("frame type = %d, want %d", got, want) } if frame.AckSeq != 0 { t.Fatalf("frame ack seq = %d, want 0", frame.AckSeq) } if got, want := len(frame.Batch), len(batch); got != want { t.Fatalf("batch len = %d, want %d", got, want) } for i := range batch { if got, want := frame.Batch[i].Seq, batch[i].Seq; got != want { t.Fatalf("batch[%d].seq = %d, want %d", i, got, want) } if got, want := string(frame.Batch[i].Payload), string(batch[i].Payload); got != want { t.Fatalf("batch[%d].payload = %q, want %q", i, got, want) } } } func TestEncodeDecodeRecordBatchFrameV2CarriesAckSeq(t *testing.T) { batch := []recordOutboundMessage{ {Seq: 11, Payload: []byte("alpha")}, {Seq: 12, Payload: []byte("beta")}, } payload, err := encodeRecordBatchFrame(batch, 9, true) if err != nil { t.Fatalf("encodeRecordBatchFrame v2 failed: %v", err) } frame, err := decodeRecordFrame(payload) if err != nil { t.Fatalf("decodeRecordFrame v2 failed: %v", err) } if got, want := frame.Version, uint8(recordFrameVersionV2); got != want { t.Fatalf("frame version = %d, want %d", got, want) } if got, want := frame.Type, recordFrameTypeBatch; got != want { t.Fatalf("frame type = %d, want %d", got, want) } if got, want := frame.AckSeq, uint64(9); got != want { t.Fatalf("frame ack seq = %d, want %d", got, want) } if got, want := len(frame.Batch), len(batch); got != want { t.Fatalf("batch len = %d, want %d", got, want) } for i := range batch { if got, want := frame.Batch[i].Seq, batch[i].Seq; got != want { t.Fatalf("batch[%d].seq = %d, want %d", i, got, want) } if got, want := string(frame.Batch[i].Payload), string(batch[i].Payload); got != want { t.Fatalf("batch[%d].payload = %q, want %q", i, got, want) } } }