def test_pubsub(self):
        services = [{"name": "data_pubsub", "module": "ion.services.dm.datapubsub", "class": "DataPubsubService"}]

        sup = yield self._spawn_processes(services)

        dpsc = DataPubsubClient(sup)
        topic_name = yield dpsc.define_topic("topic1")
        logging.info("Service reply: " + str(topic_name))

        dc1 = DataConsumer()
        dc1_id = yield dc1.spawn()
        yield dc1.attach(topic_name)

        dmsg = self._get_datamsg({}, [1, 2, 1, 4, 3, 2])
        yield sup.send(topic_name, "data", dmsg)

        # Need to await the delivery of data messages into the (separate) consumers
        yield pu.asleep(1)

        self.assertEqual(dc1.receive_cnt, 1)

        # Create a second data consumer
        dc2 = DataConsumer()
        dc2_id = yield dc2.spawn()
        yield dc2.attach(topic_name)

        dmsg = self._get_datamsg({}, [1, 2, 1, 4, 3, 2])
        yield sup.send(topic_name, "data", dmsg, {})

        # Need to await the delivery of data messages into the (separate) consumers
        yield pu.asleep(1)

        self.assertEqual(dc1.receive_cnt, 2)
        self.assertEqual(dc2.receive_cnt, 1)
    def test_chainprocess(self):
        # This test covers a chain of three data consumer processes on three
        # topics. One process is an event-detector and data-filter, sending
        # event messages to an event queue and a new data message to a different
        # data queue

        services = [{"name": "data_pubsub", "module": "ion.services.dm.datapubsub", "class": "DataPubsubService"}]

        sup = yield self._spawn_processes(services)

        dpsc = DataPubsubClient(sup)
        topic_raw = yield dpsc.define_topic("topic_raw")
        topic_qc = yield dpsc.define_topic("topic_qc")
        topic_evt = yield dpsc.define_topic("topic_qcevent")

        dc1 = DataConsumer()
        dc1_id = yield dc1.spawn()
        yield dc1.attach(topic_raw)
        dp = DataProcess(proc)
        dc1.set_ondata(dp.get_ondata())

        dc2 = DataConsumer()
        dc2_id = yield dc2.spawn()
        yield dc2.attach(topic_qc)

        dc3 = DataConsumer()
        dc3_id = yield dc3.spawn()
        yield dc3.attach(topic_evt)

        # Create an example data message with time
        dmsg = self._get_datamsg(
            {}, [(101, 5), (102, 2), (103, 4), (104, 5), (105, -1), (106, 9), (107, 3), (108, 888), (109, 3), (110, 4)]
        )
        yield sup.send(topic_raw, "data", dmsg, {})

        # Need to await the delivery of data messages into the consumers
        yield pu.asleep(2)

        self.assertEqual(dc1.receive_cnt, 1)
        self.assertEqual(dc2.receive_cnt, 1)
        self.assertEqual(dc3.receive_cnt, 2)

        dmsg = self._get_datamsg(
            {}, [(111, 8), (112, 6), (113, 4), (114, -2), (115, -1), (116, 5), (117, 3), (118, 1), (119, 4), (120, 5)]
        )
        yield sup.send(topic_raw, "data", dmsg, {})

        # Need to await the delivery of data messages into the consumers
        yield pu.asleep(2)

        self.assertEqual(dc1.receive_cnt, 2)
        self.assertEqual(dc2.receive_cnt, 2)
        self.assertEqual(dc3.receive_cnt, 4)