aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-05-19 13:15:47 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-05-19 13:15:47 +0000
commit7292aeb064b53c1a72c57ce8d3ad8e0c7886e446 (patch)
treed92c5fd725189d08ebdea00693600d4924137925 /storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp
parentb875d128cd2ca5368c2a3ab1dc3e185c62c4a237 (diff)
Fold storageapi into storage.
Diffstat (limited to 'storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp')
-rw-r--r--storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp b/storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp
new file mode 100644
index 00000000000..ea59fefc924
--- /dev/null
+++ b/storage/src/tests/storageapi/messageapi/storage_message_address_test.cpp
@@ -0,0 +1,40 @@
+// Copyright Yahoo. 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(const vespalib::string & 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));
+ EXPECT_EQ(hash_of("foo", lib::NodeType::STORAGE, 0),
+ hash_of("bar", lib::NodeType::STORAGE, 0));
+
+ // 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("foo", lib::NodeType::DISTRIBUTOR, 0));
+ EXPECT_NE(hash_of("foo", lib::NodeType::STORAGE, 0),
+ hash_of("foo", lib::NodeType::STORAGE, 1));
+
+ EXPECT_EQ(16u, sizeof(StorageMessageAddress));
+ EXPECT_EQ(72u, sizeof(StorageMessage));
+ EXPECT_EQ(16u, sizeof(mbus::Trace));
+}
+
+} // storage::api