diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-08-22 14:16:59 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-08-22 14:28:51 +0200 |
commit | 46313049ac01a3007ef60bdc937442945355a38d (patch) | |
tree | 56ce0cd679367a60ba3a706ac4d207bc9cc82230 /tests/entitystoretest.cpp | |
parent | af91a18748b91f4a4fc0d83247561371d376bec5 (diff) | |
download | sink-46313049ac01a3007ef60bdc937442945355a38d.tar.gz sink-46313049ac01a3007ef60bdc937442945355a38d.zip |
Separate UIDs and Revisions in main databases
Summary:
- Change revision type from `qint64` to `size_t` for LMDB in a couple of places (LMDB supports `unsigned int` or `size_t` which are `long unsigned int` on my machine)
- Better support for database flags (duplicate, integer keys, integer values for now but is extensible)
- Main databases' keys are now revisions
- Some databases switched to integer keys databases:
- Main databases
- the revision to uid mapping database
- the revision to entity type mapping database
- Refactor the entity type's `typeDatabases` method (if in the future we need to change the main databases' flags again)
- New uid to revision mapping database (`uidsToRevisions`):
- Stores all revisions (not uid to latest revision) because we need it for cleaning old revisions
- Flags are: duplicates + integer values (so findLatest finds the latest revision for the given uid)
~~Problems to fix before merging:~~
All Fixed!
- ~~Sometimes Sink can't read what has just been written to the database (maybe because of transactions race conditions)~~
- ~~Most of the times, this results in Sink not able to find the uid for a given revision by reading the `revisions` database~~
- ~~`pipelinetest`'s `testModifyWithConflict` fails because the local changes are overridden~~
~~The first problem prevents me from running benchmarks~~
Reviewers: cmollekopf
Tags: #sink
Differential Revision: https://phabricator.kde.org/D14974
Diffstat (limited to 'tests/entitystoretest.cpp')
-rw-r--r-- | tests/entitystoretest.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/entitystoretest.cpp b/tests/entitystoretest.cpp index 03b940b..608de4c 100644 --- a/tests/entitystoretest.cpp +++ b/tests/entitystoretest.cpp | |||
@@ -18,6 +18,7 @@ private slots: | |||
18 | void initTestCase() | 18 | void initTestCase() |
19 | { | 19 | { |
20 | Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Mail, TestMailAdaptorFactory>("test"); | 20 | Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Mail, TestMailAdaptorFactory>("test"); |
21 | Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Event, TestEventAdaptorFactory>("test"); | ||
21 | } | 22 | } |
22 | 23 | ||
23 | void cleanup() | 24 | void cleanup() |
@@ -29,6 +30,100 @@ private slots: | |||
29 | { | 30 | { |
30 | } | 31 | } |
31 | 32 | ||
33 | void testFullScan() | ||
34 | { | ||
35 | using namespace Sink; | ||
36 | ResourceContext resourceContext{resourceInstanceIdentifier.toUtf8(), "dummy", AdaptorFactoryRegistry::instance().getFactories("test")}; | ||
37 | Storage::EntityStore store(resourceContext, {}); | ||
38 | |||
39 | auto mail = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
40 | mail.setExtractedMessageId("messageid"); | ||
41 | mail.setExtractedSubject("boo"); | ||
42 | |||
43 | auto mail2 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
44 | mail2.setExtractedMessageId("messageid2"); | ||
45 | mail2.setExtractedSubject("foo"); | ||
46 | |||
47 | auto mail3 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
48 | mail3.setExtractedMessageId("messageid2"); | ||
49 | mail3.setExtractedSubject("foo"); | ||
50 | |||
51 | store.startTransaction(Storage::DataStore::ReadWrite); | ||
52 | store.add("mail", mail, false); | ||
53 | store.add("mail", mail2, false); | ||
54 | store.add("mail", mail3, false); | ||
55 | |||
56 | mail.setExtractedSubject("foo"); | ||
57 | |||
58 | store.modify("mail", mail, QByteArrayList{}, false); | ||
59 | |||
60 | { | ||
61 | const auto ids = store.fullScan("mail"); | ||
62 | |||
63 | QCOMPARE(ids.size(), 3); | ||
64 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail.identifier()))); | ||
65 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail2.identifier()))); | ||
66 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail3.identifier()))); | ||
67 | } | ||
68 | |||
69 | store.remove("mail", mail3, false); | ||
70 | store.commitTransaction(); | ||
71 | |||
72 | { | ||
73 | const auto ids = store.fullScan("mail"); | ||
74 | |||
75 | QCOMPARE(ids.size(), 2); | ||
76 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail.identifier()))); | ||
77 | QVERIFY(ids.contains(Sink::Storage::Identifier::fromDisplayByteArray(mail2.identifier()))); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | void testExistsAndContains() | ||
82 | { | ||
83 | |||
84 | using namespace Sink; | ||
85 | ResourceContext resourceContext{resourceInstanceIdentifier.toUtf8(), "dummy", AdaptorFactoryRegistry::instance().getFactories("test")}; | ||
86 | Storage::EntityStore store(resourceContext, {}); | ||
87 | |||
88 | auto mail = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
89 | mail.setExtractedMessageId("messageid"); | ||
90 | mail.setExtractedSubject("boo"); | ||
91 | |||
92 | auto mail2 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
93 | mail2.setExtractedMessageId("messageid2"); | ||
94 | mail2.setExtractedSubject("foo"); | ||
95 | |||
96 | auto mail3 = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Mail>("res1"); | ||
97 | mail3.setExtractedMessageId("messageid2"); | ||
98 | mail3.setExtractedSubject("foo"); | ||
99 | |||
100 | auto event = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::Event>("res1"); | ||
101 | event.setExtractedUid("messageid2"); | ||
102 | event.setExtractedSummary("foo"); | ||
103 | |||
104 | store.startTransaction(Storage::DataStore::ReadWrite); | ||
105 | store.add("mail", mail, false); | ||
106 | store.add("mail", mail2, false); | ||
107 | store.add("mail", mail3, false); | ||
108 | store.add("event", event, false); | ||
109 | |||
110 | mail.setExtractedSubject("foo"); | ||
111 | |||
112 | store.modify("mail", mail, QByteArrayList{}, false); | ||
113 | store.remove("mail", mail3, false); | ||
114 | store.commitTransaction(); | ||
115 | |||
116 | QVERIFY(store.contains("mail", mail.identifier())); | ||
117 | QVERIFY(store.contains("mail", mail2.identifier())); | ||
118 | QVERIFY(store.contains("mail", mail3.identifier())); | ||
119 | QVERIFY(store.contains("event", event.identifier())); | ||
120 | |||
121 | QVERIFY(store.exists("mail", mail.identifier())); | ||
122 | QVERIFY(store.exists("mail", mail2.identifier())); | ||
123 | QVERIFY(!store.exists("mail", mail3.identifier())); | ||
124 | QVERIFY(store.exists("event", event.identifier())); | ||
125 | } | ||
126 | |||
32 | void readAll() | 127 | void readAll() |
33 | { | 128 | { |
34 | using namespace Sink; | 129 | using namespace Sink; |