Esempio n. 1
0
TEST(IndexerTest, testPurgeByUser) {
    Indexer i;
    const string username1 = "val";
    const uint64_t postId1 = 666;
    const string username2 = "kim";
    const uint64_t postId2 = 777;

    EXPECT_TRUE(i.index(TTopics({"href", "cv", "date"}), username1, postId1));
    EXPECT_TRUE(i.index(TTopics({"cv"}), username1, postId1 + 1));

    EXPECT_TRUE(i.hasPostTopics(postId1));
    EXPECT_TRUE(i.hasPostTopics(postId1 + 1));
    EXPECT_FALSE(i.hasPostTopics(postId2));
    EXPECT_TRUE(i.hasTopicItem("href"));
    EXPECT_TRUE(i.hasTopicItem("cv"));
    EXPECT_TRUE(i.hasTopicItem("date"));

    EXPECT_EQ(2, i.getTopicItem("cv").postsCount);

    EXPECT_TRUE(i.index(TTopics({"href", "cv"}), username2, postId2));
    EXPECT_TRUE(i.index(TTopics({"cv"}), username2, postId2 + 1));

    EXPECT_TRUE(i.hasPostTopics(postId2));
    EXPECT_TRUE(i.hasPostTopics(postId2 + 1));
    EXPECT_EQ(4, i.getTopicItem("cv").postsCount);
    EXPECT_EQ(2, i.getTopicItem("href").postsCount);

    EXPECT_TRUE(i.purgeByUser(username1));

    EXPECT_FALSE(i.hasPostTopics(postId1));
    EXPECT_FALSE(i.hasPostTopics(postId1 + 1));

    EXPECT_TRUE(i.hasPostTopics(postId2));
    EXPECT_TRUE(i.hasPostTopics(postId2 + 1));
    EXPECT_EQ(2, i.getTopicItem("cv").postsCount);
    EXPECT_EQ(1, i.getTopicItem("href").postsCount);
    EXPECT_FALSE(i.hasTopicItem("date"));

    EXPECT_TRUE(i.purgeByUser(username2));

    EXPECT_FALSE(i.hasPostTopics(postId2));
    EXPECT_FALSE(i.hasPostTopics(postId2 + 1));
    EXPECT_FALSE(i.hasTopicItem("cv"));
    EXPECT_FALSE(i.hasTopicItem("href"));
}
Esempio n. 2
0
TEST(IndexerTest, testGetUserPostIds) {
    Indexer i;
    const string username = "******";
    const uint64_t postId1 = 666;
    const uint64_t postId2 = 777;
    {
        const TTopics topics = {"please", "give", "me", "job"};
        EXPECT_TRUE(i.index(topics, username, postId1));

        EXPECT_FALSE(i.hasTopicItem("unknown"));
        EXPECT_TRUE(i.hasTopicItem("job"));
        auto item = i.getTopicItem("job");
        EXPECT_EQ(1, item.postsCount);
        auto postIds = item.userPostIds;
        EXPECT_EQ(1, postIds.size());
        auto it = postIds.begin();
        EXPECT_EQ(username, it->first);
        EXPECT_EQ(1, it->second.size());
        auto sit = it->second.begin();
        EXPECT_EQ(postId1, *sit);
    }
    {
        const TTopics topics = {"waiting", "for", "job"};
        EXPECT_TRUE(i.index(topics, username, postId2));

        EXPECT_FALSE(i.hasTopicItem("unknown"));
        EXPECT_TRUE(i.hasTopicItem("job"));
        auto item = i.getTopicItem("job");
        EXPECT_EQ(2, item.postsCount);
        auto postIds = item.userPostIds;
        EXPECT_EQ(1, postIds.size());
        auto it = postIds.begin();
        EXPECT_EQ(username, it->first);
        EXPECT_EQ(2, it->second.size());
        auto sit = it->second.begin();
        EXPECT_EQ(postId2, *sit);
        EXPECT_EQ(postId1, *(++sit));
    }
}
Esempio n. 3
0
TEST(IndexerTest, testGetUserPostIdsMultipleUsers) {
    Indexer i;
    const string username1 = "val";
    const string username2 = "kim";
    const uint64_t postId1 = 666;
    const uint64_t postId2 = 777;
    {
        const TTopics topics = {"find", "secret", "on", "valbok.com"};
        EXPECT_TRUE(i.index(topics, username1, postId1));

        auto item = i.getTopicItem("secret");
        auto postIds = item.userPostIds;
        EXPECT_EQ(1, postIds.size());
        auto it = postIds.begin();
        EXPECT_EQ(username1, it->first);
        EXPECT_EQ(1, it->second.size());
        auto sit = it->second.begin();
        EXPECT_EQ(postId1, *sit);
    }
    {
        const TTopics topics = {"open", "secret", "page"};
        EXPECT_TRUE(i.index(topics, username2, postId2));

        auto item = i.getTopicItem("secret");
        auto postIds = item.userPostIds;
        EXPECT_EQ(2, postIds.size());
        auto it = postIds.begin();
        EXPECT_EQ(username2, it->first);
        EXPECT_EQ(1, it->second.size());
        auto sit = it->second.begin();
        EXPECT_EQ(postId2, *sit);
        ++it;
        EXPECT_EQ(username1, it->first);
        EXPECT_EQ(1, it->second.size());
        sit = it->second.begin();
        EXPECT_EQ(postId1, *sit);
    }
}