Example #1
0
    def test_logging_module(self):
        log_process = g.start_module('logger')
        netconf = get_network_config()
        mux_addr = netconf.get_address("MUX_in")
        listen_addr = netconf.get_address("console")
        emitter = get_mux_socket(mux_addr)
        consumer = get_source_socket(listen_addr)
        time.sleep(0.01)
        tms = []
        for i in range(1000):
            st = time.time()
            log.info(">>OUT>>")
            emitter.send_json({"app_id": 1, "user_id": 1, "hello": "world"})
            doc = consumer.recv_json()
            consumer.send_string("OK")
            log.info("<<IN<<", doc)
            tms.append(time.time() - st)

        tms = np.array(tms)
        print("|\n|\n|", tms.round(5))
        print("|\n|\n|", np.mean(tms))

        time.sleep(0.01)
        print("Terminating logging process")
        log_process.terminate()
        log_process.join()
Example #2
0
    def test_db_module(self):
        # start db module
        db_process = g.start_module('database')
        # configure connection to dmx
        netconf = get_network_config()
        netapi = NetworkAPI(netconf, 'id1', 'console')

        for i in range(10):
            log.info(">>OUT>>")

            netapi.send({
                "app_id": 1,
                "user_id": 1,
                "action": "put",
                'data': {
                    'foo': i
                }
            })
            doc = netapi.recv()
            netapi.reply_notif("OK")

            log.info("<<IN<< %s" % doc)

        netapi.send({"app_id": 1, "user_id": 1, "action": "get"})

        doc = netapi.recv()
        netapi.reply_notif("OK")

        log.info("<<IN<< %s" % doc)

        print("Terminating logging process")
        db_process.terminate()
        db_process.join()
Example #3
0
 def setUp(self):
     ps = []
     ps.append(g.start_cnf())
     ps.append(g.start_mux())
     ps.append(g.start_dmx(connectors=['console']))
     ps.append(g.start_module('database'))
     time.sleep(0.15)
     netconf = g.get_network_config()
     self.netapi = NetworkAPI(netconf, 'test_db_runner', 'console')
Example #4
0
 def setUp(self):
     self.conf_process = process = g.start_cnf()
     self.mux_p = g.start_mux(parallel=True)
     self.dmx_p = g.start_dmx(connectors=['websocket','login'], parallel=True)
     self.db_process = g.start_module('database')
     self.db_node = g.start_database()
     self.wsproc = processed(start_websocket, name='ws-connector')
     self.flask = processed(start_login_http, name='login_http-conn')
     time.sleep(0.1)
Example #5
0
def main():
    cnf = g.start_cnf()
    mux_p = g.start_mux(parallel=True)
    dmx_p = g.start_dmx(connectors=['websocket'], parallel=True)
    db_process = g.start_module('database')
    start_websocket()
Example #6
0
 def setUp(self):
     self.conf_process = process = g.start_cnf()
     time.sleep(0.1)
     self.mux_p = g.start_mux(parallel=True)
     self.dmx_p = g.start_dmx(connectors=['websocket'], parallel=True)
     self.log_p = g.start_module('logger')
Example #7
0
    def test_db_metrics(self):
        # start db module
        db_process = g.start_module('database')
        time.sleep(0.01)
        # configure connection to dmx
        netconf = get_network_config()
        netapi = NetworkAPI(netconf, 'id1', 'console')

        def send_recv_print(msg):
            log.info(">>OUT>>")
            msg.update({
                'user_id': 1,
                'appid': 1,
            })
            netapi.send(msg)
            doc = netapi.recv()
            netapi.reply_notif("OK")
            log.info("<<IN<< %s" % doc)
            return doc

        metrics_name = 'integral'
        record_name = 'zoo'

        def record_gen(name):
            i = 0
            while True:
                i += 1
                yield {
                    'action': 'put.test.record',
                    'name': name,
                    'value': i,
                    'time': i,
                }

        def record_gen_str(name):
            i = 0
            animals = ('zebra', 'panda', 'grizly', 'cow')
            cnt = len(animals)

            while True:
                i += 1
                yield {
                    'action': 'put.test.record',
                    'name': name,
                    'value': animals[np.random.randint(cnt)],
                    'time': i,
                }

        gen = record_gen_str(record_name)
        # create a new record accumulator
        send_recv_print({'action': 'add.test.record', 'name': record_name})

        for i in range(10):
            record = next(gen)
            send_recv_print(record)
        # get some metrics
        send_recv_print({
            'action': 'get.test.metrics',
            'provider': record_name,
            'name': metrics_name,
            'start': 0,
            'end': 6,
            'step': 2,
        })
Example #8
0
 def test_logging_module(self):
     lproc = g.start_module('logger')
     print("Terminating logging process")
     time.sleep(0.1)
     lproc.terminate()
     lproc.join()