Smityz commented on a change in pull request #842:
URL: https://github.com/apache/incubator-pegasus/pull/842#discussion_r757340534



##########
File path: src/test/function_test/test_throttle.cpp
##########
@@ -0,0 +1,790 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <dsn/utility/filesystem.h>
+#include <dsn/dist/replication/replication_ddl_client.h>
+#include <pegasus/client.h>
+#include <gtest/gtest.h>
+#include <dsn/utility/TokenBucket.h>
+#include <dsn/service_api_cpp.h>
+#include <dsn/dist/fmt_logging.h>
+#include <fstream>
+
+#include "base/pegasus_const.h"
+#include "global_env.h"
+#include "utils.h"
+
+using namespace dsn;
+using namespace dsn::replication;
+using namespace pegasus;
+
+enum class throttle_type
+{
+    read_by_qps,
+    read_by_size,
+    write_by_qps,
+    write_by_size
+};
+
+enum class operation_type
+{
+    get,
+    multi_get,
+    set,
+    multi_set
+};
+
+struct throttle_test_plan
+{
+    std::string test_plan_case;
+    operation_type ot;
+    int single_value_sz;
+    int multi_count;
+    int limit_qps;
+    bool random_value_size = false;
+    bool is_hotkey = false;
+};
+
+#define ToString(x) #x
+
+#define TIMELY_RECORD(time_interval, is_reject, size)                          
                    \
+    do {                                                                       
                    \
+        records[ToString(time_interval##_query_times)]++;                      
                    \
+        records[ToString(time_interval##_query_size)] += size;                 
                    \
+        if (is_reject) {                                                       
                    \
+            records[ToString(time_interval##_reject_times)]++;                 
                    \
+            records[ToString(time_interval##_reject_size)] += size;            
                    \
+        } else {                                                               
                    \
+            records[ToString(time_interval##_successful_times)]++;             
                    \
+            records[ToString(time_interval##_successful_size)] += size;        
                    \
+        }                                                                      
                    \
+    } while (0)
+
+struct throttle_test_recorder
+{
+    uint64_t start_time_ms;
+    uint64_t duration_ms;
+    std::map<std::string, uint64_t> records;
+    std::string test_name;
+    std::vector<std::string> parameter_seq = {"total_qps",
+                                              "total_size_per_sec",
+                                              "first_10_ms_successful_times",
+                                              "first_100_ms_successful_times",
+                                              "first_1000_ms_successful_times",
+                                              "first_5000_ms_successful_times",
+                                              "first_10_ms_successful_size",
+                                              "first_100_ms_successful_size",
+                                              "first_1000_ms_successful_size",
+                                              "first_5000_ms_successful_size"};
+
+    void start_test(const std::string &test_case, uint64_t time_duration_s)
+    {
+        test_name = test_case;
+        start_time_ms = dsn_now_ms();
+        duration_ms = time_duration_s * 1000;
+        records.emplace(std::make_pair("duration_ms", duration_ms));
+    }
+
+    bool is_time_up()
+    {
+        if (dsn_now_ms() - start_time_ms > duration_ms) {
+            return true;
+        }
+        return false;
+    }
+
+    void record(uint64_t size, bool is_reject)
+    {
+        if (is_time_up()) {
+            return;
+        }
+        if (dsn_now_ms() - start_time_ms <= 10) {

Review comment:
       switch in C++ can't support `>` or `<`




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to