diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-05 10:05:19 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-05 10:05:19 +0100 |
commit | 93d1c82ffd17df45a5cecd875a01ee3cb15d9983 (patch) | |
tree | cda5c31857362ce81f3a50959024f4270d149a07 /store/test | |
parent | 639fc60c100204c87b93112516cf3b3117cfff0d (diff) | |
parent | 351a66b5fb1c8659bff8ea20d60f5a6d2d3263ad (diff) | |
download | sink-93d1c82ffd17df45a5cecd875a01ee3cb15d9983.tar.gz sink-93d1c82ffd17df45a5cecd875a01ee3cb15d9983.zip |
Merge branch 'kyoto'
Conflicts:
common/storage.h
common/storage_lmdb.cpp
dummyresource/facade.cpp
store/test/CMakeLists.txt
tests/storagebenchmark.cpp
Diffstat (limited to 'store/test')
-rw-r--r-- | store/test/CMakeLists.txt | 22 | ||||
-rw-r--r-- | store/test/calendar.fbs | 12 | ||||
-rw-r--r-- | store/test/storagebenchmark.cpp | 161 |
3 files changed, 0 insertions, 195 deletions
diff --git a/store/test/CMakeLists.txt b/store/test/CMakeLists.txt deleted file mode 100644 index c5c4fcb..0000000 --- a/store/test/CMakeLists.txt +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | set(CMAKE_AUTOMOC ON) | ||
2 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
3 | |||
4 | set(store_path "../") | ||
5 | set(store_SRCS | ||
6 | ${store_path}/database.cpp | ||
7 | ) | ||
8 | |||
9 | generate_flatbuffers(calendar) | ||
10 | |||
11 | macro(manual_tests) | ||
12 | foreach(_testname ${ARGN}) | ||
13 | add_executable(${_testname} ${_testname}.cpp ${store_SRCS}) | ||
14 | qt5_use_modules(${_testname} Core Test Concurrent) | ||
15 | target_link_libraries(${_testname} lmdb) | ||
16 | endforeach(_testname) | ||
17 | endmacro(auto_tests) | ||
18 | |||
19 | manual_tests ( | ||
20 | storagebenchmark | ||
21 | storagetest | ||
22 | ) | ||
diff --git a/store/test/calendar.fbs b/store/test/calendar.fbs deleted file mode 100644 index 203ee43..0000000 --- a/store/test/calendar.fbs +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | // example IDL file | ||
2 | |||
3 | namespace Calendar; | ||
4 | |||
5 | table Event { | ||
6 | summary:string; | ||
7 | description:string; | ||
8 | attachment:[byte]; | ||
9 | } | ||
10 | |||
11 | root_type Event; | ||
12 | file_identifier "AKFB"; | ||
diff --git a/store/test/storagebenchmark.cpp b/store/test/storagebenchmark.cpp deleted file mode 100644 index 0bad138..0000000 --- a/store/test/storagebenchmark.cpp +++ /dev/null | |||
@@ -1,161 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include "calendar_generated.h" | ||
4 | |||
5 | #include <iostream> | ||
6 | #include <fstream> | ||
7 | |||
8 | #include <QDebug> | ||
9 | #include <QString> | ||
10 | #include <QTime> | ||
11 | |||
12 | #include "store/database.h" | ||
13 | |||
14 | using namespace Calendar; | ||
15 | using namespace flatbuffers; | ||
16 | |||
17 | static std::string createEvent() | ||
18 | { | ||
19 | FlatBufferBuilder fbb; | ||
20 | { | ||
21 | auto summary = fbb.CreateString("summary"); | ||
22 | |||
23 | const int attachmentSize = 1024*2; // 2KB | ||
24 | int8_t rawData[attachmentSize]; | ||
25 | auto data = fbb.CreateVector(rawData, attachmentSize); | ||
26 | |||
27 | Calendar::EventBuilder eventBuilder(fbb); | ||
28 | eventBuilder.add_summary(summary); | ||
29 | eventBuilder.add_attachment(data); | ||
30 | auto eventLocation = eventBuilder.Finish(); | ||
31 | FinishEventBuffer(fbb, eventLocation); | ||
32 | } | ||
33 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
34 | } | ||
35 | |||
36 | // static void readEvent(const std::string &data) | ||
37 | // { | ||
38 | // auto readEvent = GetEvent(data.c_str()); | ||
39 | // std::cout << readEvent->summary()->c_str() << std::endl; | ||
40 | // } | ||
41 | |||
42 | class StorageBenchmark : public QObject | ||
43 | { | ||
44 | Q_OBJECT | ||
45 | private: | ||
46 | //This should point to a directory on disk and not a ramdisk (since we're measuring performance) | ||
47 | QString testDataPath; | ||
48 | QString dbName; | ||
49 | QString filePath; | ||
50 | const int count = 50000; | ||
51 | |||
52 | private Q_SLOTS: | ||
53 | void initTestCase() | ||
54 | { | ||
55 | testDataPath = "./testdb"; | ||
56 | dbName = "test"; | ||
57 | filePath = testDataPath + "buffer.fb"; | ||
58 | } | ||
59 | |||
60 | void cleanupTestCase() | ||
61 | { | ||
62 | Database db(testDataPath, dbName); | ||
63 | db.removeFromDisk(); | ||
64 | } | ||
65 | |||
66 | void testWriteRead_data() | ||
67 | { | ||
68 | QTest::addColumn<bool>("useDb"); | ||
69 | QTest::addColumn<int>("count"); | ||
70 | |||
71 | QTest::newRow("db, 50k") << true << count; | ||
72 | QTest::newRow("file, 50k") << false << count; | ||
73 | } | ||
74 | |||
75 | void testWriteRead() | ||
76 | { | ||
77 | QFETCH(bool, useDb); | ||
78 | QFETCH(int, count); | ||
79 | |||
80 | Database *db = 0; | ||
81 | if (useDb) { | ||
82 | db = new Database(testDataPath, dbName); | ||
83 | } | ||
84 | |||
85 | std::ofstream myfile; | ||
86 | myfile.open(filePath.toStdString()); | ||
87 | const char *keyPrefix = "key"; | ||
88 | |||
89 | QTime time; | ||
90 | |||
91 | time.start(); | ||
92 | { | ||
93 | auto event = createEvent(); | ||
94 | for (int i = 0; i < count; i++) { | ||
95 | if (db) { | ||
96 | if (i % 10000 == 0) { | ||
97 | if (i > 0) { | ||
98 | db->commitTransaction(); | ||
99 | } | ||
100 | db->startTransaction(); | ||
101 | } | ||
102 | |||
103 | db->write(keyPrefix + std::to_string(i), event); | ||
104 | } else { | ||
105 | myfile << event; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | if (db) { | ||
110 | db->commitTransaction(); | ||
111 | } else { | ||
112 | myfile.close(); | ||
113 | } | ||
114 | } | ||
115 | const int writeDuration = time.restart(); | ||
116 | qDebug() << "Writing took[ms]: " << writeDuration; | ||
117 | |||
118 | { | ||
119 | for (int i = 0; i < count; i++) { | ||
120 | if (db) { | ||
121 | db->read(keyPrefix + std::to_string(i), [](std::string value){}); | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | const int readDuration = time.restart(); | ||
126 | |||
127 | if (db) { | ||
128 | qDebug() << "Reading took[ms]: " << readDuration; | ||
129 | } else { | ||
130 | qDebug() << "File reading is not implemented."; | ||
131 | } | ||
132 | |||
133 | delete db; | ||
134 | } | ||
135 | |||
136 | void testBufferCreation() | ||
137 | { | ||
138 | QTime time; | ||
139 | |||
140 | time.start(); | ||
141 | { | ||
142 | for (int i = 0; i < count; i++) { | ||
143 | auto event = createEvent(); | ||
144 | } | ||
145 | } | ||
146 | const int bufferDuration = time.elapsed(); | ||
147 | qDebug() << "Creating buffers took[ms]: " << bufferDuration; | ||
148 | } | ||
149 | |||
150 | void testSizes() | ||
151 | { | ||
152 | Database db(testDataPath, dbName); | ||
153 | qDebug() << "Database size [kb]: " << db.diskUsage()/1024; | ||
154 | |||
155 | QFileInfo fileInfo(filePath); | ||
156 | qDebug() << "File size [kb]: " << fileInfo.size()/1024; | ||
157 | } | ||
158 | }; | ||
159 | |||
160 | QTEST_MAIN(StorageBenchmark) | ||
161 | #include "storagebenchmark.moc" | ||