@@ -57,9 +57,10 @@ std::vector<TestParams> generateLz4TestParams() {
57
57
Lz4CodecOptions::kLz4Frame ,
58
58
Lz4CodecOptions::kLz4Hadoop }) {
59
59
params.emplace_back (
60
- CompressionKind::CompressionKind_LZ4,
61
- std::make_shared<Lz4CodecOptions>(type));
60
+ CompressionKind_LZ4, std::make_shared<Lz4CodecOptions>(type));
62
61
}
62
+ // Add default CodecOptions.
63
+ params.emplace_back (CompressionKind_LZ4);
63
64
return params;
64
65
}
65
66
@@ -386,14 +387,8 @@ class CodecTest : public ::testing::TestWithParam<TestParams> {
386
387
TEST_P (CodecTest, specifyCompressionLevel) {
387
388
std::vector<uint8_t > data = makeRandomData (2000 );
388
389
const auto kind = getCompressionKind ();
389
- if (!Codec::isAvailable (kind)) {
390
- // Support for this codec hasn't been built.
391
- VELOX_ASSERT_THROW (
392
- Codec::create (kind, kUseDefaultCompressionLevel ),
393
- " Support for codec '" + compressionKindToString (kind) +
394
- " ' is either not built or not implemented." );
395
- return ;
396
- }
390
+ ASSERT_TRUE (Codec::isAvailable (kind));
391
+
397
392
auto codecDefault =
398
393
Codec::create (kind).thenOrThrow (folly::identity, throwsNotOk);
399
394
checkCodecRoundtrip (codecDefault, data);
@@ -421,14 +416,22 @@ TEST_P(CodecTest, getUncompressedLength) {
421
416
compressed.resize (compressedLength);
422
417
423
418
if (Codec::supportsGetUncompressedLength (getCompressionKind ())) {
424
- ASSERT_EQ (
425
- codec->getUncompressedLength (compressed.data (), compressedLength),
426
- inputLength);
419
+ auto uncompressedLength =
420
+ codec->getUncompressedLength (compressed.data (), compressedLength)
421
+ .thenOrThrow (folly::identity, throwsNotOk);
422
+ ASSERT_EQ (uncompressedLength, inputLength);
427
423
} else {
428
- ASSERT_EQ (
429
- codec->getUncompressedLength (compressed.data (), compressedLength),
430
- std::nullopt );
424
+ VELOX_ASSERT_ERROR_STATUS (
425
+ codec->getUncompressedLength (compressed.data (), compressedLength)
426
+ .error (),
427
+ StatusCode::kInvalid ,
428
+ fmt::format (
429
+ " getUncompressedLength is unsupported with {} format." ,
430
+ codec->name ()));
431
431
}
432
+
433
+ // TODO: For codecs that support getUncompressedLength(), verify the error
434
+ // message for corrupted data.
432
435
}
433
436
434
437
TEST_P (CodecTest, codecRoundtrip) {
@@ -440,47 +443,47 @@ TEST_P(CodecTest, codecRoundtrip) {
440
443
}
441
444
442
445
TEST_P (CodecTest, streamingCompressor) {
443
- if (!Codec::supportsStreamingCompression (getCompressionKind ())) {
446
+ const auto codec = makeCodec ();
447
+ if (!codec->supportsStreamingCompression ()) {
444
448
return ;
445
449
}
446
450
447
451
for (auto dataSize : {0 , 10 , 10000 , 100000 }) {
448
- auto codec = makeCodec ();
449
452
checkStreamingCompressor (codec.get (), makeRandomData (dataSize));
450
453
checkStreamingCompressor (codec.get (), makeCompressibleData (dataSize));
451
454
}
452
455
}
453
456
454
457
TEST_P (CodecTest, streamingDecompressor) {
455
- if (!Codec::supportsStreamingCompression (getCompressionKind ())) {
458
+ const auto codec = makeCodec ();
459
+ if (!codec->supportsStreamingCompression ()) {
456
460
return ;
457
461
}
458
462
459
463
for (auto dataSize : {0 , 10 , 10000 , 100000 }) {
460
- auto codec = makeCodec ();
461
464
checkStreamingDecompressor (codec.get (), makeRandomData (dataSize));
462
465
checkStreamingDecompressor (codec.get (), makeCompressibleData (dataSize));
463
466
}
464
467
}
465
468
466
469
TEST_P (CodecTest, streamingRoundtrip) {
467
- if (!Codec::supportsStreamingCompression (getCompressionKind ())) {
470
+ const auto codec = makeCodec ();
471
+ if (!codec->supportsStreamingCompression ()) {
468
472
return ;
469
473
}
470
474
471
475
for (auto dataSize : {0 , 10 , 10000 , 100000 }) {
472
- auto codec = makeCodec ();
473
476
checkStreamingRoundtrip (codec.get (), makeRandomData (dataSize));
474
477
checkStreamingRoundtrip (codec.get (), makeCompressibleData (dataSize));
475
478
}
476
479
}
477
480
478
481
TEST_P (CodecTest, streamingDecompressorReuse) {
479
- if (!Codec::supportsStreamingCompression (getCompressionKind ())) {
482
+ const auto codec = makeCodec ();
483
+ if (!codec->supportsStreamingCompression ()) {
480
484
return ;
481
485
}
482
486
483
- auto codec = makeCodec ();
484
487
const auto & decompressor = makeStreamingDecompressor (codec.get ());
485
488
checkStreamingRoundtrip (
486
489
makeStreamingCompressor (codec.get ()), decompressor, makeRandomData (100 ));
@@ -512,4 +515,16 @@ TEST(CodecLZ4HadoopTest, compatibility) {
512
515
checkCodecRoundtrip (c1, c2, makeRandomData (dataSize));
513
516
}
514
517
}
518
+
519
+ TEST (CodecTestInvalid, invalidKind) {
520
+ CompressionKind kind = CompressionKind_NONE;
521
+ ASSERT_FALSE (Codec::isAvailable (kind));
522
+
523
+ VELOX_ASSERT_ERROR_STATUS (
524
+ Codec::create (kind, kUseDefaultCompressionLevel ).error (),
525
+ StatusCode::kInvalid ,
526
+ fmt::format (
527
+ " Support for codec '{}' is either not built or not implemented." ,
528
+ compressionKindToString (kind)));
529
+ }
515
530
} // namespace facebook::velox::common
0 commit comments