@@ -4,7 +4,7 @@ mod common;
4
4
#[ cfg( feature = "integration-test" ) ]
5
5
mod test {
6
6
use crate :: common:: TEST_FILE_INTS ;
7
- use bytes:: Buf ;
7
+ use bytes:: { Buf , BytesMut } ;
8
8
use hdfs_native:: {
9
9
minidfs:: { DfsFeatures , MiniDfs } ,
10
10
Client , Result , WriteOptions ,
@@ -60,7 +60,7 @@ mod test {
60
60
file. close ( ) . await ?;
61
61
62
62
// Read the whole file
63
- let reader = client. read ( "/testfile" ) . await ?;
63
+ let mut reader = client. read ( "/testfile" ) . await ?;
64
64
let mut buf = reader. read_range ( 0 , TEST_FILE_INTS * 4 ) . await ?;
65
65
for i in 0 ..TEST_FILE_INTS as i32 {
66
66
assert_eq ! ( buf. get_i32( ) , i) ;
@@ -82,6 +82,26 @@ mod test {
82
82
offset += 1024 * 1024 ;
83
83
}
84
84
85
+ // Positioned reads
86
+ let mut buf = reader. read ( reader. file_length ( ) ) . await ?;
87
+ for i in 0 ..TEST_FILE_INTS as i32 {
88
+ assert_eq ! ( buf. get_i32( ) , i) ;
89
+ }
90
+
91
+ reader. seek ( 0 ) ;
92
+
93
+ let mut buf = BytesMut :: zeroed ( reader. file_length ( ) ) ;
94
+ assert_eq ! ( reader. read_buf( & mut buf) . await ?, reader. file_length( ) ) ;
95
+ for i in 0 ..TEST_FILE_INTS as i32 {
96
+ assert_eq ! ( buf. get_i32( ) , i) ;
97
+ }
98
+
99
+ // Trying to read again should return nothing
100
+ assert ! ( reader. read( 1 ) . await ?. is_empty( ) ) ;
101
+
102
+ // Same with reading into a provided buffer
103
+ assert_eq ! ( reader. read_buf( & mut [ 0u8 ] ) . await ?, 0 ) ;
104
+
85
105
Ok ( ( ) )
86
106
}
87
107
}
0 commit comments