Esempio n. 1
0
    def test_sync_periodic_publish_noncontinuous(self):
        # create console, find agent
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        # Change noncontinuous property on each publish,
        # should only see 1 publish per each update
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        # find an agent
        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent, query, "some-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)
        self.assertTrue(sp.get_duration() == 10)
        self.assertTrue(sp.get_publish_interval() == 2)

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        sid = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                self.assertTrue(wi.get_handle() == "some-handle")
                if r_count == 1:
                    # first indication - returns all matching objects
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 2)
                    for obj in reply:
                        self.assertTrue(isinstance(obj, QmfData))
                        self.assertTrue(obj.get_object_id() == "p1c1_key2"
                                        or obj.get_object_id() == "p1c1_key1")
                        sid = obj.get_schema_class_id()
                        self.assertTrue(isinstance(sid, SchemaClassId))
                        self.assertTrue(sid.get_package_name() == "package1")
                        self.assertTrue(sid.get_class_name() == "class1")

                else:
                    # verify publish of modified object only!
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    obj = reply[0]
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2")
                    self.assertTrue(obj.get_value("count2") == r_count - 1)
                    # fail test if we receive more than expected
                    self.assertTrue(r_count < 30)

                # now update the noncontinuous field of one of the objects!
                if r_count < 20:
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count2", r_count)

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect at least 1 publish per update
        self.assertTrue(r_count > 10)

        self.console.destroy(10)
Esempio n. 2
0
    def test_sync_refresh(self):
        # create console
        # find one agent
        # subscribe to changes to any object in package1/class1
        # after 3 data indications, refresh
        # verify > 5 more data indications received
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent, query, "my-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)

        # refresh after three subscribe indications, count all
        # indications to verify refresh worked
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() == "my-handle")

                # count1 is continuous, touching it will force a
                # publish on the interval
                self.assertTrue(sid is not None)
                test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                self.assertTrue(test_obj is not None)
                test_obj.set_value("count1", r_count)

                self.console.release_workitem(wi)

                if r_count == 3:
                    rp = self.console.refresh_subscription(
                        sp.get_subscription_id())
                    self.assertTrue(rp)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 5 publish per subscription, more if refreshed
        self.assertTrue(r_count > 5)

        self.console.destroy(10)
Esempio n. 3
0
    def test_async_cancel(self):
        # create console
        # find one agent
        # async subscribe to changes to any object in package1/class1
        # cancel after first data indication
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        rc = self.console.create_subscription(agent,
                                              query,
                                              "my-handle",
                                              _blocking=False)
        self.assertTrue(rc)

        r_count = 0
        sp = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                if wi.get_type() == WorkItem.SUBSCRIBE_RESPONSE:
                    self.assertTrue(wi.get_handle() == "my-handle")
                    sp = wi.get_params()
                    self.assertTrue(
                        isinstance(sp, qmf2.console.SubscribeParams))
                    self.assertTrue(sp.succeeded())
                    self.assertTrue(sp.get_error() == None)
                else:
                    self.assertTrue(
                        wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                    # sp better be set up by now!
                    self.assertTrue(
                        isinstance(sp, qmf2.console.SubscribeParams))
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    self.assertTrue(isinstance(reply[0], QmfData))
                    self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                    sid = reply[0].get_schema_class_id()
                    self.assertTrue(isinstance(sid, SchemaClassId))
                    self.assertTrue(sid.get_package_name() == "package1")
                    self.assertTrue(sid.get_class_name() == "class1")
                    self.assertTrue(wi.get_handle() == "my-handle")

                    # count1 is continuous, touching it will force a
                    # publish on the interval
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count1", r_count)

                if r_count == 3:
                    self.console.cancel_subscription(sp.get_subscription_id())

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect cancel after 3 replies
        self.assertTrue(r_count == 3)

        self.console.destroy(10)
Esempio n. 4
0
    def test_sync_by_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent, query, index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)
            self.assertTrue(sp.get_duration() == 10)
            self.assertTrue(sp.get_publish_interval() == 2)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 2)
                for obj in reply:
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2"
                                    or obj.get_object_id() == "p1c1_key1")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")

                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
