Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3248308
D4079.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D4079.diff
View Options
diff --git a/services/backup/src/DatabaseManager.h b/services/backup/src/DatabaseManager.h
--- a/services/backup/src/DatabaseManager.h
+++ b/services/backup/src/DatabaseManager.h
@@ -28,6 +28,8 @@
void removeBackupItem(std::shared_ptr<BackupItem> item);
void putLogItem(const LogItem &item);
+ std::shared_ptr<LogItem>
+ findLogItem(const std::string &backupID, const std::string &logID);
std::vector<std::shared_ptr<LogItem>>
findLogItemsForBackup(const std::string &backupID);
void removeLogItem(std::shared_ptr<LogItem> item);
diff --git a/services/backup/src/DatabaseManager.cpp b/services/backup/src/DatabaseManager.cpp
--- a/services/backup/src/DatabaseManager.cpp
+++ b/services/backup/src/DatabaseManager.cpp
@@ -7,6 +7,7 @@
#include <aws/dynamodb/model/DeleteItemRequest.h>
#include <aws/dynamodb/model/QueryRequest.h>
#include <aws/dynamodb/model/ScanRequest.h>
+#include <aws/dynamodb/model/UpdateItemRequest.h>
#include <iostream>
@@ -57,7 +58,7 @@
BackupItem::FIELD_BACKUP_ID,
Aws::DynamoDB::Model::AttributeValue(backupID));
- return std::move(this->innerFindItem<BackupItem>(request));
+ return this->innerFindItem<BackupItem>(request);
}
std::shared_ptr<BackupItem>
@@ -121,6 +122,18 @@
this->innerPutItem(std::make_shared<LogItem>(item), request);
}
+std::shared_ptr<LogItem> DatabaseManager::findLogItem(
+ const std::string &backupID,
+ const std::string &logID) {
+ Aws::DynamoDB::Model::GetItemRequest request;
+ request.AddKey(
+ LogItem::FIELD_BACKUP_ID, Aws::DynamoDB::Model::AttributeValue(backupID));
+ request.AddKey(
+ LogItem::FIELD_LOG_ID, Aws::DynamoDB::Model::AttributeValue(logID));
+
+ return this->innerFindItem<LogItem>(request);
+}
+
std::vector<std::shared_ptr<LogItem>>
DatabaseManager::findLogItemsForBackup(const std::string &backupID) {
std::vector<std::shared_ptr<database::LogItem>> result;
diff --git a/services/backup/test/DatabaseManagerTest.cpp b/services/backup/test/DatabaseManagerTest.cpp
--- a/services/backup/test/DatabaseManagerTest.cpp
+++ b/services/backup/test/DatabaseManagerTest.cpp
@@ -69,13 +69,35 @@
std::vector<std::string> logIDs1 = {"log001", "log002", "log003"};
for (const std::string &logID : logIDs1) {
- DatabaseManager::getInstance().putLogItem(
- generateLogItem(backupID1, logID));
+ LogItem generatedItem = generateLogItem(backupID1, logID);
+ DatabaseManager::getInstance().putLogItem(generatedItem);
+ std::shared_ptr<LogItem> foundItem =
+ DatabaseManager::getInstance().findLogItem(backupID1, logID);
+ EXPECT_NE(foundItem, nullptr);
+ EXPECT_EQ(foundItem->getBackupID(), generatedItem.getBackupID());
+ EXPECT_EQ(foundItem->getLogID(), generatedItem.getLogID());
+ EXPECT_EQ(
+ foundItem->getPersistedInBlob(), generatedItem.getPersistedInBlob());
+ EXPECT_EQ(foundItem->getValue(), generatedItem.getValue());
+ EXPECT_EQ(
+ foundItem->getAttachmentHolders(),
+ generatedItem.getAttachmentHolders());
}
std::vector<std::string> logIDs2 = {"log021", "log022"};
for (const std::string &logID : logIDs2) {
- DatabaseManager::getInstance().putLogItem(
- generateLogItem(backupID2, logID));
+ LogItem generatedItem = generateLogItem(backupID2, logID);
+ DatabaseManager::getInstance().putLogItem(generatedItem);
+ std::shared_ptr<LogItem> foundItem =
+ DatabaseManager::getInstance().findLogItem(backupID2, logID);
+ EXPECT_NE(foundItem, nullptr);
+ EXPECT_EQ(foundItem->getBackupID(), generatedItem.getBackupID());
+ EXPECT_EQ(foundItem->getLogID(), generatedItem.getLogID());
+ EXPECT_EQ(
+ foundItem->getPersistedInBlob(), generatedItem.getPersistedInBlob());
+ EXPECT_EQ(foundItem->getValue(), generatedItem.getValue());
+ EXPECT_EQ(
+ foundItem->getAttachmentHolders(),
+ generatedItem.getAttachmentHolders());
}
std::vector<std::shared_ptr<LogItem>> items1 =
@@ -90,6 +112,9 @@
for (size_t i = 0; i < items1.size(); ++i) {
EXPECT_EQ(logIDs1.at(i), items1.at(i)->getLogID());
DatabaseManager::getInstance().removeLogItem(items1.at(i));
+ EXPECT_EQ(
+ DatabaseManager::getInstance().findLogItem(backupID1, logIDs1.at(i)),
+ nullptr);
}
EXPECT_EQ(
DatabaseManager::getInstance().findLogItemsForBackup(backupID1).size(),
@@ -98,6 +123,9 @@
for (size_t i = 0; i < items2.size(); ++i) {
EXPECT_EQ(logIDs2.at(i), items2.at(i)->getLogID());
DatabaseManager::getInstance().removeLogItem(items2.at(i));
+ EXPECT_EQ(
+ DatabaseManager::getInstance().findLogItem(backupID2, logIDs2.at(i)),
+ nullptr);
}
EXPECT_EQ(
DatabaseManager::getInstance().findLogItemsForBackup(backupID2).size(),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 16, 9:08 AM (12 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2497105
Default Alt Text
D4079.diff (4 KB)
Attached To
Mode
D4079: [services] Backup - Database manager - Add findLogItem
Attached
Detach File
Event Timeline
Log In to Comment