本文整理汇总了Python中zato.server.base.parallel.ParallelServer类的典型用法代码示例。如果您正苦于以下问题:Python ParallelServer类的具体用法?Python ParallelServer怎么用?Python ParallelServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParallelServer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__startup_services
def test__startup_services(self):
class FakeBrokerClient(object):
def __init__(self):
self.messages = {}
def invoke_async(self, msg):
self.messages[msg['service']] = msg
broker_client = FakeBrokerClient()
startup_services = Bunch()
for x in range(10):
name = rand_string()
payload = rand_string()
startup_services[name] = payload
ps = ParallelServer()
ps.broker_client = broker_client
ps.fs_server_config = Bunch()
ps.fs_server_config.startup_services = startup_services
ps.invoke_startup_services()
for expected_service, expected_payload in startup_services.items():
msg = Bunch(broker_client.messages[expected_service])
eq_(msg.action, SERVICE.PUBLISH)
eq_(msg.channel, CHANNEL.STARTUP_SERVICE)
eq_(msg.payload, expected_payload)
eq_(msg.service, expected_service)
ok_(msg.cid.startswith('K'))
self.assertEquals(len(msg.cid), 40)
示例2: test__set_tls_info
def test__set_tls_info(self):
expected_cert_dict = rand_string()
expected_cert_der = rand_string()
expected_cert_sha1 = sha1(expected_cert_der).hexdigest().upper()
for wsgi_url_scheme in('https', 'http'):
wsgi_environ = {
'wsgi.url_scheme': wsgi_url_scheme,
'gunicorn.socket': FakeGunicornSocket(expected_cert_der, expected_cert_dict),
'zato.http.response.status': rand_string(),
'zato.http.channel_item': Bunch(audit_enabled=False),
'PATH_INFO': rand_string(),
'REQUEST_METHOD': rand_string(),
'SERVER_PROTOCOL': rand_string(),
'HTTP_USER_AGENT': rand_string(),
}
ps = ParallelServer()
ps.worker_store = FakeWorkerStore()
ps.on_wsgi_request(wsgi_environ, StartResponse())
if wsgi_url_scheme == 'https':
eq_(wsgi_environ['zato.tls.client_cert.dict'], expected_cert_dict)
eq_(wsgi_environ['zato.tls.client_cert.der'], expected_cert_der)
eq_(wsgi_environ['zato.tls.client_cert.sha1'], expected_cert_sha1)
else:
self.assertTrue('zato.tls.client_cert.dict' not in wsgi_environ)
self.assertTrue('zato.tls.client_cert.der' not in wsgi_environ)
self.assertTrue('zato.tls.client_cert.sha1' not in wsgi_environ)
示例3: parallel_server
def parallel_server(self):
server = ParallelServer()
server.odb = self.odb_manager()
server.service_store = self.service_store()
#server.request_handler = self.request_handler()
#server.request_handler.soap_handler.server = server
#server.request_handler.plain_http_handler.server = server
return server
示例4: test_set_tls_info
def test_set_tls_info(self):
expected_cert_dict = rand_string()
expected_cert_der = rand_string()
expected_cert_sha1 = sha1(expected_cert_der).hexdigest().upper()
class FakeRequestDispatcher(object):
def dispatch(self, *ignored_args, **ignored_kwargs):
return rand_string()
class FakeWorkerStore(object):
request_dispatcher = FakeRequestDispatcher()
class FakeGunicornSocket(object):
def getpeercert(self, needs_der=False):
if needs_der:
return expected_cert_der
return expected_cert_dict
def start_response(*ignored_args, **ignored_kwargs):
pass
for wsgi_url_scheme in('https', 'http'):
wsgi_environ = {
'wsgi.url_scheme': wsgi_url_scheme,
'gunicorn.socket': FakeGunicornSocket(),
'zato.http.response.status': rand_string()
}
ps = ParallelServer()
ps.worker_store = FakeWorkerStore()
ps.on_wsgi_request(wsgi_environ, start_response)
if wsgi_url_scheme == 'https':
eq_(wsgi_environ['zato.tls.client_cert.dict'], expected_cert_dict)
eq_(wsgi_environ['zato.tls.client_cert.der'], expected_cert_der)
eq_(wsgi_environ['zato.tls.client_cert.sha1'], expected_cert_sha1)
else:
self.assertTrue('zato.tls.client_cert.dict' not in wsgi_environ)
self.assertTrue('zato.tls.client_cert.der' not in wsgi_environ)
self.assertTrue('zato.tls.client_cert.sha1' not in wsgi_environ)
示例5: test_access_log
def test_access_log(self):
def _utcnow(self):
return datetime(year=2014, month=1, day=12, hour=16, minute=22, second=12, tzinfo=UTC)
local_tz = get_localzone()
_now = _utcnow(None)
local_dt = _now.replace(tzinfo=UTC).astimezone(local_tz)
local_dt = local_tz.normalize(local_dt)
request_timestamp = local_dt.strftime(ACCESS_LOG_DT_FORMAT)
with patch('arrow.factory.ArrowFactory.utcnow', _utcnow):
response = rand_string() * rand_int()
cid = new_cid()
cluster_id = 1
channel_name = rand_string()
url_path = '/{}'.format(rand_string())
user_agent = rand_string()
http_version = rand_string()
request_method = rand_string()
remote_ip = '10.{}.{}.{}'.format(rand_int(), rand_int(), rand_int())
req_timestamp_utc = utcnow()
channel_item = {
'name': channel_name,
'audit_enabled': False,
'is_active': True,
'transport': 'plain_http',
'data_format': None,
'match_target': url_path
}
wsgi_environ = {
'gunicorn.socket': FakeGunicornSocket(None, None),
'wsgi.url_scheme': 'http',
'wsgi.input': StringIO(response),
'zato.http.response.status': httplib.OK,
'zato.http.channel_item': channel_item,
'zato.request_timestamp_utc': req_timestamp_utc,
'HTTP_X_FORWARDED_FOR': remote_ip,
'PATH_INFO': url_path,
'REQUEST_METHOD': request_method,
'SERVER_PROTOCOL': http_version,
'HTTP_USER_AGENT': user_agent,
}
class FakeBrokerClient(object):
def __init__(self):
self.msg = None
def publish(self, msg):
self.msg = msg
class FakeODB(ODBManager):
def __init__(self):
self.msg = None
self.cluster = Bunch(id=cluster_id)
def session(self):
return fake_session
class FakeURLData(URLData):
def __init__(self):
self.url_sec = {url_path: Bunch(sec_def=ZATO_NONE)}
def match(self, *ignored_args, **ignored_kwargs):
return True, channel_item
class FakeRequestHandler(object):
def handle(self, *ignored_args, **ignored_kwargs):
return Bunch(payload=response, content_type='text/plain', headers={}, status_code=httplib.OK)
class FakeAccessLogger(object):
def __init__(self):
self.extra = {}
def info(self, msg, extra):
self.extra = extra
def isEnabledFor(self, ignored):
return True
bc = FakeBrokerClient()
ws = FakeWorkerStore()
ws.request_dispatcher = RequestDispatcher()
ws.request_dispatcher.request_handler = FakeRequestHandler()
ws.request_dispatcher.url_data = FakeURLData()
ws.request_dispatcher.url_data.broker_client = bc
ws.request_dispatcher.url_data.odb = FakeODB()
ps = ParallelServer()
ps.worker_store = ws
ps.access_logger = FakeAccessLogger()
ps.on_wsgi_request(wsgi_environ, StartResponse(), cid=cid)
#.........这里部分代码省略.........
示例6: test_audit
#.........这里部分代码省略.........
def __init__(self):
self.msg = None
def publish(self, msg):
self.msg = msg
class FakeODB(ODBManager):
def __init__(self):
self.msg = None
self.cluster = Bunch(id=expected_cluster_id)
def session(self):
return fake_session
class FakeURLData(URLData):
def __init__(self):
self.url_sec = {expected_match_target: Bunch(sec_def=ZATO_NONE)}
def match(self, *ignored_args, **ignored_kwargs):
return True, channel_item
class FakeRequestHandler(object):
def handle(self, *ignored_args, **ignored_kwargs):
return Bunch(payload=expected_payload, content_type='text/plain', headers={}, status_code=expected_status_code)
bc = FakeBrokerClient()
ws = FakeWorkerStore()
ws.request_dispatcher = RequestDispatcher()
ws.request_dispatcher.request_handler = FakeRequestHandler()
ws.request_dispatcher.url_data = FakeURLData()
ws.request_dispatcher.url_data.broker_client = bc
ws.request_dispatcher.url_data.odb = FakeODB()
ps = ParallelServer()
ps.worker_store = ws
ps.on_wsgi_request(wsgi_environ, StartResponse(), cid=expected_cid)
if expected_audit_enabled:
#
# Audit 1/2 - Request
#
# Parsing will confirm the proper value was used
datetime.strptime(fake_session.audit.req_time.isoformat(), '%Y-%m-%dT%H:%M:%S.%f')
self.assertEquals(fake_session.audit.name, expected_name)
self.assertEquals(fake_session.audit.cid, expected_cid)
self.assertEquals(fake_session.audit.transport, expected_transport)
self.assertEquals(fake_session.audit.connection, expected_connection)
self.assertEquals(fake_session.audit.resp_time, None)
self.assertEquals(fake_session.audit.user_token, expected_username)
self.assertEquals(fake_session.audit.auth_ok, None)
self.assertEquals(fake_session.audit.invoke_ok, None)
self.assertEquals(fake_session.audit.remote_addr, expected_remote_addr)
self.assertEquals(fake_session.audit.req_payload, expected_request[:expected_audit_max_payload])
self.assertEquals(fake_session.audit.resp_headers, None)
self.assertEquals(fake_session.audit.resp_payload, None)
req_headers = literal_eval(fake_session.audit.req_headers)
self.assertEquals(req_headers[expected_remote_addr_header], repr(expected_remote_addr))
self.assertEquals(req_headers['wsgi.url_scheme'], repr(expected_url_scheme))
self.assertEquals(req_headers['gunicorn.socket'], repr(FakeGunicornSocket(None, None)))
channel_item = literal_eval(req_headers['zato.http.channel_item'])
示例7: parallel_server
def parallel_server(self):
server = ParallelServer()
server.odb = self.odb_manager()
server.service_store = self.service_store()
server.sql_pool_store = self.sql_pool_store()
server.int_parameters = self.int_parameters()
server.int_parameter_suffixes = self.int_parameter_suffixes()
server.bool_parameter_prefixes = self.bool_parameter_prefixes()
server.internal_service_modules = self.internal_service_modules()
server.service_modules = self.service_modules()
server.kvdb = self.kvdb()
server.user_config = Bunch()
return server
示例8: parallel_server
def parallel_server(self):
server = ParallelServer()
server.odb = self.odb_manager()
server.service_store = self.service_store()
server.sql_pool_store = self.sql_pool_store()
server.int_parameters = self.int_parameters()
server.int_parameter_suffixes = self.int_parameter_suffixes()
server.bool_parameter_prefixes = self.bool_parameter_prefixes()
server.soap11_content_type = self.soap11_content_type()
server.soap12_content_type = self.soap12_content_type()
server.plain_xml_content_type = self.plain_xml_content_type()
server.json_content_type = self.json_content_type()
server.internal_service_modules = self.internal_service_modules()
server.service_modules = self.service_modules()
server.kvdb = self.kvdb()
return server