mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-04 11:55:51 +00:00
Fixes #932 Also fixes #966 Decided not to add Summary type because it has the same functionality as Histogram but makes more calculations on client side (Clio side). See https://prometheus.io/docs/practices/histograms for detailed comparison.
58 lines
2.0 KiB
C++
58 lines
2.0 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of clio: https://github.com/XRPLF/clio
|
|
Copyright (c) 2023, the clio developers.
|
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <util/prometheus/OStream.h>
|
|
|
|
#include <boost/iostreams/filter/gzip.hpp>
|
|
#include <gtest/gtest.h>
|
|
|
|
using namespace util::prometheus;
|
|
|
|
TEST(OStreamTests, empty)
|
|
{
|
|
OStream stream{false};
|
|
EXPECT_EQ(std::move(stream).data(), "");
|
|
}
|
|
|
|
TEST(OStreamTests, string)
|
|
{
|
|
OStream stream{false};
|
|
stream << "hello";
|
|
EXPECT_EQ(std::move(stream).data(), "hello");
|
|
}
|
|
|
|
TEST(OStreamTests, compression)
|
|
{
|
|
OStream stream{true};
|
|
std::string const str = "helloooooooooooooooooooooooooooooooooo";
|
|
stream << str;
|
|
auto const compressed = std::move(stream).data();
|
|
EXPECT_LT(compressed.size(), str.size());
|
|
|
|
std::string const decompressed = [&compressed]() {
|
|
std::string result;
|
|
boost::iostreams::filtering_istream stream;
|
|
stream.push(boost::iostreams::gzip_decompressor{});
|
|
stream.push(boost::iostreams::array_source{compressed.data(), compressed.size()});
|
|
stream >> result;
|
|
return result;
|
|
}();
|
|
EXPECT_EQ(decompressed, str);
|
|
}
|