Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: common/recordio/reader_test.go

Issue 1834123002: common/recordio: Add zero-copy buffer split. (Closed) Base URL: https://github.com/luci/luci-go@symlink-clean
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/recordio/reader.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/recordio/reader_test.go
diff --git a/common/recordio/reader_test.go b/common/recordio/reader_test.go
index 74f2f41aef5f1ae348e3c79c005bbe8580926d44..5e4744c73d003780f91a32b6dc6f681fd28fa21c 100644
--- a/common/recordio/reader_test.go
+++ b/common/recordio/reader_test.go
@@ -8,6 +8,7 @@ import (
"bytes"
"encoding/binary"
"errors"
+ "fmt"
"io"
"io/ioutil"
"testing"
@@ -58,6 +59,14 @@ func (r *testByteReader) ReadByte() (b byte, err error) {
return
}
+func btos(b ...[]byte) []string {
+ s := make([]string, len(b))
+ for i, v := range b {
+ s[i] = string(v)
+ }
+ return s
+}
+
// TestReader tests the default Reader implementation, "reader".
func TestReader(t *testing.T) {
t.Parallel()
@@ -205,3 +214,43 @@ func TestReader(t *testing.T) {
})
})
}
+
+func TestSplit(t *testing.T) {
+ t.Parallel()
+
+ Convey(`Testing Split`, t, func() {
+ for _, v := range [][]string{
+ {},
+ {""},
+ {"", "foo", ""},
+ {"foo", "bar", "baz"},
+ } {
+ Convey(fmt.Sprintf(`Can Split stream: %#v`, v), func() {
+ // Write frames to "buf".
+ var buf bytes.Buffer
+ for _, s := range v {
+ _, err := WriteFrame(&buf, []byte(s))
+ if err != nil {
+ panic(err)
+ }
+ }
+
+ // Confirm that Split works.
+ sp, err := Split(buf.Bytes())
+ So(err, ShouldBeNil)
+ So(btos(sp...), ShouldResemble, v)
+ })
+ }
+
+ Convey(`Will refuse to split a frame that is too large.`, func() {
+ _, err := Split([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00})
+ So(err, ShouldEqual, ErrFrameTooLarge)
+ })
+
+ Convey(`Will fail to split if there aren't enough bytes.`, func() {
+ sp, err := Split([]byte{0x01, 0xAA, 0x02}) // 1-byte {0xAA}, 2-bytes ... EOF!
+ So(sp, ShouldResemble, [][]byte{{0xAA}})
+ So(err, ShouldEqual, ErrFrameTooLarge)
+ })
+ })
+}
« no previous file with comments | « common/recordio/reader.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698