You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by GitBox <gi...@apache.org> on 2020/11/10 06:06:18 UTC

[GitHub] [incubator-pegasus] levy5307 commented on a change in pull request #639: feat(hotkey): add unit test of internal_collector

levy5307 commented on a change in pull request #639:
URL: https://github.com/apache/incubator-pegasus/pull/639#discussion_r520307504



##########
File path: src/server/test/hotkey_collector_test.cpp
##########
@@ -0,0 +1,162 @@
+#include "server/hotkey_collector.h"
+
+#include <dsn/utility/rand.h>
+#include "pegasus_server_test_base.h"
+
+namespace pegasus {
+namespace server {
+
+static std::string generate_hash_key_by_random(bool is_hotkey, int probability = 100)
+{
+    if (is_hotkey && (dsn::rand::next_u32(100) < probability)) {
+        return "ThisisahotkeyThisisahotkey";
+    }
+    static const std::string chars("abcdefghijklmnopqrstuvwxyz"
+                                   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                                   "1234567890"
+                                   "!@#$%^&*()"
+                                   "`~-_=+[{]{\\|;:'\",<.>/? ");
+    std::string result;
+    for (int i = 0; i < 20; i++) {
+        result += chars[dsn::rand::next_u32(chars.size())];
+    }
+    return result;
+}
+
+TEST(hotkey_collector_test, get_bucket_id_test)
+{
+    int bucket_id = -1;
+    bucket_id = get_bucket_id(dsn::blob::create_from_bytes(generate_hash_key_by_random(false)));
+    ASSERT_NE(bucket_id, -1);
+}
+
+TEST(hotkey_collector_test, find_outlier_index_test)
+{
+    int threshold = 3;
+    int hot_index;
+    bool if_find_hot_index;
+
+    if_find_hot_index = find_outlier_index({1, 2, 3}, threshold, hot_index);
+    ASSERT_EQ(if_find_hot_index, false);
+    ASSERT_EQ(hot_index, -1);
+
+    if_find_hot_index = find_outlier_index({1, 2, 100000}, threshold, hot_index);
+    ASSERT_EQ(if_find_hot_index, true);
+    ASSERT_EQ(hot_index, 2);
+
+    if_find_hot_index = find_outlier_index({1, 10000, 2, 3, 4, 10000000, 6}, threshold, hot_index);
+    ASSERT_EQ(if_find_hot_index, true);
+    ASSERT_EQ(hot_index, 5);
+
+    if_find_hot_index = find_outlier_index(
+        {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, threshold, hot_index);
+    ASSERT_EQ(if_find_hot_index, false);
+    ASSERT_EQ(hot_index, -1);
+}
+
+class coarse_collector_test : public pegasus_server_test_base
+{
+public:
+    coarse_collector_test() : coarse_collector(_server.get()){};
+
+    hotkey_coarse_data_collector coarse_collector;
+
+    bool if_empty()
+    {
+        int empty = true;
+        for (const auto &iter : coarse_collector._hash_buckets) {
+            if (iter.load() != 0) {
+                empty = false;

Review comment:
       I think you should add a break here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org