proxygen
folly::io::test::StreamingCompressionTest Class Reference
Inheritance diagram for folly::io::test::StreamingCompressionTest:

Protected Member Functions

bool hasFlush () const
 
void SetUp () override
 
void runResetStreamTest (DataHolder const &dh)
 
void runCompressStreamTest (DataHolder const &dh)
 
void runUncompressStreamTest (DataHolder const &dh)
 
void runFlushTest (DataHolder const &dh)
 

Private Member Functions

std::vector< ByteRangesplit (ByteRange data) const
 

Private Attributes

uint64_t uncompressedLength_
 
size_t chunkSize_
 
std::unique_ptr< StreamCodeccodec_
 

Detailed Description

Definition at line 780 of file CompressionTest.cpp.

Member Function Documentation

bool folly::io::test::StreamingCompressionTest::hasFlush ( ) const
inlineprotected

Definition at line 783 of file CompressionTest.cpp.

References folly::io::test::codecHasFlush().

783  {
784  return codecHasFlush(std::get<2>(GetParam()));
785  }
static bool codecHasFlush(CodecType type)
void folly::io::test::StreamingCompressionTest::runCompressStreamTest ( DataHolder const &  dh)
protected

Definition at line 882 of file CompressionTest.cpp.

References codec_, folly::io::test::compressSome(), folly::io::test::DataHolder::data(), folly::empty(), folly::io::StreamCodec::END, EXPECT_EQ, folly::io::test::DataHolder::hash(), folly::io::test::hashIOBuf(), folly::io::StreamCodec::NONE, and folly::split().