Esempio n. 5
0
    def test_sync_by_obj_id_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                            agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match object "p2c1_key2" in schema package2/class1
        sid = SchemaClassId.create("package2", "class1")
        query = QmfQuery.create_id_object("p2c1_key2", sid)

        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent, query, index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for all subscriptions to expire (2x interval w/o
        # indications)
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p2c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package2")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
Esempio n. 6
0
    def test_sync_periodic_publish_noncontinuous(self):
        # create console, find agent
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        # Change noncontinuous property on each publish,
        # should only see 1 publish per each update 
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        # find an agent
        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent,
                                              query,
                                              "some-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)
        self.assertTrue(sp.get_duration() == 10)
        self.assertTrue(sp.get_publish_interval() == 2)

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        sid = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                self.assertTrue(wi.get_handle() == "some-handle")
                if r_count == 1:
                    # first indication - returns all matching objects
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 2)
                    for obj in reply:
                        self.assertTrue(isinstance(obj, QmfData))
                        self.assertTrue(obj.get_object_id() == "p1c1_key2" or
                                        obj.get_object_id() == "p1c1_key1")
                        sid = obj.get_schema_class_id()
                        self.assertTrue(isinstance(sid, SchemaClassId))
                        self.assertTrue(sid.get_package_name() == "package1")
                        self.assertTrue(sid.get_class_name() == "class1")

                else:
                    # verify publish of modified object only!
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    obj = reply[0]
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2")
                    self.assertTrue(obj.get_value("count2") == r_count - 1)
                    # fail test if we receive more than expected
                    self.assertTrue(r_count < 30)


                # now update the noncontinuous field of one of the objects!
                if r_count < 20:
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count2", r_count)

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect at least 1 publish per update
        self.assertTrue(r_count > 10)

        self.console.destroy(10)
Esempio n. 7
0
    def test_async_cancel(self):
        # create console
        # find one agent
        # async subscribe to changes to any object in package1/class1
        # cancel after first data indication
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        rc = self.console.create_subscription(agent,
                                              query,
                                              "my-handle",
                                              _blocking=False)
        self.assertTrue(rc)

        r_count = 0
        sp = None
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                if wi.get_type() == WorkItem.SUBSCRIBE_RESPONSE:
                    self.assertTrue(wi.get_handle() == "my-handle")
                    sp = wi.get_params()
                    self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
                    self.assertTrue(sp.succeeded())
                    self.assertTrue(sp.get_error() == None)
                else:
                    self.assertTrue(wi.get_type() ==
                                    WorkItem.SUBSCRIBE_INDICATION)
                    # sp better be set up by now!
                    self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
                    reply = wi.get_params()
                    self.assertTrue(isinstance(reply, type([])))
                    self.assertTrue(len(reply) == 1)
                    self.assertTrue(isinstance(reply[0], QmfData))
                    self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                    sid = reply[0].get_schema_class_id()
                    self.assertTrue(isinstance(sid, SchemaClassId))
                    self.assertTrue(sid.get_package_name() == "package1")
                    self.assertTrue(sid.get_class_name() == "class1")
                    self.assertTrue(wi.get_handle() == "my-handle")

                    # count1 is continuous, touching it will force a
                    # publish on the interval
                    self.assertTrue(sid is not None)
                    test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                    self.assertTrue(test_obj is not None)
                    test_obj.set_value("count1", r_count)

                if r_count == 3:
                    self.console.cancel_subscription(sp.get_subscription_id())

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect cancel after 3 replies
        self.assertTrue(r_count == 3)

        self.console.destroy(10)
