@@ -189,4 +189,27 @@ TEST_F(CacheInputStreamTest, test_file_overwrite) {
189
189
ASSERT_EQ (stats2.read_cache_count , 0 );
190
190
}
191
191
192
+ TEST_F (CacheInputStreamTest, test_read_with_zero_range) {
193
+ const int64_t block_count = 1 ;
194
+ int64_t data_size = block_size * block_count;
195
+ char data[data_size + 1 ];
196
+ gen_test_data (data, data_size, block_size);
197
+
198
+ std::shared_ptr<io::SeekableInputStream> stream (new MockSeekableInputStream (data, data_size));
199
+ io::CacheInputStream cache_stream (stream, " test_file4" , data_size, 1000000 );
200
+ cache_stream.set_enable_populate_cache (true );
201
+ auto & stats = cache_stream.stats ();
202
+
203
+ // read from backend, cache the data
204
+ char buffer[block_size];
205
+ read_stream_data (&cache_stream, 0 , block_size, buffer);
206
+ ASSERT_TRUE (check_data_content (buffer, block_size, ' a' ));
207
+ ASSERT_EQ (stats.read_cache_count , 0 );
208
+ ASSERT_EQ (stats.write_cache_count , 1 );
209
+
210
+ // try read zero length data, expect no crash
211
+ read_stream_data (&cache_stream, 0 , 0 , nullptr );
212
+ ASSERT_EQ (stats.read_cache_count , 0 );
213
+ }
214
+
192
215
} // namespace starrocks::io
0 commit comments