Beispiel #1
0
 def test_register_duplicated_handler(self):
     """
     Tests registration duplicated entry point
     """
     ep1 = entry_point.EntryPoint("service1", "method1")
     ep2 = entry_point.EntryPoint("service2", "method2")
     message_type = "request"
     handler_method_name = "method_name"
     self.dispatcher.register(ep1, message_type, handler_method_name)
     self.assertRaises(exceptions.DuplicatedMethodRegistration,
                       self.dispatcher.register, ep2, message_type,
                       handler_method_name)
Beispiel #2
0
    def decorator(cls):
        import service
        if not issubclass(cls, service.ServiceController):
            raise exceptions.NeedToBeController(service=str(cls))

        cls.service_name = service_name
        for method_name in dir(cls):
            method = getattr(cls, method_name)

            # if method is handler then register it in dispatcher
            if hasattr(method, "_method_name") \
                and hasattr(method, "_service_name") \
                    and hasattr(method, "_method_type"):

                # register service in router to define message controller
                # class
                router.Router().register(method._service_name,
                                         cls)
                ep = entry_point.EntryPoint(method._service_name,
                                            method._method_name)
                cls.get_dispatcher().register(ep,
                                              method._method_type,
                                              method_name)

        return cls
Beispiel #3
0
 def test_get_handler_for_unregistered_entry_point(self):
     """
     Tests get handler for unregistered entry point
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "request"
     self.assertRaises(exceptions.HandlerNotFound,
                       self.dispatcher.get_handler, ep, message_type)
Beispiel #4
0
 def test_get_handler_for_unknown_message_type(self):
     """
     Tests get handler for unknown message type
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "zzz"
     self.assertRaises(exceptions.HandlerNotFound,
                       self.dispatcher.get_handler, ep, message_type)
Beispiel #5
0
 def test_get_handler_positive(self):
     """
     Tests get handler registered for ep
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "request"
     method_name = "method_name"
     self.dispatcher.register(ep, message_type, method_name)
     self.assertEqual(self.dispatcher.get_handler(ep, message_type),
                      method_name)
Beispiel #6
0
 def test_register_entry_point_handler_positive(self):
     """
     Tests successful handler registration for entry point
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "request"
     method_name = "method_name"
     self.dispatcher.register(ep, message_type, method_name)
     self.assertEqual(self.dispatcher.handlers[message_type][str(ep)],
                      method_name)
Beispiel #7
0
 def test_get_request_entry_services(self):
     """
     Tests entry point's services for requests
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "request"
     method_name = "method_name"
     self.dispatcher.register(ep, message_type, method_name)
     res = list(self.dispatcher.get_request_entry_services())
     self.assertListEqual(res, [ep.service])
Beispiel #8
0
 def test_get_publishers(self):
     """
     Tests entry points for publishers
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "notification"
     method_name = "method_name"
     self.dispatcher.register(ep, message_type, method_name)
     res = list(self.dispatcher.get_publishers())
     self.assertListEqual(res, [ep])
Beispiel #9
0
 def test_register_duplicated_entry_point(self):
     """
     Tests registration duplicated entry point
     """
     ep = entry_point.EntryPoint("service", "method")
     message_type = "request"
     method_name = "method_name"
     self.dispatcher.register(ep, message_type, method_name)
     self.assertRaises(exceptions.DuplicatedEntryPointRegistration,
                       self.dispatcher.register, ep, message_type,
                       method_name)
Beispiel #10
0
 def test_ep_routing_key(self):
     service_name = "some_service"
     method_name = "some_method"
     rk = "some_service.some_method"
     ep = entry_point.EntryPoint(service_name, method_name)
     self.assertEqual(ep.to_routing_key(), rk)