Beispiel #1
0
// File Sanity check
TEST(FTDCFileTest, TestFileBasicCompress) {
    unittest::TempDir tempdir("metrics_testpath");
    boost::filesystem::path p(tempdir.path());
    p /= kTestFile;

    deleteFileIfNeeded(p);

    BSONObj doc1 = BSON("name"
                        << "joe"
                        << "key1" << 34 << "key2" << 45);
    BSONObj doc2 = BSON("name"
                        << "joe"
                        << "key3" << 34 << "key5" << 45);

    FTDCConfig config;
    FTDCFileWriter writer(&config);

    ASSERT_OK(writer.open(p));

    ASSERT_OK(writer.writeSample(doc1));
    ASSERT_OK(writer.writeSample(doc2));

    writer.close();

    FTDCFileReader reader;
    ASSERT_OK(reader.open(p));

    ASSERT_OK(reader.hasNext());

    BSONObj doc1a = std::get<1>(reader.next());

    ASSERT_TRUE(doc1 == doc1a);

    ASSERT_OK(reader.hasNext());

    BSONObj doc2a = std::get<1>(reader.next());

    ASSERT_TRUE(doc2 == doc2a);

    auto sw = reader.hasNext();
    ASSERT_OK(sw);
    ASSERT_EQUALS(sw.getValue(), false);
}
Beispiel #2
0
// Test a bad file
TEST(FTDCFileTest, TestBadFile) {
    unittest::TempDir tempdir("metrics_testpath");
    boost::filesystem::path p(tempdir.path());
    p /= kTestFile;

    std::ofstream stream(p.c_str());
    // This test case caused us to allocate more memory then the size of the file the first time I
    // tried it
    stream << "Hello World";

    stream.close();

    FTDCFileReader reader;
    ASSERT_OK(reader.open(p));

    auto sw = reader.hasNext();
    ASSERT_NOT_OK(sw);
}