• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <gtest/gtest.h>
16 
17 #include "distributeddb_data_generator.h"
18 #include "distributed_test_tools.h"
19 #include "distributed_crud_transaction_tools.h"
20 #include "kv_store_delegate.h"
21 #include "kv_store_delegate_manager.h"
22 
23 using namespace std;
24 using namespace testing;
25 #if defined TESTCASES_USING_GTEST_EXT
26 using namespace testing::ext;
27 #endif
28 using namespace DistributedDB;
29 using namespace DistributedDBDataGenerator;
30 
31 namespace DistributeddbKvTransactionPerf {
32 const bool IS_LOCAL = false;
33 const int PUT_TIMES = 10;
34 const int KEY_LENGTH = 16;
35 const int VALUE_LENGTH = 100;
36 
37 class DistributeddbKvTransactionPerfTest : public testing::Test {
38 public:
39     static void SetUpTestCase(void);
40     static void TearDownTestCase(void);
41     void SetUp();
42     void TearDown();
43 };
44 
45 KvStoreDelegate *g_transactionDelegate = nullptr; // the delegate used in this suit.
46 KvStoreDelegateManager *g_transactionManager = nullptr;
SetUpTestCase(void)47 void DistributeddbKvTransactionPerfTest::SetUpTestCase(void)
48 {
49 }
50 
TearDownTestCase(void)51 void DistributeddbKvTransactionPerfTest::TearDownTestCase(void)
52 {
53 }
54 
SetUp(void)55 void DistributeddbKvTransactionPerfTest::SetUp(void)
56 {
57     MST_LOG("SetUpTestCase before all cases local[%d].", IS_LOCAL);
58     RemoveDir(DIRECTOR);
59 
60     UnitTest *test = UnitTest::GetInstance();
61     ASSERT_NE(test, nullptr);
62     const TestInfo *testinfo = test->current_test_info();
63     ASSERT_NE(testinfo, nullptr);
64     string testCaseName = string(testinfo->name());
65     MST_LOG("[SetUp] test case %s is start to run", testCaseName.c_str());
66 
67     g_transactionDelegate = DistributedTestTools::GetDelegateSuccess(g_transactionManager,
68         g_kvdbParameter1, g_kvOption);
69     ASSERT_TRUE(g_transactionManager != nullptr && g_transactionDelegate != nullptr);
70 }
71 
TearDown(void)72 void DistributeddbKvTransactionPerfTest::TearDown(void)
73 {
74     EXPECT_EQ(g_transactionManager->CloseKvStore(g_transactionDelegate), OK);
75     g_transactionDelegate = nullptr;
76     DBStatus status = g_transactionManager->DeleteKvStore(STORE_ID_1);
77     EXPECT_EQ(status, DistributedDB::DBStatus::OK) << "fail to delete exist kvdb";
78     delete g_transactionManager;
79     g_transactionManager = nullptr;
80     RemoveDir(DIRECTOR);
81 }
82 
83 /*
84  * @tc.name: Performance 001
85  * @tc.desc: Compare between inserting many records in one transaction and one record in each transaction.
86  * @tc.type: Performance
87  * @tc.require: SR000BUH3J
88  * @tc.author: luqianfu
89  */
90 HWTEST_F(DistributeddbKvTransactionPerfTest, Performance001, TestSize.Level3)
91 {
92     /**
93      * @tc.steps: step1.get the putDuration of putBatch(keys,values) by transaction.
94      * @tc.expected: step1. the putDuration is smaller than 1ms/k.
95      */
96     PerformanceData performance(PUT_TIMES, KEY_LENGTH, VALUE_LENGTH, false, false, false, false, IS_LOCAL);
97     double transactionInsert, singleInsert, batchInsert;
98 
99     EXPECT_TRUE(DistributedTestTools::CalculateTransactionPerformance(performance));
100     transactionInsert = performance.putDuration;
101     /**
102      * @tc.steps: step2.get the putDuration of put(k,v) singlely.
103      * @tc.expected: step2. the putDuration is smaller than 1ms/k and bigger than step1.
104      */
105     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
106     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
107     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
108     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
109     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
110     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
111     singleInsert = performance.putDuration;
112     /**
113      * @tc.steps: step3.get the putDuration of putBatch(keys,value) without transaction.
114      * @tc.expected: step3. the putDuration is smaller than 1ms/k.
115      */
116     performance.putBatch = true;
117     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
118     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
119     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
120     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
121     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
122     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
123     batchInsert = performance.putDuration;
124 
125     if (transactionInsert <= batchInsert && batchInsert <= singleInsert) {
126         MST_LOG("the put performance is ok!");
127     }
128 }
129 
130 /*
131  * @tc.name: Performance 002
132  * @tc.desc: Compare between updating many records in one transaction and one record in each transaction.
133  * @tc.type: Performance
134  * @tc.require: SR000BUH3J
135  * @tc.author: luqianfu
136  */
137 HWTEST_F(DistributeddbKvTransactionPerfTest, Performance002, TestSize.Level3)
138 {
139     /**
140      * @tc.steps: step1.get the putDuration of updateBatch(keys,values) by transaction.
141      * @tc.expected: step1. the putDuration is smaller than 1ms/k.
142      */
143     PerformanceData performance(PUT_TIMES, KEY_LENGTH, VALUE_LENGTH, false, false, false, false, IS_LOCAL);
144     double transactionUpdate, singleUpdate, batchUpdate;
145 
146     EXPECT_TRUE(DistributedTestTools::CalculateTransactionPerformance(performance));
147     transactionUpdate = performance.updateDuration;
148     /**
149      * @tc.steps: step2.get the putDuration of update(k,v) singlely.
150      * @tc.expected: step2. the putDuration is smaller than 1ms/k and is bigger than step1.
151      */
152     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
153     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
154     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
155     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
156     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
157     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
158     singleUpdate = performance.updateDuration;
159     /**
160      * @tc.steps: step3.get the putDuration of putBatch(keys,value) without transaction.
161      * @tc.expected: step3. the putDuration is smaller than 1ms/k.
162      */
163     performance.putBatch = true;
164     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
165     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
166     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
167     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
168     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
169     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
170     batchUpdate = performance.updateDuration;
171 
172     if (transactionUpdate <= batchUpdate && batchUpdate <= singleUpdate) {
173         MST_LOG("the update performance is ok!");
174     }
175 }
176 
177 /*
178  * @tc.name: Performance 003
179  * @tc.desc: Compare between deleting many records in one transaction and one record in each transaction.
180  * @tc.type: Performance
181  * @tc.require: SR000BUH3J
182  * @tc.author: luqianfu
183  */
184 HWTEST_F(DistributeddbKvTransactionPerfTest, Performance003, TestSize.Level3)
185 {
186     /**
187      * @tc.steps: step1.get the putDuration of deleteBatch(keys,values) by transaction.
188      * @tc.expected: step1. the putDuration is smaller than 1ms/k.
189      */
190     PerformanceData performance(PUT_TIMES, KEY_LENGTH, VALUE_LENGTH, false, false, false, false, IS_LOCAL);
191     double transactionDel, singleDel, batchDel;
192 
193     EXPECT_TRUE(DistributedTestTools::CalculateTransactionPerformance(performance));
194     transactionDel = performance.deleteDuration;
195     /**
196      * @tc.steps: step2.get the putDuration of delete(k,v) singlely.
197      * @tc.expected: step2. the putDuration is smaller than 1ms/k and is bigger than step1.
198      */
199     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
200     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
201     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
202     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
203     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
204     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
205     singleDel = performance.deleteDuration;
206     /**
207      * @tc.steps: step3.get the putDuration of deleteBatch(keys,value) without transaction.
208      * @tc.expected: step3. the putDuration is smaller than 1ms/k.
209      */
210     performance.putBatch = true;
211     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
212     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
213     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
214     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
215     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
216     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
217     batchDel = performance.deleteDuration;
218 
219     if (transactionDel <= batchDel && batchDel <= singleDel) {
220         MST_LOG("the delete performance is ok!");
221     }
222 }
223 
224 /*
225  * @tc.name: Performance 004
226  * @tc.desc: system info of inserting many records in one transaction and one record in each transaction.
227  * @tc.type: Performance
228  * @tc.require: SR000BUH3J
229  * @tc.author: luqianfu
230  */
231 HWTEST_F(DistributeddbKvTransactionPerfTest, Performance004, TestSize.Level3)
232 {
233     PerformanceData performance(PUT_TIMES, KEY_LENGTH, VALUE_LENGTH, false, false, false, true, IS_LOCAL);
234     /**
235      * @tc.steps: step1.get the sys info of putBatch(keys,values) by transaction.
236      * @tc.expected: step1. the sys info is normal.
237      */
238     EXPECT_TRUE(DistributedTestTools::CalculateTransactionPerformance(performance));
239     /**
240      * @tc.steps: step2.get the sys info of put(k,v) singlely.
241      * @tc.expected: step2. the sys info is normal.
242      */
243     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
244     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
245     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
246     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
247     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
248     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
249     /**
250      * @tc.steps: step3.get the sys info of putBatch(keys,values) without transaction.
251      * @tc.expected: step3. the sys info is normal.
252      */
253     performance.putBatch = true;
254     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
255     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
256     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
257     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
258     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
259     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
260 }
261 
262 /*
263  * @tc.name: Performance 005
264  * @tc.desc: system info of updating many records in one transaction and one record in each transaction.
265  * @tc.type: Pressure
266  * @tc.require: SR000BUH3J
267  * @tc.author: luqianfu
268  */
269 HWTEST_F(DistributeddbKvTransactionPerfTest, Performance005, TestSize.Level3)
270 {
271     PerformanceData performance(PUT_TIMES, KEY_LENGTH, VALUE_LENGTH, false, false, false, true, IS_LOCAL);
272 
273     /**
274      * @tc.steps: step1.get the sys info of updateBatch(keys,values) by transaction.
275      * @tc.expected: step1. the sys info is normal.
276      */
277     EXPECT_TRUE(DistributedTestTools::CalculateTransactionPerformance(performance));
278     /**
279      * @tc.steps: step2.get the sys info of update(k,v) singlely.
280      * @tc.expected: step2. the sys info is normal.
281      */
282     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
283     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
284     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
285     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
286     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
287     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
288     /**
289      * @tc.steps: step3.get the sys info of updateBatch(keys,values) without transaction.
290      * @tc.expected: step3. the sys info is normal.
291      */
292     performance.putBatch = true;
293     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
294     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
295     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
296     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
297     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
298     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
299 }
300 
301 /*
302  * @tc.name: Performance 006
303  * @tc.desc: system info of deleting many records in one transaction and one record in each transaction.
304  * @tc.type: Pressure
305  * @tc.require: SR000BUH3J
306  * @tc.author: luqianfu
307  */
308 HWTEST_F(DistributeddbKvTransactionPerfTest, Performance006, TestSize.Level3)
309 {
310     PerformanceData performance(PUT_TIMES, KEY_LENGTH, VALUE_LENGTH, false, false, false, true, IS_LOCAL);
311 
312     /**
313      * @tc.steps: step1.get the sys info of deleteBatch(keys,values) by transaction.
314      * @tc.expected: step1. the sys info is normal.
315      */
316     EXPECT_TRUE(DistributedTestTools::CalculateTransactionPerformance(performance));
317     /**
318      * @tc.steps: step2.get the sys info of delete(k,v) singlely.
319      * @tc.expected: step2. the sys info is normal.
320      */
321     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
322     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
323     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
324     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
325     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
326     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
327     /**
328      * @tc.steps: step3.get the sys info of deleteBatch(keys,values) without transaction.
329      * @tc.expected: step3. the sys info is normal.
330      */
331     performance.putBatch = true;
332     EXPECT_TRUE(DistributedTestTools::CalculateOpenPerformance(performance));
333     EXPECT_TRUE(DistributedTestTools::CalculateInsertPerformance(performance));
334     EXPECT_TRUE(DistributedTestTools::CalculateGetPutPerformance(performance));
335     EXPECT_TRUE(DistributedTestTools::CalculateUpdatePerformance(performance));
336     EXPECT_TRUE(DistributedTestTools::CalculateGetUpdatePerformance(performance));
337     EXPECT_TRUE(DistributedTestTools::CalculateUseClearPerformance(performance));
338 }
339 }