Commits

Anonymous committed 88eceda Draft

selection of marshalling works

Comments (0)

Files changed (12)

         self._logger.debug("Adding websocket '%s'" % web_socket_name)
         #self._logger.debug("### %s" % web_socket.__class__)
 
+        web_socket_conf = self._plugin_manager.plugin_subconfig(
+            "araldo.endpoints.inbound", web_socket_name)
+
         endpoint = InOutBound(
-            config=self._config,
+            config=web_socket_conf,
             gevent_queue=self._queue,
             name=web_socket_name,
             plugin_manager=self._plugin_manager,
                 required(
                     "araldo.endpoints.inbound"):
                 [{
-                    "name": str,
-                    "id": str,
-                    "host": str,
-                    "port": port_spec,
-                    "channel": str
+                    v.optional("instantiate"): bool,
+                    v.extra: object,
                 }],
                 required(
                     "araldo.endpoints.outbound"):
                 [{
-                    "name": str,
-                    "id": str,
-                    "host": str,
-                    "port": port_spec,
-                    "channel": str
+                    v.optional("instantiate"): bool,
+                    v.extra: object,
                 }],
                 required(
                     "araldo.marshalling"):

araldo/endpoints/__init__.py

         self._logger = logging.getLogger("araldo")
         self._plugin_manager = kwargs["plugin_manager"]
         self._config = kwargs["config"]
-
-        marshalling_name = kwargs.get("marshalling", "marshal-default")
+        #import pdb; pdb.set_trace()
+        marshalling_name = self._config.get("marshalling", "marshal-json")
         self._marshalling = self._get_marshalling(marshalling_name)
 
     def _get_marshalling(self, marshalling_name):

araldo/marshalling/json_marshalling.py

     def plugin_id():
         """ :return: ID of plugin
         """
-        return "marshal-default"
+        return "marshal-json"
 
     def to_internal_format(self, message_str):
         obj = json.loads(message_str)

araldo/marshalling/raw.py

     def plugin_id():
         """ :return: ID of plugin
         """
-        return "marshal-default"
+        return "marshal-raw"
 
     def to_internal_format(self, message_str):
         return Message(

araldo/plugin_manager.py

         if plugin_name in container:
             del container[plugin_name]
 
+    def plugin_subconfig(
+            self, plugin_group_key, plugin_name):
+        plugin_configs = self._config.settings()["plugins"]
+        group_configs = plugin_configs[plugin_group_key]
+        sub_config = filter(
+            lambda x: x["name"] == plugin_name,
+            group_configs)[0]
+        return sub_config
+
     def _load_plugins_for_group(self, group, class_name):
         """ Load plugins for a particular group
         """
             self._log.debug("Plugin group '%s'" % plugin_group_key)
             for plugin_config in plugin_group:
                 self._log.debug("plugin_config: %s" % plugin_config)
-                plugin_instance = self._instantiate_plugin(
-                    plugin_group_key,
-                    plugin_config)
-                plugin_name = plugin_config["name"]
-                self.add_plugin_instance(
-                    plugin_group_key,
-                    plugin_name,
-                    plugin_instance)
+                instantiate = plugin_config.get("instantiate", True)
+                if instantiate:
+                    plugin_instance = self._instantiate_plugin(
+                        plugin_group_key,
+                        plugin_config)
+                    plugin_name = plugin_config["name"]
+                    self.add_plugin_instance(
+                        plugin_group_key,
+                        plugin_name,
+                        plugin_instance)
+                else:
+                    self._log.debug("No automatic instantiation")
         self._log.debug(
             "Plugin instances: %s",
             self._plugin_instances)

functest/websocket_test/websockettest.js

 $(function(){
     "use strict";
+    var MAX_MESSAGE_DISPLAY_LEN = 100;
     console.log("loaded");
 
 
                     console.log("Message too long to display");
                 }
                 $receivedMessageSizeSpan.text(evt.data.length);
-                $messageSpan.text(evt.data.substring(0,100) + "...");
+                var dataLen = data.length;
+                var ellipsis = dataLen > MAX_MESSAGE_DISPLAY_LEN ? "..." : "";
+                $messageSpan.text(evt.data.substring(0, MAX_MESSAGE_DISPLAY_LEN) + ellipsis);
             };
             ws.onerror = function(evt){
                 console.log("onerror");
     ],
     entry_points={
         "araldo.marshalling": [
-            "default-marshalling = araldo.marshalling.json_marshalling"
-            "raw-marshalling = araldo.marshalling.raw_marshalling"
+            "default-marshalling = araldo.marshalling.json_marshalling",
+            "raw-marshalling = araldo.marshalling.raw"
         ]
     },
     classifiers=[
         'Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware',
         'Topic :: Software Development :: Libraries'
     ],
-    keywords='websockets pubsub publish subscribe message queue push',
+    keywords='websockets pubsub publish subscribe message queue push notification',
     license='The MIT License (MIT)',
 )

test/conf_test.py

     del conf1._conf["routes"]
     with pytest.raises(ConfigException):
         conf1._validate(conf1._conf)
-
-
-def test_incorrect_type(conf1_name):
-    conf1 = Config.create(conf1_name)
-    conf1._conf["plugins"]["araldo.endpoints.inbound"][0]["port"] = "a"
-    with pytest.raises(ConfigException):
-        conf1._validate(conf1._conf)

test/endpoint_websocket_test.py

 from gevent.queue import Queue
 from geventwebsocket import WebSocketError
 from araldo.endpoints import websocket as sut
-from araldo.config import Config
 from araldo.marshalling import json_marshalling
 from araldo.message import Message
 
 
 @pytest.fixture
-def conf1_name():
-    return "testfiles/conf1.yaml"
-
-
-@pytest.fixture
-def config(conf1_name):
-    return Config(conf1_name)
+def sub_config():
+    return {
+        "marshalling": "marshal_json"
+    }
 
 
 @pytest.fixture
 
 
 @pytest.fixture
-def endpoint(config, queue, plugin_manager, valid_socket):
+def endpoint(sub_config, queue, plugin_manager, valid_socket):
     with patch.object(sut.InOutBound, "_get_marshalling") as getm:
         getm.return_value = json_marshalling.Marshalling()
         result = sut.InOutBound(
-            config=config,
+            config=sub_config,
             gevent_queue=queue,
             name="test_websocket",
             plugin_manager=plugin_manager,

test/endpoints_test.py

 
 
 @pytest.fixture
-def marshal_default():
+def marshal_json():
     return Mock()
 
 
 @pytest.fixture
-def plugin_manager(marshal_default):
+def plugin_manager(marshal_json):
     plugin_manager = Mock()
     plugin_manager.plugin_instances.return_value = {
         "araldo.marshalling": {
-            "marshal-default": marshal_default
+            "marshal-json": marshal_json
         }
     }
     return plugin_manager
     assert "testmessage" == str(exception)
 
 
-def test_inbound_instantiation(queue, plugin_manager, marshal_default):
+def test_inbound_instantiation(queue, plugin_manager, marshal_json):
     class C(InBoundBase):
         pass
     conf = {}
     assert conf == c.config()
     assert queue == c.gevent_queue
     assert plugin_manager == c.plugin_manager()
-    assert c.marshalling() == marshal_default
+    assert c.marshalling() == marshal_json
 
 
 def test_outbound_instantiation(
         outbound_derived,
         plugin_manager,
-        marshal_default):
+        marshal_json):
     conf = {}
     c = outbound_derived(
         name="testname",
     assert c.config() == conf
     assert c.name() == "testname"
     assert c.plugin_manager() == plugin_manager
-    assert c.marshalling() == marshal_default
+    assert c.marshalling() == marshal_json
 
 
 def test_outbound_instantiation_explicit_marshalling(
         outbound_derived,
         plugin_manager):
-    conf = {}
+    conf = {
+        "marshalling": "marshal-test"
+    }
     test_marshal = Mock()
     plugin_instances = plugin_manager.plugin_instances()
     marshalling_instances = plugin_instances["araldo.marshalling"]
     marshalling_instances["marshal-test"] = test_marshal
     c = outbound_derived(
         name="testname",
-        marshalling="marshal-test",
         plugin_manager=plugin_manager,
         config=conf)
     assert c.config() == conf

testfiles/conf1.yaml

 
 plugins:
   araldo.marshalling:
-    - name: marshal-default
-      id: marshal-default
+    - name: marshal-json
+      id: marshal-json
   araldo.endpoints.inbound:
     - name: redis_in_1
       id: inbound-redis