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

Protected Member Functions

void SetUp () override
 
void runSimpleIOBufTest (const DataHolder &dh)
 
void runSimpleStringTest (const DataHolder &dh)
 

Private Member Functions

std::unique_ptr< IOBufsplit (std::unique_ptr< IOBuf > data) const
 

Private Attributes

uint64_t uncompressedLength_
 
size_t chunks_
 
std::unique_ptr< Codeccodec_
 

Detailed Description

Definition at line 197 of file CompressionTest.cpp.

Member Function Documentation

void folly::io::test::CompressionTest::runSimpleIOBufTest ( const DataHolder dh)
protected

Definition at line 221 of file CompressionTest.cpp.

References codec_, folly::io::test::DataHolder::data(), EXPECT_EQ, EXPECT_LE, folly::io::test::DataHolder::hash(), folly::io::test::hashIOBuf(), folly::split(), and folly::IOBuf::wrapBuffer().

221  {
222  const auto original = split(IOBuf::wrapBuffer(dh.data(uncompressedLength_)));
223  const auto compressed = split(codec_->compress(original.get()));
224  EXPECT_LE(
225  compressed->computeChainDataLength(),
226  codec_->maxCompressedLength(uncompressedLength_));
227  if (!codec_->needsUncompressedLength()) {
228  auto uncompressed = codec_->uncompress(compressed.get());
229  EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
230  EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
231  }
232  {
233  auto uncompressed =
234  codec_->uncompress(compressed.get(), uncompressedLength_);
235  EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
236  EXPECT_EQ(dh.hash(uncompressedLength_), hashIOBuf(uncompressed.get()));
237  }
238 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
Definition: IOBuf.cpp:353
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< Codec > codec_
uint64_t hashIOBuf(const IOBuf *buf)
std::unique_ptr< IOBuf > split(std::unique_ptr< IOBuf > data) const
void folly::io::test::CompressionTest::runSimpleStringTest ( const DataHolder dh)
protected

Definition at line 240 of file CompressionTest.cpp.

References codec_, folly::io::test::DataHolder::data(), folly::Range< Iter >::data(), EXPECT_EQ, EXPECT_LE, and string.

240  {
241  const auto original = std::string(
242  reinterpret_cast<const char*>(dh.data(uncompressedLength_).data()),
244  const auto compressed = codec_->compress(original);
245  EXPECT_LE(
246  compressed.length(), codec_->maxCompressedLength(uncompressedLength_));
247 
248  if (!codec_->needsUncompressedLength()) {
249  auto uncompressed = codec_->uncompress(compressed);
250  EXPECT_EQ(uncompressedLength_, uncompressed.length());
251  EXPECT_EQ(uncompressed, original);
252  }
253  {
254  auto uncompressed = codec_->uncompress(compressed, uncompressedLength_);
255  EXPECT_EQ(uncompressedLength_, uncompressed.length());
256  EXPECT_EQ(uncompressed, original);
257  }
258 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< Codec > codec_
const char * string
Definition: Conv.cpp:212
void folly::io::test::CompressionTest::SetUp ( )
inlineoverrideprotected

Definition at line 200 of file CompressionTest.cpp.

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

200  {
201  auto tup = GetParam();
202  int lengthLog = std::get<0>(tup);
203  // Small hack to test empty data
204  uncompressedLength_ = (lengthLog < 0) ? 0 : uint64_t(1) << std::get<0>(tup);
205  chunks_ = std::get<1>(tup);
206  codec_ = getCodec(std::get<2>(tup));
207  }
std::unique_ptr< Codec > codec_
std::unique_ptr< Codec > getCodec(CodecType type, int level)
std::unique_ptr< IOBuf > folly::io::test::CompressionTest::split ( std::unique_ptr< IOBuf data) const
private

Definition at line 261 of file CompressionTest.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::copyBuffer(), i, folly::IOBufQueue::move(), folly::Random::rand64(), folly::size(), and folly::split().

262  {
263  if (data->isChained()) {
264  data->coalesce();
265  }
266 
267  const size_t size = data->computeChainDataLength();
268 
269  std::multiset<size_t> splits;
270  for (size_t i = 1; i < chunks_; ++i) {
271  splits.insert(Random::rand64(size));
272  }
273 
274  folly::IOBufQueue result;
275 
276  size_t offset = 0;
277  for (size_t split : splits) {
278  result.append(IOBuf::copyBuffer(data->data() + offset, split - offset));
279  offset = split;
280  }
281  result.append(IOBuf::copyBuffer(data->data() + offset, size - offset));
282 
283  return result.move();
284 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
std::unique_ptr< IOBuf > split(std::unique_ptr< IOBuf > data) const
static uint64_t rand64()
Definition: Random.h:263
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587

Member Data Documentation

size_t folly::io::test::CompressionTest::chunks_
private

Definition at line 217 of file CompressionTest.cpp.

std::unique_ptr<Codec> folly::io::test::CompressionTest::codec_
private

Definition at line 218 of file CompressionTest.cpp.

uint64_t folly::io::test::CompressionTest::uncompressedLength_
private

Definition at line 216 of file CompressionTest.cpp.


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