Esempio n. 8
0
    def test_sync_refresh(self):
        # create console
        # find one agent
        # subscribe to changes to any object in package1/class1
        # after 3 data indications, refresh
        # verify > 5 more data indications received
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        # query to match object "p1c1_key2" in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        query = QmfQuery.create_id_object("p1c1_key2", sid)

        agent_app = self.agents[0]
        aname = agent_app.agent.get_name()
        agent = self.console.find_agent(aname, timeout=3)
        self.assertTrue(agent and agent.get_name() == aname)

        # setup subscription on agent

        sp = self.console.create_subscription(agent,
                                              query,
                                              "my-handle")
        self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
        self.assertTrue(sp.succeeded())
        self.assertTrue(sp.get_error() == None)

        # refresh after three subscribe indications, count all
        # indications to verify refresh worked
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p1c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() == "my-handle")

                # count1 is continuous, touching it will force a
                # publish on the interval
                self.assertTrue(sid is not None)
                test_obj = agent_app.agent.get_object("p1c1_key2", sid)
                self.assertTrue(test_obj is not None)
                test_obj.set_value("count1", r_count)

                self.console.release_workitem(wi)

                if r_count == 3:
                    rp = self.console.refresh_subscription(sp.get_subscription_id())
                    self.assertTrue(rp)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 5 publish per subscription, more if refreshed
        self.assertTrue(r_count > 5)

        self.console.destroy(10)
Esempio n. 9
0
    def test_sync_by_obj_id_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match object "p2c1_key2" in schema package2/class1
        sid = SchemaClassId.create("package2", "class1")
        query = QmfQuery.create_id_object("p2c1_key2", sid)

        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent,
                                                  query,
                                                  index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for all subscriptions to expire (2x interval w/o
        # indications)
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 1)
                self.assertTrue(isinstance(reply[0], QmfData))
                self.assertTrue(reply[0].get_object_id() == "p2c1_key2")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package2")
                self.assertTrue(sid.get_class_name() == "class1")
                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)
Esempio n. 10
0
    def test_sync_by_schema(self):
        # create console
        # find all agents
        # subscribe to changes to any object in package1/class1
        # should succeed - verify 1 publish
        self.notifier = _testNotifier()
        self.console = qmf2.console.Console(notifier=self.notifier,
                                              agent_timeout=3)
        self.conn = qpid.messaging.Connection(self.broker)
        self.conn.open()
        self.console.add_connection(self.conn)

        subscriptions = []
        index = 0

        # query to match all objects in schema package1/class1
        sid = SchemaClassId.create("package1", "class1")
        t_params = {QmfData.KEY_SCHEMA_ID: sid}
        query = QmfQuery.create_wildcard(QmfQuery.TARGET_OBJECT,
                                         _target_params=t_params)
        for agent_app in self.agents:
            aname = agent_app.agent.get_name()
            agent = self.console.find_agent(aname, timeout=3)
            self.assertTrue(agent and agent.get_name() == aname)

            # now subscribe to agent

            sp = self.console.create_subscription(agent,
                                                  query,
                                                  index)
            self.assertTrue(isinstance(sp, qmf2.console.SubscribeParams))
            self.assertTrue(sp.succeeded())
            self.assertTrue(sp.get_error() == None)
            self.assertTrue(sp.get_duration() == 10)
            self.assertTrue(sp.get_publish_interval() == 2)

            subscriptions.append([sp, 0])
            index += 1

        # now wait for the (2 * interval) and count the updates
        r_count = 0
        while self.notifier.wait_for_work(4):
            wi = self.console.get_next_workitem(timeout=0)
            while wi is not None:
                r_count += 1
                self.assertTrue(wi.get_type() == WorkItem.SUBSCRIBE_INDICATION)
                reply = wi.get_params()
                self.assertTrue(isinstance(reply, type([])))
                self.assertTrue(len(reply) == 2)
                for obj in reply:
                    self.assertTrue(isinstance(obj, QmfData))
                    self.assertTrue(obj.get_object_id() == "p1c1_key2" or
                                    obj.get_object_id() == "p1c1_key1")
                sid = reply[0].get_schema_class_id()
                self.assertTrue(isinstance(sid, SchemaClassId))
                self.assertTrue(sid.get_package_name() == "package1")
                self.assertTrue(sid.get_class_name() == "class1")

                self.assertTrue(wi.get_handle() < len(subscriptions))
                subscriptions[wi.get_handle()][1] += 1

                self.console.release_workitem(wi)

                wi = self.console.get_next_workitem(timeout=0)

        # expect 1 publish per subscription
        self.assertTrue(r_count == 5)
        for ii in range(len(subscriptions)):
            self.assertTrue(subscriptions[ii][1] == 1)

        self.console.destroy(10)