示例#1
0
def main():
    if len(sys.argv) > 1:
        if sys.argv[1] == "master":
            a = AgentIOMaster()
        elif sys.argv[1] == "server":
            a = AgentIOServer()
        elif sys.argv[1] == "client":
            a = AgentIOClient()
        else:
            raise Exception("Unsupported mode " + sys.argv[1])
        a.start_loop()
    else:
        #print("Usage: testagent.py <mode>")
        import lrmq
        lrmq.main({
            "loglevel": "DEBUG",
            "agents": [
                {"name": "master",
                 "id": "test-master",
                 "type": "stdio",
                 "log": "",
                 "loglevel": "DEBUG",
                 "cmd": sys.executable,
                 "args": [sys.argv[0], "master"]
                
                }
            
            ]
        })
示例#2
0
    def test_agent_not_found(self):
        logname = os.path.join(self.logdir.name, "not_found")
        code = lrmq.main({
            "debuglogger":
            logname + ".pkl",
            "loglevel":
            "DEBUG",
            "log":
            logname + "_hub.log",
            "agents": [{
                "type": "stdio",
                "name": "agent_dump",
                "cmd": "test/agent_not_found"
            }]
        })
        assert code == 0

        def check_msg_args(args, event):
            self.assertEqual(args[0], "system/" + event + "_agent/agent_dump")
            pass

        self.verify_log(
            logname + ".pkl",
            [["DEBUG", LogTypes.HUB_LOAD_MODE, {
                "args": ('config', )
            }], ["DEBUG", LogTypes.HUB_AGENT_COUNT, {
                "args": (1, )
            }], ["DEBUG", LogTypes.HUB_LOAD_AGENT, {}],
             ["INFO", LogTypes.HUB_START, {}],
             ["DEBUG", LogTypes.AGENT_PREPARE, {
                 "args": ("agent_dump", )
             }],
             [
                 "DEBUG", LogTypes.HUB_MESSAGE, {
                     "args": lambda x: check_msg_args(x, "prepare")
                 }
             ], ["INFO", LogTypes.AGENT_START, {}],
             ["ERROR", LogTypes.AGENT_EXC_PREPARE, {}],
             [
                 "DEBUG", LogTypes.HUB_MESSAGE, {
                     "args": lambda x: check_msg_args(x, "error")
                 }
             ], ["INFO", LogTypes.HUB_LOOP_END, {}],
             ["INFO", LogTypes.HUB_FINISH, {}], ["return"]])
示例#3
0
 def test_single_master(self):
     logname = os.path.join(self.logdir.name, "single_master")
     code = lrmq.main({
         "debuglogger":
         logname + ".pkl",
         "loglevel":
         "DEBUG",
         "log":
         logname + "_hub.log",
         "agents": [{
             "type": "stdio",
             "cmd": "test/msc1.py",
             "id": "test02_master",
             "name": "test02_master",
             "log": logname + "_master.log",
             "loglevel": "DEBUG",
             "args": ["master"]
         }]
     })
     assert code == 0
     for log in self.read_log(logname + ".pkl"):
         log_id = None
         if "log_id" in log:
             print(log)
示例#4
0
 def test_module(self):
     lrmq.main({"_": None})
示例#5
0
# Command-line utility
# Copyright (c) 2016 Roman Kharin <*****@*****.**>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys
import argparse
import asyncio

import lrmq

if __name__ == "__main__":
    sys.exit(lrmq.main())