From 922e0979e2c27ff8dbc765ae151d17c7815b98a0 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 26 Jun 2018 11:44:11 +0200 Subject: [Storage] Implement Key API --- tests/pipelinetest.cpp | 29 +++++++++++++++++++---------- tests/storagetest.cpp | 10 ++++++---- 2 files changed, 25 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index 45e2fbb..7431deb 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -250,8 +250,9 @@ private slots: // Get uid of written entity auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto key = keys.first(); - const auto uid = Sink::Storage::DataStore::uidFromKey(key); + auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); + //const auto uid = Sink::Storage::DataStore::uidFromKey(key); + const auto uid = key.identifier().toDisplayByteArray(); // Execute the modification entityFbb.Clear(); @@ -260,8 +261,10 @@ private slots: pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); pipeline.commit(); + key.setRevision(2); + // Ensure we've got the new revision with the modification - auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 2)); + auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); QVERIFY(!buffer.isEmpty()); Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); @@ -296,7 +299,8 @@ private slots: // Get uid of written entity auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); + auto key = Sink::Storage::Key::fromInternalByteArray(keys.first()); + const auto uid = key.identifier().toDisplayByteArray(); // Create another operation inbetween @@ -315,8 +319,10 @@ private slots: pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); pipeline.commit(); + key.setRevision(3); + // Ensure we've got the new revision with the modification - auto buffer = getEntity(instanceIdentifier(), "event.main", Sink::Storage::DataStore::assembleKey(uid, 3)); + auto buffer = getEntity(instanceIdentifier(), "event.main", key.toInternalByteArray()); QVERIFY(!buffer.isEmpty()); Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); @@ -337,7 +343,7 @@ private slots: auto result = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(result.size(), 1); - const auto uid = Sink::Storage::DataStore::uidFromKey(result.first()); + const auto uid = Sink::Storage::Key::fromInternalByteArray(result.first()).identifier().toDisplayByteArray(); // Delete entity auto deleteCommand = deleteEntityCommand(uid, 1); @@ -373,21 +379,23 @@ private slots: QCOMPARE(testProcessor->newUids.size(), 1); QCOMPARE(testProcessor->newRevisions.size(), 1); // Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor->newUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->newUids.at(0))); + const auto uid = Sink::Storage::Key::fromDisplayByteArray(testProcessor->newUids.at(0)).identifier().toDisplayByteArray(); + QCOMPARE(testProcessor->newUids.at(0), uid); } pipeline.commit(); entityFbb.Clear(); pipeline.startTransaction(); auto keys = getKeys(instanceIdentifier(), "event.main"); QCOMPARE(keys.size(), 1); - const auto uid = Sink::Storage::DataStore::uidFromKey(keys.first()); + const auto uid = Sink::Storage::Key::fromDisplayByteArray(keys.first()).identifier().toDisplayByteArray(); { auto modifyCommand = modifyEntityCommand(createEvent(entityFbb, "summary2"), uid, 1); pipeline.modifiedEntity(modifyCommand.constData(), modifyCommand.size()); QCOMPARE(testProcessor->modifiedUids.size(), 1); QCOMPARE(testProcessor->modifiedRevisions.size(), 1); // Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor->modifiedUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->modifiedUids.at(0))); + const auto uid2 = Sink::Storage::Key::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).identifier().toDisplayByteArray(); + QCOMPARE(testProcessor->modifiedUids.at(0), uid2); } pipeline.commit(); entityFbb.Clear(); @@ -399,7 +407,8 @@ private slots: QCOMPARE(testProcessor->deletedUids.size(), 1); QCOMPARE(testProcessor->deletedSummaries.size(), 1); // Key doesn't contain revision and is just the uid - QCOMPARE(testProcessor->deletedUids.at(0), Sink::Storage::DataStore::uidFromKey(testProcessor->deletedUids.at(0))); + const auto uid2 = Sink::Storage::Key::fromDisplayByteArray(testProcessor->modifiedUids.at(0)).identifier().toDisplayByteArray(); + QCOMPARE(testProcessor->deletedUids.at(0), uid2); QCOMPARE(testProcessor->deletedSummaries.at(0), QByteArray("summary2")); } } diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index bca91b1..40492f0 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -456,8 +456,10 @@ private slots: auto db = transaction.openDatabase("test", nullptr, false); const auto uid = "{c5d06a9f-1534-4c52-b8ea-415db68bdadf}"; //Ensure we can sort 1 and 10 properly (by default string comparison 10 comes before 6) - db.write(Sink::Storage::DataStore::assembleKey(uid, 6), "value1"); - db.write(Sink::Storage::DataStore::assembleKey(uid, 10), "value2"); + const auto key1 = Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(uid), 6); + db.write(key1.toInternalByteArray(), "value1"); + const auto key2 = Sink::Storage::Key(Sink::Storage::Identifier::fromDisplayByteArray(uid), 10); + db.write(key2.toInternalByteArray(), "value2"); db.findLatest(uid, [&](const QByteArray &key, const QByteArray &value) { result = value; }); QCOMPARE(result, QByteArray("value2")); } @@ -689,7 +691,7 @@ private slots: Sink::Storage::DataStore::clearEnv(); //Try to read-only dynamic opening of the db. - //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) + //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) { // Trick the db into not loading all dbs by passing in a bogus layout. Sink::Storage::DataStore store(testDataPath, {dbName, {{"bogus", 0}}}, Sink::Storage::DataStore::ReadOnly); @@ -707,7 +709,7 @@ private slots: Sink::Storage::DataStore::clearEnv(); //Try to read-write dynamic opening of the db. - //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) + //This is the case if we don't have all databases available upon initializatoin and we don't (e.g. because the db hasn't been created yet) { // Trick the db into not loading all dbs by passing in a bogus layout. Sink::Storage::DataStore store(testDataPath, {dbName, {{"bogus", 0}}}, Sink::Storage::DataStore::ReadWrite); -- cgit v1.2.3