Esempio n. 1
0
    def __init__(self, context: Context, service: str) -> None:
        self.service = service
        self.url = context.url
        self.context = context
        self.registry = context.get_registry()
        self.endpoints = context.get_endpoints(self.registry, service)
        self.ha = context.get_ha()
        self.lb = context.get_lb(list(self.endpoints.values()))
        self.filter = context.get_filter(self)
        self.available = True
        self.closed = False

        self.watch()
Esempio n. 2
0
 def __init__(self, context: Context) -> None:
     self.name = context.url.get_param("name")
     self.url = context.url
     self.context = context
     self.registry = context.get_registry()
     self.handler: Optional[DogeRPCServer] = None
     self.limit = context.url.get_param("limitConn", "default")
Esempio n. 3
0
    def __init__(self, config_file: str) -> None:
        u"""Cluster 抽象"""
        self.config_file = config_file
        self.config = Config(config_file)
        self.context = Context(self.config.parse_refer(),
                               self.config.parse_registry())

        self.clients: Dict[str, Client] = {}
        self.sem = BoundedSemaphore(1)
Esempio n. 4
0
def server():
    server = StreamServer(
        ("127.0.0.1", 4399),
        DogeRPCServer(
            Context(URL(None, None, None, {"name": ""}),
                    URL(None, None, None, {})),
            SumServer,
        ),
    )
    g = gevent.spawn(server.serve_forever)
    gevent.sleep(0.1)
    yield server
    g.kill()
Esempio n. 5
0
 def test_context(self, server):
     url = URL(
         "127.0.0.1",
         4399,
         params={
             "name": "test",
             "node": "n1",
             "haStrategy": "backupRequestHA",
             "loadBalance": "RandomLB",
         },
     )
     rurl = URL("127.0.0.1", 4399, params={"protocol": "direct"})
     context = Context(url, rurl)
     c = Client(context, "test")
     self.c = c
     assert c.call("sum", 1, 2) == 3
     assert c.call("sum", 1, 2) == 3
     assert c.call("sum", 1, 2) == 3
Esempio n. 6
0
# coding: utf-8

import gevent
import pytest
from gevent import sleep
from mprpc import RPCClient

from doge.common.context import Context
from doge.common.url import URL
from doge.rpc.server import Server

url = URL("127.0.0.1", 4399, params={"name": "test", "node": "n1"})
rurl = URL("127.0.0.1", 2379, params={"ttl": 10})
context = Context(url, rurl)


@pytest.fixture(scope="function")
def server():
    s = Server(context)
    yield s
    s.registry.deregister(s.name, url)
    s.registry.destroy()


class TestServer:
    def teardown_method(self, method):
        self.g.kill()

    def test_server(self, server):
        class Sum:
            def sum(self, x, y):
Esempio n. 7
0
def new_server(config_file: str) -> Server:
    """从配置文件生成server"""
    config = Config(config_file)
    context = Context(config.parse_service(), config.parse_registry())
    return Server(context)
Esempio n. 8
0
 def __init__(self, context: Context, cls: Type) -> None:
     super().__init__()
     self._name = context.url.get_param("name")
     self._filter = context.get_filter(self)
     self._methods = cls()