github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/chunked_buffer_test.cc (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  #include <gtest/gtest.h>
    12  #include "chunked_buffer.h"
    13  
    14  // Verify we can a chunked buffer can hold more than 2GB of data when
    15  // writing in pieces that are smaller than the maximum chunk size (128
    16  // MB). See #32896.
    17  TEST(ChunkedBuffer, PutSmall) {
    18    const std::string data(1 << 20, '.');  // 1 MB
    19    const int64_t total = 3LL << 30;       // 3 GB
    20    cockroach::chunkedBuffer buf;
    21    for (int64_t sum = 0; sum < total; sum += data.size()) {
    22      buf.Put(data, data);
    23    }
    24  }
    25  
    26  // Verify we can a chunked buffer can hold more than 2GB of data when
    27  // writing in pieces that are larger than the maximum chunk size (128
    28  // MB). See #32896.
    29  TEST(ChunkedBuffer, PutLarge) {
    30    const std::string data(256 << 20, '.');  // 256 MB
    31    const int64_t total = 3LL << 30;         // 3 GB
    32    cockroach::chunkedBuffer buf;
    33    for (int64_t sum = 0; sum < total; sum += data.size()) {
    34      buf.Put(data, data);
    35    }
    36  }