aboutsummaryrefslogtreecommitdiffstats
path: root/storageapi/src/tests/messageapi/storage_message_address_test.cpp
blob: 55adcf46c0d052da28c2950c6c6d97aced259049 (plain) (blame)
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
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/storageapi/messageapi/storagemessage.h>
#include <vespa/vespalib/gtest/gtest.h>

using namespace ::testing;

namespace storage::api {

namespace {

size_t hash_of(vespalib::stringref cluster, const lib::NodeType& type, uint16_t index) {
    return StorageMessageAddress(cluster, type, index).internal_storage_hash();
}

}

TEST(StorageMessageAddressTest, storage_hash_covers_all_expected_fields) {
    EXPECT_EQ(hash_of("foo", lib::NodeType::STORAGE, 0),
              hash_of("foo", lib::NodeType::STORAGE, 0));
    EXPECT_EQ(hash_of("foo", lib::NodeType::DISTRIBUTOR, 0),
              hash_of("foo", lib::NodeType::DISTRIBUTOR, 0));
    EXPECT_EQ(hash_of("foo", lib::NodeType::STORAGE, 123),
              hash_of("foo", lib::NodeType::STORAGE, 123));

    // These tests are all true with extremely high probability, though they do
    // depend on a hash function that may inherently cause collisions.
    EXPECT_NE(hash_of("foo", lib::NodeType::STORAGE, 0),
              hash_of("bar", lib::NodeType::STORAGE, 0));
    EXPECT_NE(hash_of("foo", lib::NodeType::STORAGE, 0),
              hash_of("foo", lib::NodeType::DISTRIBUTOR, 0));
    EXPECT_NE(hash_of("foo", lib::NodeType::STORAGE, 0),
              hash_of("foo", lib::NodeType::STORAGE, 1));

    EXPECT_EQ(112u, sizeof(StorageMessageAddress));
    EXPECT_EQ(64u, sizeof(StorageMessage));
    EXPECT_EQ(16u, sizeof(mbus::Trace));
}

} // storage::api