Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
7e85374b
Commit
7e85374b
authored
May 14, 2019
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UT for returning EAGAIN from the IReader
parent
727dd4cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
3 deletions
+55
-3
recordio.h
src/butil/recordio.h
+1
-1
recordio_unittest.cpp
test/recordio_unittest.cpp
+54
-2
No files found.
src/butil/recordio.h
View file @
7e85374b
...
...
@@ -79,7 +79,7 @@ private:
// Parse records from the IReader, corrupted records will be skipped.
// Example:
// RecordReader rd(
ireader
);
// RecordReader rd(
...
);
// Record rec;
// while (rd.ReadNext(&rec)) {
// // Handle the rec
...
...
test/recordio_unittest.cpp
View file @
7e85374b
...
...
@@ -8,8 +8,11 @@ namespace {
class
StringReader
:
public
butil
::
IReader
{
public
:
StringReader
(
const
std
::
string
&
str
)
:
_str
(
str
),
_offset
(
0
)
{}
StringReader
(
const
std
::
string
&
str
,
bool
report_eagain_on_end
=
false
)
:
_str
(
str
)
,
_offset
(
0
)
,
_report_eagain_on_end
(
report_eagain_on_end
)
{}
ssize_t
ReadV
(
const
iovec
*
iov
,
int
iovcnt
)
override
{
size_t
total_nc
=
0
;
...
...
@@ -25,11 +28,16 @@ public:
break
;
}
}
if
(
_report_eagain_on_end
&&
total_nc
==
0
)
{
errno
=
EAGAIN
;
return
-
1
;
}
return
total_nc
;
}
private
:
std
::
string
_str
;
size_t
_offset
;
bool
_report_eagain_on_end
;
};
class
StringWriter
:
public
butil
::
IWriter
{
...
...
@@ -159,6 +167,50 @@ TEST(RecordIOTest, write_read_basic) {
ASSERT_EQ
(
sw
.
str
().
size
(),
rr
.
read_bytes
());
}
TEST
(
RecordIOTest
,
incomplete_reader
)
{
StringWriter
sw
;
butil
::
RecordWriter
rw
(
&
sw
);
butil
::
Record
src
;
butil
::
IOBuf
*
foo_val
=
src
.
MutableMeta
(
"foo"
);
foo_val
->
append
(
"foo_data"
);
ASSERT_EQ
(
0
,
rw
.
Write
(
src
));
butil
::
IOBuf
*
bar_val
=
src
.
MutableMeta
(
"bar"
);
bar_val
->
append
(
"bar_data"
);
ASSERT_EQ
(
0
,
rw
.
Write
(
src
));
ASSERT_EQ
(
0
,
rw
.
Flush
());
std
::
string
data
=
sw
.
str
();
std
::
cout
<<
"len="
<<
data
.
size
()
<<
" content="
<<
butil
::
PrintedAsBinary
(
data
,
256
)
<<
std
::
endl
;
StringReader
sr
(
data
,
true
);
butil
::
RecordReader
rr
(
&
sr
);
butil
::
Record
r2
;
ASSERT_TRUE
(
rr
.
ReadNext
(
&
r2
));
ASSERT_EQ
(
0
,
rr
.
last_error
());
ASSERT_EQ
((
size_t
)
1
,
r2
.
MetaCount
());
ASSERT_EQ
(
"foo"
,
r2
.
MetaAt
(
0
).
name
);
ASSERT_EQ
(
"foo_data"
,
*
r2
.
MetaAt
(
0
).
data
);
ASSERT_TRUE
(
r2
.
Payload
().
empty
());
butil
::
Record
r3
;
ASSERT_TRUE
(
rr
.
ReadNext
(
&
r3
));
ASSERT_EQ
(
0
,
rr
.
last_error
());
ASSERT_EQ
((
size_t
)
2
,
r3
.
MetaCount
());
ASSERT_EQ
(
"foo"
,
r3
.
MetaAt
(
0
).
name
);
ASSERT_EQ
(
"foo_data"
,
*
r3
.
MetaAt
(
0
).
data
);
ASSERT_EQ
(
"bar"
,
r3
.
MetaAt
(
1
).
name
);
ASSERT_EQ
(
"bar_data"
,
*
r3
.
MetaAt
(
1
).
data
);
ASSERT_TRUE
(
r3
.
Payload
().
empty
());
ASSERT_FALSE
(
rr
.
ReadNext
(
NULL
));
ASSERT_EQ
(
EAGAIN
,
rr
.
last_error
());
ASSERT_EQ
(
sw
.
str
().
size
(),
rr
.
read_bytes
());
}
static
std
::
string
rand_string
(
int
min_len
,
int
max_len
)
{
const
int
len
=
butil
::
fast_rand_in
(
min_len
,
max_len
);
std
::
string
str
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment