MCPcopy
hub / github.com/segmentio/kafka-go / TestXerialFramedCompression

Function TestXerialFramedCompression

compress/snappy/xerial_test.go:63–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestXerialFramedCompression(t *testing.T) {
64 rawData := new(bytes.Buffer)
65 rawData.Grow(1024 * 1024)
66 io.CopyN(rawData, rand.Reader, 1024*1024)
67
68 framedAndCompressedData := new(bytes.Buffer)
69 framedAndCompressedData.Grow(rawData.Len())
70 w := simpleWriter{&xerialWriter{writer: framedAndCompressedData, framed: true, encode: snappy.Encode}}
71 r := simpleReader{bytes.NewReader(rawData.Bytes())}
72 io.Copy(w, r)
73 w.Writer.(*xerialWriter).Flush()
74
75 unframedAndDecompressedData := new(bytes.Buffer)
76 unframedAndDecompressedData.Grow(rawData.Len())
77 io.Copy(unframedAndDecompressedData,
78 simpleReader{&xerialReader{reader: framedAndCompressedData, decode: snappy.Decode}})
79
80 b0 := rawData.Bytes()
81 b1 := unframedAndDecompressedData.Bytes()
82
83 if !bytes.Equal(b0, b1) {
84 t.Error("data mismatch")
85 }
86}
87
88func TestXerialFramedCompressionOptimized(t *testing.T) {
89 rawData := new(bytes.Buffer)

Callers

nothing calls this directly

Calls 5

LenMethod · 0.65
NewReaderMethod · 0.65
BytesMethod · 0.65
FlushMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected