Exemplo n.º 1
0
 def test_registry_can_register_worker_methods(self):
     def func():
         return 123
     r = Registry()
     r.method(func)
     assert r['func'] is func
Exemplo n.º 2
0
 def test_calling_registry_dispatches_to_method(self):
     r = Registry()
     r['method'] = lambda x: x + 12
     assert r('method', 24) == 36
Exemplo n.º 3
0
 def test_registry_method_decorator_accepts_explicit_names(self):
     r = Registry()
     @r.method(name='some_method')
     def func():
         return 123
     assert r['some_method'] is func
Exemplo n.º 4
0
 def test_registry_method_can_be_used_as_a_decorator(self):
     r = Registry()
     @r.method
     def func():
         return 123
     assert r['func'] is func
Exemplo n.º 5
0
 def test_registry_can_register_worker_methods_with_explicit_names(self):
     def func():
         return 123
     r = Registry()
     r.method(func, name='some_method')
     assert r['some_method'] is func
Exemplo n.º 6
0
from __future__ import with_statement

from contextlib import contextmanager
from Queue import Queue
import threading

from bson import BSON
from nose.tools import assert_equal
import zmq

from zrpc.concurrency import Callback
from zrpc.server import Server
from zrpc.registry import Registry

REGISTRY = Registry()


@REGISTRY.method
def add(x, y):
    return x + y


@REGISTRY.method
def raises_error():
    raise Exception("some error occurred")


@contextmanager
def server(addr, registry, connect=False, context=None):
    context = context or zmq.Context.instance()