diff options
author | Minijackson <minijackson@riseup.net> | 2018-06-27 11:12:38 +0200 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2018-07-04 15:37:14 +0200 |
commit | 016fea734d09df707be9a16a4ad6a1107f41549f (patch) | |
tree | 60bf9767842713538505fca80515a8f5e59ca985 | |
parent | c90ba4a98292a39eb0b3df12fd7e2dec0300e58d (diff) | |
download | sink-016fea734d09df707be9a16a4ad6a1107f41549f.tar.gz sink-016fea734d09df707be9a16a4ad6a1107f41549f.zip |
Fix pipelinetest + remove useless commented lines
-rw-r--r-- | common/changereplay.cpp | 1 | ||||
-rw-r--r-- | common/storage.h | 4 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 16 | ||||
-rw-r--r-- | common/storage_common.cpp | 24 | ||||
-rw-r--r-- | common/synchronizer.cpp | 2 | ||||
-rw-r--r-- | common/utils.cpp | 1 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_inspect.cpp | 1 | ||||
-rw-r--r-- | tests/pipelinetest.cpp | 13 | ||||
-rw-r--r-- | tests/storagetest.cpp | 9 |
9 files changed, 18 insertions, 53 deletions
diff --git a/common/changereplay.cpp b/common/changereplay.cpp index e94ed80..5817e8d 100644 --- a/common/changereplay.cpp +++ b/common/changereplay.cpp | |||
@@ -114,7 +114,6 @@ KAsync::Job<void> ChangeReplay::replayNextRevision() | |||
114 | if (uid.isEmpty() || type.isEmpty()) { | 114 | if (uid.isEmpty() || type.isEmpty()) { |
115 | SinkErrorCtx(mLogCtx) << "Failed to read uid or type for revison: " << revision << uid << type; | 115 | SinkErrorCtx(mLogCtx) << "Failed to read uid or type for revison: " << revision << uid << type; |
116 | } else { | 116 | } else { |
117 | //const auto key = DataStore::assembleKey(uid, revision); | ||
118 | // TODO: should not use internal representations | 117 | // TODO: should not use internal representations |
119 | const auto key = Storage::Key(Storage::Identifier::fromDisplayByteArray(uid), revision).toInternalByteArray(); | 118 | const auto key = Storage::Key(Storage::Identifier::fromDisplayByteArray(uid), revision).toInternalByteArray(); |
120 | QByteArray entityBuffer; | 119 | QByteArray entityBuffer; |
diff --git a/common/storage.h b/common/storage.h index 25d0fa6..8904148 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -239,10 +239,6 @@ public: | |||
239 | static bool isInternalKey(void *key, int keySize); | 239 | static bool isInternalKey(void *key, int keySize); |
240 | static bool isInternalKey(const QByteArray &key); | 240 | static bool isInternalKey(const QByteArray &key); |
241 | 241 | ||
242 | //static QByteArray assembleKey(const QByteArray &key, qint64 revision); | ||
243 | //static Identifier uidFromKey(const QByteArray &key); | ||
244 | //static qint64 revisionFromKey(const QByteArray &key); | ||
245 | |||
246 | static NamedDatabase mainDatabase(const Transaction &, const QByteArray &type); | 242 | static NamedDatabase mainDatabase(const Transaction &, const QByteArray &type); |
247 | 243 | ||
248 | static QByteArray generateUid(); | 244 | static QByteArray generateUid(); |
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index efafe8a..d3420e4 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -371,8 +371,9 @@ void EntityStore::cleanupEntityRevisionsUntil(qint64 revision) | |||
371 | return; | 371 | return; |
372 | } | 372 | } |
373 | SinkTraceCtx(d->logCtx) << "Cleaning up revision " << revision << uid << bufferType; | 373 | SinkTraceCtx(d->logCtx) << "Cleaning up revision " << revision << uid << bufferType; |
374 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | ||
374 | DataStore::mainDatabase(d->transaction, bufferType) | 375 | DataStore::mainDatabase(d->transaction, bufferType) |
375 | .scan(uid, | 376 | .scan(internalUid, |
376 | [&](const QByteArray &key, const QByteArray &data) -> bool { | 377 | [&](const QByteArray &key, const QByteArray &data) -> bool { |
377 | EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); | 378 | EntityBuffer buffer(const_cast<const char *>(data.data()), data.size()); |
378 | if (!buffer.isValid()) { | 379 | if (!buffer.isValid()) { |
@@ -530,7 +531,6 @@ ApplicationDomain::ApplicationDomainType EntityStore::readLatest(const QByteArra | |||
530 | return dt; | 531 | return dt; |
531 | } | 532 | } |
532 | 533 | ||
533 | // TODO: check every usage | ||
534 | void EntityStore::readEntity(const QByteArray &type, const QByteArray &displayKey, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) | 534 | void EntityStore::readEntity(const QByteArray &type, const QByteArray &displayKey, const std::function<void(const QByteArray &uid, const EntityBuffer &entity)> callback) |
535 | { | 535 | { |
536 | const auto key = Key::fromDisplayByteArray(displayKey); | 536 | const auto key = Key::fromDisplayByteArray(displayKey); |
@@ -598,7 +598,6 @@ void EntityStore::readPrevious(const QByteArray &type, const QByteArray &uid, qi | |||
598 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | 598 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); |
599 | db.scan(internalUid, | 599 | db.scan(internalUid, |
600 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { | 600 | [&latestRevision, revision](const QByteArray &key, const QByteArray &) -> bool { |
601 | //const auto foundRevision = DataStore::revisionFromKey(key); | ||
602 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); | 601 | const auto foundRevision = Key::fromInternalByteArray(key).revision().toQint64(); |
603 | if (foundRevision < revision && foundRevision > latestRevision) { | 602 | if (foundRevision < revision && foundRevision > latestRevision) { |
604 | latestRevision = foundRevision; | 603 | latestRevision = foundRevision; |
@@ -633,11 +632,7 @@ void EntityStore::readAllUids(const QByteArray &type, const std::function<void(c | |||
633 | 632 | ||
634 | bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) | 633 | bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) |
635 | { | 634 | { |
636 | // Because of pipeline using this function with new entities | 635 | Q_ASSERT(!uid.isEmpty()); |
637 | // TODO: maybe modify pipeline instead? | ||
638 | if(uid.isEmpty()) { | ||
639 | return false; | ||
640 | } | ||
641 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | 636 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); |
642 | return DataStore::mainDatabase(d->getTransaction(), type).contains(internalUid); | 637 | return DataStore::mainDatabase(d->getTransaction(), type).contains(internalUid); |
643 | } | 638 | } |
@@ -675,10 +670,11 @@ void EntityStore::readRevisions(const QByteArray &type, const QByteArray &uid, q | |||
675 | { | 670 | { |
676 | Q_ASSERT(d); | 671 | Q_ASSERT(d); |
677 | Q_ASSERT(!uid.isEmpty()); | 672 | Q_ASSERT(!uid.isEmpty()); |
673 | const auto internalUid = Identifier::fromDisplayByteArray(uid).toInternalByteArray(); | ||
678 | DataStore::mainDatabase(d->transaction, type) | 674 | DataStore::mainDatabase(d->transaction, type) |
679 | .scan(uid, | 675 | .scan(internalUid, |
680 | [&](const QByteArray &key, const QByteArray &value) -> bool { | 676 | [&](const QByteArray &key, const QByteArray &value) -> bool { |
681 | const auto parsedKey = Key::fromDisplayByteArray(key); | 677 | const auto parsedKey = Key::fromInternalByteArray(key); |
682 | const auto revision = parsedKey.revision().toQint64(); | 678 | const auto revision = parsedKey.revision().toQint64(); |
683 | if (revision >= startingRevision) { | 679 | if (revision >= startingRevision) { |
684 | callback(parsedKey.identifier().toDisplayByteArray(), revision, Sink::EntityBuffer(value.data(), value.size())); | 680 | callback(parsedKey.identifier().toDisplayByteArray(), revision, Sink::EntityBuffer(value.data(), value.size())); |
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index c922d9d..f96097a 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -24,8 +24,6 @@ | |||
24 | #include "log.h" | 24 | #include "log.h" |
25 | #include "utils.h" | 25 | #include "utils.h" |
26 | 26 | ||
27 | #include <QUuid> | ||
28 | |||
29 | QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) | 27 | QDebug& operator<<(QDebug &dbg, const Sink::Storage::DataStore::Error &error) |
30 | { | 28 | { |
31 | dbg << error.message << "Code: " << error.code << "Db: " << error.store; | 29 | dbg << error.message << "Code: " << error.code << "Db: " << error.store; |
@@ -38,8 +36,6 @@ namespace Storage { | |||
38 | static const char *s_internalPrefix = "__internal"; | 36 | static const char *s_internalPrefix = "__internal"; |
39 | static const int s_internalPrefixSize = strlen(s_internalPrefix); | 37 | static const int s_internalPrefixSize = strlen(s_internalPrefix); |
40 | static const int s_lengthOfUid = 38; | 38 | static const int s_lengthOfUid = 38; |
41 | // RFC 4122 Section 4.1.2 says 128 bits -> 16 bytes | ||
42 | //static const int s_lengthOfUid = 16; | ||
43 | 39 | ||
44 | DbLayout::DbLayout() | 40 | DbLayout::DbLayout() |
45 | { | 41 | { |
@@ -198,26 +194,6 @@ bool DataStore::isInternalKey(const QByteArray &key) | |||
198 | return key.startsWith(s_internalPrefix); | 194 | return key.startsWith(s_internalPrefix); |
199 | } | 195 | } |
200 | 196 | ||
201 | /* | ||
202 | QByteArray DataStore::assembleKey(const QByteArray &key, qint64 revision) | ||
203 | { | ||
204 | Q_ASSERT(revision <= 9223372036854775807); | ||
205 | Q_ASSERT(key.size() == s_lengthOfUid); | ||
206 | return key + QByteArray::number(revision).rightJustified(19, '0', false); | ||
207 | } | ||
208 | |||
209 | //QByteArray DataStore::uidFromKey(const QByteArray &key) | ||
210 | Identifier DataStore::uidFromKey(const QByteArray &key) | ||
211 | { | ||
212 | return Identifier::fromByteArray(key.mid(0, s_lengthOfUid)); | ||
213 | } | ||
214 | |||
215 | qint64 DataStore::revisionFromKey(const QByteArray &key) | ||
216 | { | ||
217 | return key.mid(s_lengthOfUid + 1).toLongLong(); | ||
218 | } | ||
219 | */ | ||
220 | |||
221 | QByteArray DataStore::generateUid() | 197 | QByteArray DataStore::generateUid() |
222 | { | 198 | { |
223 | return createUuid(); | 199 | return createUuid(); |
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index f19c08a..ffc7020 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -616,7 +616,7 @@ KAsync::Job<void> Synchronizer::replay(const QByteArray &type, const QByteArray | |||
616 | Q_ASSERT(mEntityStore->hasTransaction()); | 616 | Q_ASSERT(mEntityStore->hasTransaction()); |
617 | 617 | ||
618 | const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; | 618 | const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; |
619 | //const auto uid = Sink::Storage::DataStore::uidFromKey(key); | 619 | // TODO: should not use internal representations |
620 | const auto uid = Sink::Storage::Key::fromDisplayByteArray(key).identifier().toDisplayByteArray(); | 620 | const auto uid = Sink::Storage::Key::fromDisplayByteArray(key).identifier().toDisplayByteArray(); |
621 | const auto modifiedProperties = metadataBuffer->modifiedProperties() ? BufferUtils::fromVector(*metadataBuffer->modifiedProperties()) : QByteArrayList(); | 621 | const auto modifiedProperties = metadataBuffer->modifiedProperties() ? BufferUtils::fromVector(*metadataBuffer->modifiedProperties()) : QByteArrayList(); |
622 | QByteArray oldRemoteId; | 622 | QByteArray oldRemoteId; |
diff --git a/common/utils.cpp b/common/utils.cpp index e98365c..3c54db4 100644 --- a/common/utils.cpp +++ b/common/utils.cpp | |||
@@ -22,5 +22,4 @@ | |||
22 | QByteArray Sink::createUuid() | 22 | QByteArray Sink::createUuid() |
23 | { | 23 | { |
24 | return QUuid::createUuid().toByteArray(); | 24 | return QUuid::createUuid().toByteArray(); |
25 | //return QUuid::createUuid().toRfc4122(); | ||
26 | } | 25 | } |
diff --git a/sinksh/syntax_modules/sink_inspect.cpp b/sinksh/syntax_modules/sink_inspect.cpp index 019ef31..1b3d77c 100644 --- a/sinksh/syntax_modules/sink_inspect.cpp +++ b/sinksh/syntax_modules/sink_inspect.cpp | |||
@@ -92,7 +92,6 @@ bool inspect(const QStringList &args, State &state) | |||
92 | 92 | ||
93 | QSet<QByteArray> uids; | 93 | QSet<QByteArray> uids; |
94 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { | 94 | db.scan("", [&] (const QByteArray &key, const QByteArray &data) { |
95 | //uids.insert(Sink::Storage::DataStore::uidFromKey(key)); | ||
96 | uids.insert(Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); | 95 | uids.insert(Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray()); |
97 | return true; | 96 | return true; |
98 | }, | 97 | }, |
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 5165d35..2610305 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp | |||
@@ -22,6 +22,8 @@ | |||
22 | #include "adaptorfactoryregistry.h" | 22 | #include "adaptorfactoryregistry.h" |
23 | #include "storage/key.h" | 23 | #include "storage/key.h" |
24 | 24 | ||
25 | // TODO: fix test | ||
26 | |||
25 | static void removeFromDisk(const QString &name) | 27 | static void removeFromDisk(const QString &name) |
26 | { | 28 | { |
27 | Sink::Storage::DataStore store(Sink::Store::storageLocation(), name, Sink::Storage::DataStore::ReadWrite); | 29 | Sink::Storage::DataStore store(Sink::Store::storageLocation(), name, Sink::Storage::DataStore::ReadWrite); |
@@ -379,8 +381,7 @@ private slots: | |||
379 | pipeline.newEntity(command.constData(), command.size()); | 381 | pipeline.newEntity(command.constData(), command.size()); |
380 | QCOMPARE(testProcessor->newUids.size(), 1); | 382 | QCOMPARE(testProcessor->newUids.size(), 1); |
381 | QCOMPARE(testProcessor->newRevisions.size(), 1); | 383 | QCOMPARE(testProcessor->newRevisions.size(), 1); |
382 | // Key doesn't contain revision and is just the uid | 384 | const auto uid = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->newUids.at(0)).toDisplayByteArray(); |
383 | const auto uid = Sink::Storage::Key::fromDisplayByteArray(testProcessor->newUids.at(0)).identifier().toDisplayByteArray(); | ||
384 | QCOMPARE(testProcessor->newUids.at(0), uid); | 385 | QCOMPARE(testProcessor->newUids.at(0), uid); |
385 | } | 386 | } |
386 | pipeline.commit(); | 387 | pipeline.commit(); |
@@ -388,14 +389,13 @@ private slots: | |||
388 | pipeline.startTransaction(); | 389 | pipeline.startTransaction(); |
389 | auto keys = getKeys(instanceIdentifier(), "event.main"); | 390 | auto keys = getKeys(instanceIdentifier(), "event.main"); |
390 | QCOMPARE(keys.size(), 1); | 391 | QCOMPARE(keys.size(), 1); |
391 | const auto uid = Sink::Storage::Key::fromDisplayByteArray(keys.first()).identifier().toDisplayByteArray(); | 392 | const auto uid = Sink::Storage::Key::fromInternalByteArray(keys.first()).identifier().toDisplayByteArray(); |
392 | { | 393 | { |
393 | auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); | 394 | auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); |
394 | pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); | 395 | pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); |
395 | QCOMPARE(testProcessor->modifiedUids.size(), 1); | 396 | QCOMPARE(testProcessor->modifiedUids.size(), 1); |
396 | QCOMPARE(testProcessor->modifiedRevisions.size(), 1); | 397 | QCOMPARE(testProcessor->modifiedRevisions.size(), 1); |
397 | // Key doesn't contain revision and is just the uid | 398 | const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray(); |
398 | const auto uid2 = Sink::Storage::Key::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).identifier().toDisplayByteArray(); | ||
399 | QCOMPARE(testProcessor->modifiedUids.at(0), uid2); | 399 | QCOMPARE(testProcessor->modifiedUids.at(0), uid2); |
400 | } | 400 | } |
401 | pipeline.commit(); | 401 | pipeline.commit(); |
@@ -407,8 +407,7 @@ private slots: | |||
407 | QCOMPARE(testProcessor->deletedUids.size(), 1); | 407 | QCOMPARE(testProcessor->deletedUids.size(), 1); |
408 | QCOMPARE(testProcessor->deletedUids.size(), 1); | 408 | QCOMPARE(testProcessor->deletedUids.size(), 1); |
409 | QCOMPARE(testProcessor->deletedSummaries.size(), 1); | 409 | QCOMPARE(testProcessor->deletedSummaries.size(), 1); |
410 | // Key doesn't contain revision and is just the uid | 410 | const auto uid2 = Sink::Storage::Identifier::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).toDisplayByteArray(); |
411 | const auto uid2 = Sink::Storage::Key::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).identifier().toDisplayByteArray(); | ||
412 | QCOMPARE(testProcessor->deletedUids.at(0), uid2); | 411 | QCOMPARE(testProcessor->deletedUids.at(0), uid2); |
413 | QCOMPARE(testProcessor->deletedSummaries.at(0), QByteArray("summary2")); | 412 | QCOMPARE(testProcessor->deletedSummaries.at(0), QByteArray("summary2")); |
414 | } | 413 | } |
diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index d3f180a..2ddbebf 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp | |||
@@ -457,10 +457,11 @@ private slots: | |||
457 | auto db = transaction.openDatabase("test", nullptr, false); | 457 | auto db = transaction.openDatabase("test", nullptr, false); |
458 | const auto uid = "{c5d06a9f-1534-4c52-b8ea-415db68bdadf}"; | 458 | const auto uid = "{c5d06a9f-1534-4c52-b8ea-415db68bdadf}"; |
459 | //Ensure we can sort 1 and 10 properly (by default string comparison 10 comes before 6) | 459 | //Ensure we can sort 1 and 10 properly (by default string comparison 10 comes before 6) |
460 | const auto key1 = Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(uid), 6); | 460 | const auto id = Sink::Storage::Identifier::fromDisplayByteArray(uid); |
461 | db.write(key1.toInternalByteArray(), "value1"); | 461 | auto key = Sink::Storage::Key(id, 6); |
462 | const auto key2 = Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(uid), 10); | 462 | db.write(key.toInternalByteArray(), "value1"); |
463 | db.write(key2.toInternalByteArray(), "value2"); | 463 | key.setRevision(10); |
464 | db.write(key.toInternalByteArray(), "value2"); | ||
464 | db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); | 465 | db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); |
465 | QCOMPARE(result, QByteArray("value2")); | 466 | QCOMPARE(result, QByteArray("value2")); |
466 | } | 467 | } |