2022-03-09 02:03:04 +00:00
|
|
|
#include <snappy.h>
|
2022-03-10 01:46:43 +00:00
|
|
|
#include <IO/HadoopSnappyReadBuffer.h>
|
|
|
|
#include <gtest/gtest.h>
|
2022-03-09 02:03:04 +00:00
|
|
|
|
|
|
|
#include <IO/ReadBufferFromFile.h>
|
2022-03-10 01:46:43 +00:00
|
|
|
#include <IO/ReadBufferFromString.h>
|
2022-03-09 02:03:04 +00:00
|
|
|
#include <IO/WriteBufferFromFile.h>
|
|
|
|
#include <IO/WriteBufferFromString.h>
|
2022-03-10 01:46:43 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <IO/copyData.h>
|
2022-03-09 02:03:04 +00:00
|
|
|
#include <Poco/Base64Decoder.h>
|
|
|
|
#include <Poco/Base64Encoder.h>
|
2022-03-10 01:46:43 +00:00
|
|
|
#include <Poco/MemoryStream.h>
|
2022-03-09 02:03:04 +00:00
|
|
|
#include <Poco/StreamCopier.h>
|
|
|
|
#include <Poco/String.h>
|
|
|
|
#include <Common/SipHash.h>
|
|
|
|
#include <Common/hex.h>
|
|
|
|
using namespace DB;
|
2022-03-10 01:46:43 +00:00
|
|
|
TEST(HadoopSnappyDecoder, repeatNeedMoreInput)
|
2022-03-09 02:03:04 +00:00
|
|
|
{
|
2022-03-10 01:46:43 +00:00
|
|
|
String snappy_base64_content = "AAAl6gAAB67qSzQyMDIxLTA2LTAxAXh4eGIEACQzMTkuNzQyNDMKnjEAHDQyLjgyMTcynjEAIDI5Ni4yODQwNqIxA"
|
|
|
|
"BgyNy43MjYzqpMAGDMuNTIyMzSiYgAcNjUuNDk1OTeiMQAYOTQuNTg1NaYxABg4OC40NzgyojEAHDMyMS4zOTE1os"
|
|
|
|
"QAHDM0Ni4xNTI3qjEAGDEuMjA3MTWm9QAQMi41MjamYQAcMjIuNTEyNDieYQAcMzMwLjI5MTKiGgIcMzIzLjAzNDi"
|
|
|
|
"iwwAcMzE1LjA1MDmiYgAcNDM1Ljc2ODaqxAA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A0M6YaAhA1NC4yNKYkBWEMDsELqmEAFDIuN"
|
|
|
|
"jE4N6LNBxgyODMuNTM1qqUfFDk5Ljc4NKaaGQ5UEAgyNjSuqw2usgkYNDMuMDY0MZ5rAyHkCDMzOa6sHg6+CwAwpn"
|
|
|
|
"YGDnseCDk1MqaoAsHYDDgzNjeiLgsYMjg1LjkzMqZ1EQ67IQgyNTmmMQBB2Qg0OTamuhMUMjcxLjkzqpMWBDMyDoo"
|
|
|
|
"hADSmYgChhAg2NjimeAIQMzkxLjiqyw4IOTkuDt8bpoYBDDk0LjamaQMO4hAIOTI3qqQYFDQyLjk1M6oxAAQ4NA7G"
|
|
|
|
"HaZKIg6YCwwxNzYzpiQXFDkwLjk0OKqqAhQ5Ny4yNzSmvwQANg54GKq/CA4AIQg1MzOm/wMUNTYuNzQ2phcCHDM0N"
|
|
|
|
"S4wOTEyoswHDoAQCDA5M6rOGRA5MS42N6ZPGyQyNzUuNzExMTIK";
|
2022-03-09 02:03:04 +00:00
|
|
|
String snappy_content;
|
|
|
|
Poco::MemoryInputStream istr(snappy_base64_content.data(), snappy_base64_content.size());
|
|
|
|
Poco::Base64Decoder decoder(istr);
|
|
|
|
Poco::StreamCopier::copyToString(decoder, snappy_content);
|
|
|
|
auto file_writer = std::make_unique<WriteBufferFromFile>("./test.snappy");
|
|
|
|
file_writer->write(snappy_content.c_str(), snappy_content.size());
|
|
|
|
file_writer->close();
|
|
|
|
std::unique_ptr<ReadBuffer> in = std::make_unique<ReadBufferFromFile>("./test.snappy", 128);
|
|
|
|
HadoopSnappyReadBuffer read_buffer(std::move(in));
|
|
|
|
String output;
|
|
|
|
WriteBufferFromString out(output);
|
|
|
|
copyData(read_buffer, out);
|
|
|
|
UInt128 hashcode = sipHash128(output.c_str(), output.size());
|
|
|
|
String hashcode_str = getHexUIntLowercase(hashcode);
|
|
|
|
ASSERT_EQ(hashcode_str, "593afe14f61866915cc00b8c7bd86046");
|
|
|
|
}
|