Esempio n. 1
0
 def start(self):
     berrymq.regist_method("*", self.message_receiver)
     berrymq.init_connection(PRIMARY_NODE_URL)
     berrymq.interconnect(SECONDARY_NODE_URL)
     berrymq.twitter("style01c:test01")
     time.sleep(1)
     return True
Esempio n. 2
0
def primary_node():
    global jsonserver
    jsonserver = berrymq.jsonrpc.server.SimpleJSONRPCServer(CONTROL_SERVER_URL)
    jsonserver.register_instance(TestSuite(), allow_dotted_names=True)
    jsonserver.register_function(quit)
    print "start primary server. waiting secondary node."

    @berrymq.following_function("style03s:*")
    def receive_messages(message):
        _primary_node_test_result.append(message)

    berrymq.twitter("start primary server:info")
    jsonserver.serve_forever()
Esempio n. 3
0
def secondary_node():
    expected_at_secondary = [
        ["style02c:test02", [1, 2, 3], {
            "a": 1,
            "b": 2
        }],
        ["style03c:test01", [3, 2, 1], {
            "a": 1,
            "b": 2
        }],
        ["style03s:test02", (), {}],
        ["style03s:test03", (), {}],
        ["style01c:test01", [], {}],
        ["style01s:test02", (), {}],
    ]
    test_results = []

    @berrymq.following_function("*:*")
    def test_receiver(message):
        expected = expected_at_secondary[0]
        if expected[0] == message.id and \
           expected[1] == message.args and \
           expected[2] == message.kwargs:
            result = "ok"
        else:
            result = "ng"
        del expected_at_secondary[0]
        test_results.append([
            str(expected),
            str([message.id, message.args, message.kwargs]), result
        ])

    berrymq.init_connection(SECONDARY_NODE_URL)

    controller = berrymq.jsonrpc.client.ServerProxy(_url(CONTROL_SERVER_URL))
    controller.style02.start()
    controller.style02.exit()

    controller.style03.start()
    berrymq.twitter("style03s:test02")
    controller.style03.check()
    berrymq.twitter("style03s:test03")
    controller.style03.exit()

    controller.style01.start()
    berrymq.twitter("style01s:test02")
    time.sleep(1)

    controller.style01.exit()
    controller.quit()

    berrymq.close_connection()

    for expected, actual, result in test_results:
        if result == "ok":
            print "ok: expected = %s" % expected
        else:
            print "ng: expected = %s, actual = %s" % (expected, actual)
    if len(test_results) == 0:
        print "ng: no message received"
Esempio n. 4
0
def secondary_node():
    expected_at_secondary = [
        ["style02c:test02", [1,2,3], {"a":1, "b":2}],
        ["style03c:test01", [3,2,1], {"a":1, "b":2}],
        ["style03s:test02", (), {}],
        ["style03s:test03", (), {}],
        ["style01c:test01", [], {}],
        ["style01s:test02", (), {}],
    ]
    test_results = []
    @berrymq.following_function("*:*")
    def test_receiver(message):
        expected = expected_at_secondary[0]
        if expected[0] == message.id and \
           expected[1] == message.args and \
           expected[2] == message.kwargs:
            result = "ok"
        else:
            result = "ng"
        del expected_at_secondary[0]
        test_results.append([str(expected), 
                             str([message.id, message.args, message.kwargs]), 
                             result])
    
    exported_functions = berrymq.connect.ExportedFunctions()
    secondary_node_server = berrymq.jsonrpc.server.SimpleJSONRPCServer(
        SECONDARY_NODE_URL)
    secondary_node_server.register_instance(exported_functions)
    secondary_node_server.serve_forever(in_thread=True)
    controller = berrymq.jsonrpc.client.ServerProxy(_url(CONTROL_SERVER_URL))
    controller.style02.start()
    controller.style02.exit()

    controller.style03.start()
    berrymq.twitter("style03s:test02")
    controller.style03.check()
    berrymq.twitter("style03s:test03")
    controller.style03.exit()

    berrymq.connect.ConnectionPoint.regist_exchanger()
    controller.style01.start()
    berrymq.twitter("style01s:test02")
    time.sleep(1)
    berrymq.connect.ConnectionPoint.clear_exchanger()
    controller.style01.exit()

    controller.quit()
    secondary_node_server.shutdown()

    for expected, actual, result in test_results:
        if result == "ok":
            print("ok: expected = %s" % expected)
        else:
            print("ng: expected = %s, actual = %s" % (expected, actual))
    if len(test_results) == 0:
        print("ng: no message received")
Esempio n. 5
0
 def _checkdir(self):
     while self.running:
         time.sleep(self.interval)
         new_info = self._get_fileinfo()
         old_info = self.fileinfo
         newfiles = set(new_info.keys())
         oldfiles = set(old_info.keys())
         for created_file in (newfiles - oldfiles):
             berrymq.twitter("%s:created" % self.id_name, created_file)
         for remove_file in (oldfiles - newfiles):
             berrymq.twitter("%s:removed" % self.id_name, remove_file)
         for remain_file in (oldfiles & newfiles):
             if new_info[remain_file] != old_info[remain_file]:
                 berrymq.twitter("%s:modified" % self.id_name, remain_file)
         self.fileinfo = new_info
Esempio n. 6
0
 def _checkdir(self):
     while self.running:
         time.sleep(self.interval)
         berrymq.twitter("%s:tick" % self.id_name)