Пример #1
0
// Test all types
TEST(FTDCCompressor, Types) {
    TestTie c;

    auto st = c.addSample(BSON("name"
                               << "joe"
                               << "key1" << 33 << "key2" << 42LL));
    ASSERT_HAS_SPACE(st);

    const char bytes[] = {0x1, 0x2, 0x3};
    BSONObj o = BSON("created" << DATENOW                       // date_t
                               << "null" << BSONNULL            // { a : null }
                               << "undefined" << BSONUndefined  // { a : undefined }
                               << "obj" << BSON(                // nested object
                                               "a"
                                               << "abc"
                                               << "b" << 123LL) << "foo"
                               << BSON_ARRAY("bar"
                                             << "baz"
                                             << "qux")               // array of strings
                               << "foo2" << BSON_ARRAY(5 << 6 << 7)  // array of ints
                               << "bindata" << BSONBinData(&bytes[0], 3, bdtCustom)  // bindata
                               << "oid" << OID("010203040506070809101112")           // oid
                               << "bool" << true                                     // bool
                               << "regex" << BSONRegEx("mongodb")                    // regex
                               << "ref" << BSONDBRef("c", OID("010203040506070809101112"))  // ref
                               << "code" << BSONCode("func f() { return 1; }")              // code
                               << "codewscope" << BSONCodeWScope("func f() { return 1; }",
                                                                 BSON("c" << true))  // codew
                               << "minkey" << MINKEY                                 // minkey
                               << "maxkey" << MAXKEY                                 // maxkey
                     );

    st = c.addSample(o);
    ASSERT_SCHEMA_CHANGED(st);

    st = c.addSample(o);
    ASSERT_HAS_SPACE(st);

    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1" << 34LL << "key2" << 45.0f));
    ASSERT_SCHEMA_CHANGED(st);
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1" << static_cast<char>(32) << "key2" << 45.0F));
    ASSERT_HAS_SPACE(st);
}
Пример #2
0
// Test various schema changes
TEST_F(FTDCCompressorTest, TestSchemaChanges) {
    TestTie c;

    auto st = c.addSample(BSON("name"
                               << "joe"
                               << "key1"
                               << 33
                               << "key2"
                               << 42));
    ASSERT_HAS_SPACE(st);
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key2"
                          << 45));
    ASSERT_HAS_SPACE(st);
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key2"
                          << 45));
    ASSERT_HAS_SPACE(st);

    // Add Field
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key2"
                          << 45
                          << "key3"
                          << 47));
    ASSERT_SCHEMA_CHANGED(st);

    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key2"
                          << 45
                          << "key3"
                          << 47));
    ASSERT_HAS_SPACE(st);

    // Rename field
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key5"
                          << 45
                          << "key3"
                          << 47));
    ASSERT_SCHEMA_CHANGED(st);

    // Change type
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key5"
                          << "45"
                          << "key3"
                          << 47));
    ASSERT_SCHEMA_CHANGED(st);

    // Add Field
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key1"
                          << 34
                          << "key2"
                          << 45
                          << "key3"
                          << 47
                          << "key7"
                          << 34
                          << "key9"
                          << 45
                          << "key13"
                          << 47));
    ASSERT_SCHEMA_CHANGED(st);

    // Remove Field
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << 34
                          << "key9"
                          << 45
                          << "key13"
                          << 47));
    ASSERT_SCHEMA_CHANGED(st);

    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << 34
                          << "key9"
                          << 45
                          << "key13"
                          << 47));
    ASSERT_HAS_SPACE(st);

    // Start new batch
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << 5));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field to object
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << BSON(  // nested object
                                 "a" << 1)));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field from object to number
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << 7));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field from number to array
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << BSON_ARRAY(13 << 17)));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field from array to number
    st = c.addSample(BSON("name"
                          << "joe"
                          << "key7"
                          << 19));
    ASSERT_SCHEMA_CHANGED(st);


    // New Schema
    st = c.addSample(BSON("_id" << 1));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field to oid
    st = c.addSample(BSON(GENOID));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field from oid to object
    st = c.addSample(BSON("_id" << BSON("sub1" << 1)));
    ASSERT_SCHEMA_CHANGED(st);

    // Change field from object to oid
    st = c.addSample(BSON(GENOID));
    ASSERT_SCHEMA_CHANGED(st);
}
Пример #3
0
// Test various schema changes with strings
TEST_F(FTDCCompressorTest, TestStringSchemaChanges) {
    TestTie c(FTDCValidationMode::kWeak);

    auto st = c.addSample(BSON("str1"
                               << "joe"
                               << "int1"
                               << 42));
    ASSERT_HAS_SPACE(st);
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int1"
                          << 45));
    ASSERT_HAS_SPACE(st);

    // Add string field
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "str2"
                          << "smith"
                          << "int1"
                          << 47));
    ASSERT_HAS_SPACE(st);

    // Reset schema by renaming a int field
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "str2"
                          << "smith"
                          << "int2"
                          << 48));
    ASSERT_SCHEMA_CHANGED(st);

    // Remove string field
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int2"
                          << 49));
    ASSERT_HAS_SPACE(st);


    // Add string field as last element
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int2"
                          << 50
                          << "str3"
                          << "bar"));
    ASSERT_HAS_SPACE(st);

    // Reset schema by renaming a int field
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int1"
                          << 51
                          << "str3"
                          << "bar"));
    ASSERT_SCHEMA_CHANGED(st);

    // Remove string field as last element
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int1"
                          << 52));
    ASSERT_HAS_SPACE(st);


    // Add 2 string fields
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "str2"
                          << "smith"
                          << "str3"
                          << "foo"
                          << "int1"
                          << 53));
    ASSERT_HAS_SPACE(st);

    // Reset schema by renaming a int field
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "str2"
                          << "smith"
                          << "str3"
                          << "foo"
                          << "int2"
                          << 54));
    ASSERT_SCHEMA_CHANGED(st);

    // Remove 2 string fields
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int2"
                          << 55));
    ASSERT_HAS_SPACE(st);

    // Change string to number
    st = c.addSample(BSON("str1" << 12 << "int1" << 56));
    ASSERT_SCHEMA_CHANGED(st);

    // Change number to string
    st = c.addSample(BSON("str1"
                          << "joe"
                          << "int1"
                          << 67));
    ASSERT_SCHEMA_CHANGED(st);
}