diff --git a/services/tunnelbroker/test/DatabaseManagerTest.cpp b/services/tunnelbroker/test/DatabaseManagerTest.cpp --- a/services/tunnelbroker/test/DatabaseManagerTest.cpp +++ b/services/tunnelbroker/test/DatabaseManagerTest.cpp @@ -298,3 +298,38 @@ database::DatabaseManager::getInstance().removeMessageItem( item.getMessageID()); } + +TEST_F(DatabaseManagerTest, RemoveMessageItemsOlderThenCheckpoint) { + const std::string receiverID = + "mobile:EMQNoQ7b2ueEmQ4QsevRWlXxFCNt055y20T1PHdoYAQRt0S6TLzZWNM6XSvdWqxm"; + const database::MessageItem item( + "bc0c1aa2-bf09-11ec-9d64-0242ac120002", + "mobile:EMQNoQ7b2ueEmQ4QsevRWlXxFCNt055y20T1PHdoYAQRt0S6TLzZWNM6XSvdWqxm", + receiverID, + "lYlNcO6RR4i9UW3G1DGjdJTRRGbqtPya2aj94ZRjIGZWoHwT5MB9ciAgnQf2VafYb9Tl" + "8SZkX37tg4yZ9pOb4lqslY4g4h58OmWjumghVRvrPUZDalUuK8OLs1Qoengpu9wccxAk" + "Bti2leDTNeiJDy36NnwS9aCIUc0ozsMvXfX1gWdBdmKbiRG1LvpNd6S7BNGG7Zly5zYj" + "xz7s6ZUSDoFfZe3eJWQ15ngYhgMw1TsfbECnMVQTYvY6OyqWPBQi5wiftFcluoxor8G5" + "RJ1NEDQq2q2FRfWjNHLhky92C2C7Nnfe4oVzSinfC1319uUkNLpSzI4MvEMi6g5Ukbl7" + "iGhpnX7Hp4xpBL3h2IkvGviDRQ98UvW0ugwUuPxm1NOQpjLG5dPoqQ0jrMst0Bl5rgPw" + "ajjNGsUWmp9r0ST0wRQXrQcY30PoSoqKSlCEgFMLzHWLrPQ86QFyCICismGSe7iBIqdD" + "6d37StvXBzfJoZVU79UeOF2bFvb3DNoArEOe", + "7s6ZUSDoFfZe3eJWQ15ngYhgMw1TsfbECnMVQTYvY6OyqWPBQi5wiftFcluoxor8"); + EXPECT_EQ( + database::DatabaseManager::getInstance().isTableAvailable( + item.getTableName()), + true); + database::DatabaseManager::getInstance().putMessageItem(item); + std::vector> foundItems = + database::DatabaseManager::getInstance().findMessageItemsByReceiver( + receiverID); + EXPECT_NE(foundItems.size(), 0); + const size_t currentCheckpointTimestamp = tools::getCurrentTimestamp(); + database::DatabaseManager::getInstance() + .removeMessageItemsOlderThenDeviceCheckpoint( + item.getToDeviceID(), currentCheckpointTimestamp); + std::vector> foundItems = + database::DatabaseManager::getInstance().findMessageItemsByReceiver( + receiverID); + EXPECT_EQ(foundItems.size(), 0); +}