Exemplo n.º 1
0
// test endpoint_declare and endpoint_undeclare
BOOST_FIXTURE_TEST_CASE( endpoint_declare, ServerFixture ) {
    startClient();
    WAIT_FOR(connReady(processor.getPool(), LOCALHOST, 8009), 1000);

    StoreClient::notif_t notifs;

    URI u1("/");
    shared_ptr<ObjectInstance> oi1 = make_shared<ObjectInstance>(1);
    client1->put(1, u1, oi1);

    // check add
    URI u2_1("/class2/42/");
    shared_ptr<ObjectInstance> oi2_1 = make_shared<ObjectInstance>(2);
    oi2_1->setInt64(4, 42);
    client1->put(2, u2_1, oi2_1);

    URI u2_2("/class2/43/");
    shared_ptr<ObjectInstance> oi2_2 = make_shared<ObjectInstance>(2);
    oi2_2->setInt64(4, 43);
    client1->put(2, u2_2, oi2_2);

    client1->queueNotification(1, u1, notifs);
    client1->queueNotification(2, u2_1, notifs);
    client1->queueNotification(2, u2_2, notifs);
    client1->deliverNotifications(notifs);
    notifs.clear();

    StoreClient* rclient = mockServer.getSystemClient();
    WAIT_FOR(itemPresent(rclient, 2, u2_1), 1000);
    WAIT_FOR(itemPresent(rclient, 2, u2_2), 1000);
    shared_ptr<const ObjectInstance> roi2_2 = rclient->get(2, u2_2);
    BOOST_CHECK_EQUAL(43, roi2_2->getInt64(4));

    // check update
    MAC mac("aa:bb:cc:dd:ee:ff");
    oi2_1->setMAC(15, mac);
    client1->put(2, u2_1, oi2_1);
    client1->queueNotification(2, u2_1, notifs);
    client1->deliverNotifications(notifs);
    notifs.clear();

    WAIT_FOR(rclient->get(2, u2_1)->isSet(15, PropertyInfo::MAC), 1000);
    BOOST_CHECK_EQUAL(mac, rclient->get(2, u2_1)->getMAC(15));
    
    // check delete
    client1->remove(2, u2_2, true, &notifs);
    client1->queueNotification(2, u2_2, notifs);
    client1->deliverNotifications(notifs);
    notifs.clear();

    WAIT_FOR(!itemPresent(rclient, 2, u2_2), 1000);
    BOOST_CHECK(itemPresent(rclient, 2, u2_1));
    
}
Exemplo n.º 2
0
// Test garbage collection after removing references
BOOST_FIXTURE_TEST_CASE( dereference, Fixture ) {
    StoreClient::notif_t notifs;
    URI c4u("/class4/test/");
    URI c5u("/class5/test/");
    URI c6u("/class4/test/class6/test2/");
    shared_ptr<ObjectInstance> oi5 = make_shared<ObjectInstance>(5);
    oi5->setString(10, "test");
    oi5->addReference(11, 4, c4u);

    shared_ptr<ObjectInstance> oi4 = make_shared<ObjectInstance>(4);
    oi4->setString(9, "test");
    shared_ptr<ObjectInstance> oi6 = make_shared<ObjectInstance>(6);
    oi6->setString(13, "test2");

    client2->put(5, c5u, oi5);
    client2->queueNotification(5, c5u, notifs);
    client2->deliverNotifications(notifs);
    notifs.clear();

    BOOST_CHECK(itemPresent(client2, 5, c5u));
    WAIT_FOR(processor.getRefCount(c4u) > 0, 1000);

    client2->put(4, c4u, oi4);
    client2->put(6, c6u, oi6);
    client2->addChild(4, c4u, 12, 6, c6u);

    processor.remoteObjectUpdated(4, c4u);
    processor.remoteObjectUpdated(6, c6u);

    client2->queueNotification(4, c4u, notifs);
    client2->queueNotification(6, c6u, notifs);
    client2->deliverNotifications(notifs);
    notifs.clear();
 
    BOOST_CHECK(itemPresent(client2, 4, c4u));
    BOOST_CHECK(itemPresent(client2, 6, c6u));

    client2->remove(5, c5u, false, &notifs);
    client2->queueNotification(5, c5u, notifs);
    client2->deliverNotifications(notifs);
    notifs.clear();

    BOOST_CHECK(!itemPresent(client2, 5, c5u));
    WAIT_FOR(!itemPresent(client2, 4, c4u), 1000);
    BOOST_CHECK_EQUAL(0, processor.getRefCount(c4u));
    WAIT_FOR(!itemPresent(client2, 6, c6u), 1000);
}
Exemplo n.º 3
0
BOOST_FIXTURE_TEST_CASE( mo_deserialize , BaseFixture ) {
    StoreClient::notif_t notifs;

    static const char buffer[] = 
        "{\"result\":{\"policy\":[{\"subject\":\"class1\",\"uri\""
        ":\"/\",\"properties\":[{\"name\":\"prop2\",\"data\":[\"te"
        "st1\",\"test2\"]},{\"name\":\"prop1\",\"data\":42}],\"chi"
        "ldren\":[\"/class2/-84\",\"/class2/-42\"]},{\"subject\":"
        "\"class2\",\"uri\":\"/class2/-84\",\"properties\":[{\"na"
        "me\":\"prop4\",\"data\":-84}],\"children\":[],\"parent_su"
        "bject\":\"class1\",\"parent_uri\":\"/\",\"parent_relatio"
        "n\":\"class2\"},{\"subject\":\"class2\",\"uri\":\"/class"
        "2/-42\",\"properties\":[{\"name\":\"prop4\",\"data\":-42}"
        "],\"children\":[],\"parent_subject\":\"class1\",\"parent_"
        "uri\":\"/\",\"parent_relation\":\"class2\"}],\"prr\":360"
        "0},\"id\":42}";

    MOSerializer serializer(&db);
    StoreClient& sysClient = db.getStoreClient("_SYSTEM_");
    Document d;
    d.Parse(buffer);
    const Value& result = d["result"];
    const Value& policy = result["policy"];
    BOOST_CHECK(policy.IsArray());
    for (SizeType i = 0; i < policy.Size(); ++i) {
        serializer.deserialize(policy[i], sysClient, false, &notifs);
    }
    
    URI uri("/");
    URI uri2("/class2/-42");
    URI uri3("/class2/-84");
    shared_ptr<const ObjectInstance> oi = sysClient.get(1, uri);
    shared_ptr<const ObjectInstance> oi2 = sysClient.get(2, uri2);

    BOOST_CHECK_EQUAL(42, oi->getUInt64(1));
    BOOST_CHECK_EQUAL(2, oi->getStringSize(2));
    BOOST_CHECK_EQUAL("test1", oi->getString(2, 0));
    BOOST_CHECK_EQUAL("test2", oi->getString(2, 1));
    BOOST_CHECK_EQUAL(-42, oi2->getInt64(4));

    std::vector<URI> children;
    sysClient.getChildren(2, uri, 3, 2, children);
    BOOST_CHECK_EQUAL(2, children.size());
    BOOST_CHECK(uri2.toString() == children.at(0).toString() ||
                uri3.toString() == children.at(0).toString());
    BOOST_CHECK(uri2.toString() == children.at(1).toString() ||
                uri3.toString() == children.at(1).toString());
    children.clear();

    BOOST_CHECK(notifs.find(uri) != notifs.end());
    BOOST_CHECK(notifs.find(uri2) != notifs.end());
    BOOST_CHECK(notifs.find(uri3) != notifs.end());
    notifs.clear();

    // remove both children
    static const char buffer2[] = 
        "{\"result\":{\"policy\":[{\"subject\":\"class1\",\"uri\""
        ":\"/\",\"properties\":[{\"name\":\"prop2\",\"data\":[\"te"
        "st3\",\"test4\"]},{\"name\":\"prop1\",\"data\":84}],\"chi"
        "ldren\":[]}],\"prr\":360"
        "0},\"id\":42}";
    Document d2;
    d2.Parse(buffer2);
    const Value& result2 = d2["result"];
    const Value& policy2 = result2["policy"];
    BOOST_CHECK(policy2.IsArray());
    for (SizeType i = 0; i < policy2.Size(); ++i) {
        serializer.deserialize(policy2[i], sysClient, true, &notifs);
    }

    oi = sysClient.get(1, uri);
    BOOST_CHECK_EQUAL(84, oi->getUInt64(1));
    BOOST_CHECK_EQUAL(2, oi->getStringSize(2));
    BOOST_CHECK_EQUAL("test3", oi->getString(2, 0));
    BOOST_CHECK_EQUAL("test4", oi->getString(2, 1));
    BOOST_CHECK_THROW(sysClient.get(2, uri2), out_of_range);

    BOOST_CHECK(notifs.find(uri) != notifs.end());
    BOOST_CHECK(notifs.find(uri2) != notifs.end());
    BOOST_CHECK(notifs.find(uri3) != notifs.end());
    notifs.clear();

    // restore original
    for (SizeType i = 0; i < policy.Size(); ++i) {
        serializer.deserialize(policy[i], sysClient, true, &notifs);
    }
    sysClient.getChildren(2, uri, 3, 2, children);
    BOOST_CHECK_EQUAL(2, children.size());
    children.clear();

    BOOST_CHECK(notifs.find(uri) != notifs.end());
    BOOST_CHECK(notifs.find(uri2) != notifs.end());
    BOOST_CHECK(notifs.find(uri3) != notifs.end());
    notifs.clear();

    // remove only one child
    static const char buffer3[] = 
        "{\"result\":{\"policy\":[{\"subject\":\"class1\",\"uri\""
        ":\"/\",\"properties\":[{\"name\":\"prop2\",\"data\":[\"te"
        "st1\",\"test2\"]},{\"name\":\"prop1\",\"data\":42}],\"chi"
        "ldren\":[\"/class2/-84\"]}],\"prr\":3600},\"id\":42}";
    Document d3;
    d3.Parse(buffer3);
    const Value& result3 = d3["result"];
    const Value& policy3 = result3["policy"];
    BOOST_CHECK(policy3.IsArray());
    for (SizeType i = 0; i < policy3.Size(); ++i) {
        serializer.deserialize(policy3[i], sysClient, true, &notifs);
    }
    sysClient.getChildren(2, uri, 3, 2, children);
    BOOST_CHECK_EQUAL(1, children.size());
    BOOST_CHECK_EQUAL(uri3.toString(), children.at(0).toString());
    children.clear();

    // Notify parent that child removed
    BOOST_CHECK(notifs.find(uri) != notifs.end());
    // child changed
    BOOST_CHECK(notifs.find(uri2) != notifs.end());
    // child not changed
    BOOST_CHECK(notifs.find(uri3) == notifs.end());
    notifs.clear();

    // Don't change anything
    for (SizeType i = 0; i < policy3.Size(); ++i) {
        serializer.deserialize(policy3[i], sysClient, true, &notifs);
    }
    sysClient.getChildren(2, uri, 3, 2, children);
    BOOST_CHECK_EQUAL(1, children.size());
    BOOST_CHECK_EQUAL(uri3.toString(), children.at(0).toString());
    BOOST_CHECK_EQUAL(0, notifs.size());
}