883  {
884  auto const inputs = split(dh.data(uncompressedLength_));
885 
886  IOBufQueue queue;
887  codec_->resetStream(uncompressedLength_);
888  // Compress many inputs in a row
889  for (auto const input : inputs) {
890  queue.append(compressSome(
892  }
893  // Finish the operation with empty input.
895  queue.append(
897 
898  auto const uncompressed = codec_->uncompress(queue.front());
899  EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
900 }
static std::unique_ptr< IOBuf > compressSome(StreamCodec *codec, ByteRange data, uint64_t bufferSize, StreamCodec::FlushOp flush)
std::vector< ByteRange > split(ByteRange data) const
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< StreamCodec > codec_
constexpr auto empty(C const &c) -> decltype(c.empty())
Definition: Access.h:55
uint64_t hashIOBuf(const IOBuf *buf)
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
void folly::io::test::StreamingCompressionTest::runFlushTest ( DataHolder const &  dh)
protected

Definition at line 948 of file CompressionTest.cpp.

References codec_, folly::io::test::compressSome(), folly::io::test::DataHolder::data(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, folly::io::StreamCodec::FLUSH, folly::io::getStreamCodec(), folly::io::test::hashIOBuf(), folly::split(), folly::io::test::uncompressSome(), and folly::IOBuf::wrapBuffer().

948  {
949  auto const inputs = split(dh.data(uncompressedLength_));
950  auto uncodec = getStreamCodec(codec_->type());
951 
952  if (codec_->needsDataLength()) {
953  codec_->resetStream(uncompressedLength_);
954  } else {
955  codec_->resetStream();
956  }
957  for (auto input : inputs) {
958  // Compress some data and flush the stream
959  auto compressed = compressSome(
961  auto compressedRange = compressed->coalesce();
962  // Uncompress the compressed data
963  auto result = uncompressSome(
964  uncodec.get(),
965  compressedRange,
966  chunkSize_,
968  // All compressed data should have been consumed
969  EXPECT_TRUE(compressedRange.empty());
970  // The frame isn't complete
971  EXPECT_FALSE(result.first);
972  // The uncompressed data should be exactly the input data
973  EXPECT_EQ(input.size(), result.second->computeChainDataLength());
974  auto const data = IOBuf::wrapBuffer(input);
975  EXPECT_EQ(hashIOBuf(data.get()), hashIOBuf(result.second.get()));
976  }
977 }
static std::unique_ptr< IOBuf > compressSome(StreamCodec *codec, ByteRange data, uint64_t bufferSize, StreamCodec::FlushOp flush)
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
Definition: IOBuf.cpp:353
std::vector< ByteRange > split(ByteRange data) const
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< StreamCodec > codec_
static std::pair< bool, std::unique_ptr< IOBuf > > uncompressSome(StreamCodec *codec, ByteRange &data, uint64_t bufferSize, StreamCodec::FlushOp flush)
uint64_t hashIOBuf(const IOBuf *buf)
std::unique_ptr< StreamCodec > getStreamCodec(CodecType type, int level)
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void folly::io::test::StreamingCompressionTest::runResetStreamTest ( DataHolder const &  dh)
protected

Definition at line 860 of file CompressionTest.cpp.

References codec_, folly::io::test::compressSome(), folly::io::test::DataHolder::data(), folly::io::StreamCodec::END, EXPECT_EQ, folly::io::test::DataHolder::hash(), folly::io::test::hashIOBuf(), and folly::io::StreamCodec::NONE.

860  {
861  auto const input = dh.data(uncompressedLength_);
862  // Compress some but leave state unclean
863  codec_->resetStream(uncompressedLength_);
865  // Reset stream and compress all
866  if (codec_->needsDataLength()) {
867  codec_->resetStream(uncompressedLength_);
868  } else {
869  codec_->resetStream();
870  }
871  auto compressed =
873  auto const uncompressed = codec_->uncompress(compressed.get(), input.size());
874  EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
875 }
static std::unique_ptr< IOBuf > compressSome(StreamCodec *codec, ByteRange data, uint64_t bufferSize, StreamCodec::FlushOp flush)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< StreamCodec > codec_
uint64_t hashIOBuf(const IOBuf *buf)
void folly::io::test::StreamingCompressionTest::runUncompressStreamTest ( DataHolder const &  dh)
protected

Definition at line 907 of file CompressionTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, codec_, folly::io::test::DataHolder::data(), folly::io::StreamCodec::END, EXPECT_TRUE, folly::io::StreamCodec::FLUSH, folly::io::test::hashIOBuf(), folly::io::StreamCodec::NONE, folly::io::test::uncompressSome(), and folly::IOBuf::wrapBuffer().

908  {
909  const auto flush =
911  auto const data = IOBuf::wrapBuffer(dh.data(uncompressedLength_));
912  // Concatenate 3 compressed frames in a row
913  auto compressed = codec_->compress(data.get());
914  compressed->prependChain(codec_->compress(data.get()));
915  compressed->prependChain(codec_->compress(data.get()));
916  // Pass all 3 compressed frames in one input buffer
917  auto input = compressed->coalesce();
918  // Uncompress the first frame
919  codec_->resetStream(data->computeChainDataLength());
920  {
921  auto const result = uncompressSome(codec_.get(), input, chunkSize_, flush);
922  ASSERT_TRUE(result.first);
923  ASSERT_EQ(hashIOBuf(data.get()), hashIOBuf(result.second.get()));
924  }
925  // Uncompress the second frame
926  codec_->resetStream();
927  {
928  auto const result = uncompressSome(
930  ASSERT_TRUE(result.first);
931  ASSERT_EQ(hashIOBuf(data.get()), hashIOBuf(result.second.get()));
932  }
933  // Uncompress the third frame
934  codec_->resetStream();
935  {
936  auto const result = uncompressSome(codec_.get(), input, chunkSize_, flush);
937  ASSERT_TRUE(result.first);
938  ASSERT_EQ(hashIOBuf(data.get()), hashIOBuf(result.second.get()));
939  }
940  EXPECT_TRUE(input.empty());
941 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
Definition: IOBuf.cpp:353
std::unique_ptr< StreamCodec > codec_
static std::pair< bool, std::unique_ptr< IOBuf > > uncompressSome(StreamCodec *codec, ByteRange &data, uint64_t bufferSize, StreamCodec::FlushOp flush)
uint64_t hashIOBuf(const IOBuf *buf)
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
void folly::io::test::StreamingCompressionTest::SetUp ( )
inlineoverrideprotected

Definition at line 787 of file CompressionTest.cpp.

References codec_, folly::io::test::DataHolder::data(), folly::io::getStreamCodec(), folly::split(), and uint64_t.

787  {
788  auto const tup = GetParam();
789  uncompressedLength_ = uint64_t(1) << std::get<0>(tup);
790  chunkSize_ = size_t(1) << std::get<1>(tup);
791  codec_ = getStreamCodec(std::get<2>(tup));
792  }
std::unique_ptr< StreamCodec > codec_
std::unique_ptr< StreamCodec > getStreamCodec(CodecType type, int level)
std::vector< ByteRange > folly::io::test::StreamingCompressionTest::split ( ByteRange  data) const
private

Definition at line 807 of file CompressionTest.cpp.

References folly::Range< Iter >::empty(), min, folly::Range< Iter >::size(), folly::Range< Iter >::subpiece(), and folly::Range< Iter >::uncheckedAdvance().

807  {
808  size_t const pieces = std::max<size_t>(1, data.size() / chunkSize_);
809  std::vector<ByteRange> result;
810  result.reserve(pieces + 1);
811  while (!data.empty()) {
812  size_t const pieceSize = std::min(data.size(), chunkSize_);
813  result.push_back(data.subpiece(0, pieceSize));
814  data.uncheckedAdvance(pieceSize);
815  }
816  return result;
817 }
LogLevel min
Definition: LogLevel.cpp:30
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71

Member Data Documentation

size_t folly::io::test::StreamingCompressionTest::chunkSize_
private

Definition at line 803 of file CompressionTest.cpp.

std::unique_ptr<StreamCodec> folly::io::test::StreamingCompressionTest::codec_
private

Definition at line 804 of file CompressionTest.cpp.

uint64_t folly::io::test::StreamingCompressionTest::uncompressedLength_
private

Definition at line 802 of file CompressionTest.cpp.


The documentation for this class was generated from the following file: