1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/searchlib/transactionlog/chunks.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/log/log.h>
LOG_SETUP("translog_chunks_test");
using namespace search::transactionlog;
using vespalib::ConstBufferRef;
using vespalib::nbostream;
using vespalib::compression::CompressionConfig;
constexpr const char * TEXT = "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz";
void
verifySerializationAndDeserialization(IChunk & org, size_t numEntries) {
for (size_t i(0); i < numEntries; i++) {
const char *start = TEXT + (i%20);
Packet::Entry entry(i, i%8, ConstBufferRef(start, strlen(start)));
org.add(entry);
}
nbostream os;
Encoding encoding = org.encode(os);
auto deserialized = IChunk::create(encoding.getRaw());
deserialized->decode(os);
EXPECT_TRUE(os.empty());
EXPECT_EQUAL(numEntries, deserialized->getEntries().size());
}
TEST("test serialization and deserialization of current default uncompressed xxh64") {
XXH64NoneChunk chunk;
verifySerializationAndDeserialization(chunk, 1);
}
TEST("test serialization and deserialization of legacy uncompressed ccittcrc32") {
CCITTCRC32NoneChunk chunk;
verifySerializationAndDeserialization(chunk, 1);
}
TEST("test serialization and deserialization of future multientry xxh64 lz4 compression") {
for (size_t level(1); level < 9; level++) {
XXH64CompressedChunk chunk(CompressionConfig::Type::LZ4, level);
verifySerializationAndDeserialization(chunk, 100);
}
}
TEST("test serialization and deserialization of future multientry xxh64 zstd compression") {
for (size_t level(1); level < 9; level++) {
XXH64CompressedChunk chunk(CompressionConfig::Type::ZSTD, level);
verifySerializationAndDeserialization(chunk, 100);
}
}
TEST("test serialization and deserialization of future multientry xxh64 no compression") {
XXH64CompressedChunk chunk(CompressionConfig::Type::NONE_MULTI, 1);
verifySerializationAndDeserialization(chunk, 100);
}
TEST_MAIN() { TEST_RUN_ALL(); }
|