本文整理汇总了Python中zato.common.test.rand_int函数的典型用法代码示例。如果您正苦于以下问题:Python rand_int函数的具体用法?Python rand_int怎么用?Python rand_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rand_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invoke_retry_ok
def test_invoke_retry_ok(self):
target = 'target_{}'.format(rand_string())
callback = 'callback_{}'.format(rand_string())
callback_impl_name = 'callback_impl_name_{}'.format(rand_string())
cid = new_cid()
expected_result = rand_string()
invoking_service = DummyTargetService(callback, callback_impl_name, cid, expected_result)
ir = InvokeRetry(invoking_service)
kwargs = {
'async_fallback': True,
'callback': callback,
'context': {rand_string():rand_string()},
'repeats': rand_int(),
'seconds': rand_int(),
'minutes': 0,
'cid': cid,
}
result = ir.invoke(target, 1, 2, 3, **kwargs)
self.assertEquals(expected_result, result)
self.assertTrue(len(invoking_service.invoke_args), 2)
self.assertEquals(invoking_service.invoke_args, (target, 1, 2, 3))
self.assertEquals(invoking_service.invoke_kwargs, {'cid':cid})
示例2: test_password_not_given
def test_password_not_given(self):
class MyChangePasswordNotRequired(self.service_class):
class SimpleIO(object):
input_required = ('id',)
def handle(self):
pass
class MyChangePasswordRequired(self.service_class):
class SimpleIO(object):
input_required = ('id', 'password1', 'password2')
def handle(self):
pass
request1 = {'id':rand_int()}
response_data1 = {}
self.check_impl(MyChangePasswordNotRequired, request1, response_data1, 'ignored')
password1 = password2 = rand_string()
request2 = {'id':rand_int(), 'password1':password1, 'password2':password2}
response_data2 = {}
self.check_impl(MyChangePasswordRequired, request2, response_data2, 'ignored')
示例3: test_lock_ok
def test_lock_ok(self):
""" Succesfully grab a service lock.
"""
my_kvdb = FakeKVDB()
my_kvdb.conn.setnx_return_value = True
lock_name = rand_string()
expires = 500 + rand_int() # It's 500 which means DummyService.invoke has that many seconds to complete
timeout = rand_int()
class DummyService(Service):
kvdb = my_kvdb
def handle(self):
with self.lock(lock_name, expires, timeout):
pass
instance = DummyService()
instance.handle()
eq_(my_kvdb.conn.delete_args, KVDB.LOCK_SERVICE_PREFIX + lock_name)
eq_(my_kvdb.conn.expire_args, (KVDB.LOCK_SERVICE_PREFIX + lock_name, expires))
# First arg is the lock_name that can ne checked directly but the other
# one is the expiration time that we can check only approximately,
# anything within 3 seconds range is OK. The value of 3 is the maximum
# time allowed for execution of DummyService's invoke method which is
# way more than needed but let's use 3 to be on the safe side when the
# test is run on a very slow system.
eq_(my_kvdb.conn.setnx_args[0], KVDB.LOCK_SERVICE_PREFIX + lock_name)
expires_approx = time() + expires
self.assertAlmostEquals(my_kvdb.conn.setnx_args[1], expires_approx, delta=3)
示例4: get_response_data
def get_response_data(self):
return Bunch({'id':rand_int(), 'name':self.name, 'is_active':rand_bool(), 'is_internal':rand_bool(),
'url_path':rand_string(), 'service_id':rand_int(), 'service_name':rand_string(), 'security_id':rand_int(),
'security_name':rand_int(), 'sec_type':rand_string(), 'method':rand_string(), 'soap_action':rand_string(),
'soap_version':rand_string(), 'data_format':rand_string(), 'host':rand_string(), 'ping_method':rand_string(),
'pool_size':rand_int()}
)
示例5: test_delete
def test_delete(self):
test_wait_time = 0.5
job_sleep_time = 10
job_max_repeats = 30
job1 = Job(rand_int(), 'a', SCHEDULER.JOB_TYPE.INTERVAL_BASED, Interval(seconds=0.1), max_repeats=job_max_repeats)
job1.wait_sleep_time = job_sleep_time
job2 = Job(rand_int(), 'b', SCHEDULER.JOB_TYPE.INTERVAL_BASED, Interval(seconds=0.1), max_repeats=job_max_repeats)
job2.wait_sleep_time = job_sleep_time
scheduler = Scheduler(dummy_callback)
scheduler.lock = RLock()
scheduler.iter_cb = iter_cb
scheduler.iter_cb_args = (scheduler, datetime.utcnow() + timedelta(seconds=test_wait_time))
scheduler.create(job1)
scheduler.create(job2)
scheduler.run()
scheduler.unschedule(job1)
self.assertIn(job2, scheduler.jobs)
self.assertNotIn(job1, scheduler.jobs)
self.assertFalse(job1.keep_running)
# run - 1
# create - 2
# delete - 1
# on_max_repeats_reached - 0 (because of how long it takes to run job_max_repeats with test_wait_time)
# 1+2+1 = 4
self.assertEquals(scheduler.lock.called, 4)
示例6: test_publish_custom_attrs
def test_publish_custom_attrs(self):
self._check_publish(**{
'mime_type': rand_string(),
'priority': rand_int(),
'expiration': rand_int(1000, 2000),
'msg_id': rand_string(),
})
示例7: test_response
def test_response(self):
request = {'cluster_id':rand_int(), 'name':rand_string()}
expected_id = rand_int()
expected_name = rand_string()
expected_is_active = rand_bool()
expected_impl_name = rand_string()
expected_is_internal = rand_bool()
service = Service()
service.id = expected_id
service.name = expected_name
service.is_active = expected_is_active
service.impl_name = expected_impl_name
service.is_internal = expected_is_internal
expected = Expected()
expected.add(service)
instance = self.invoke(GetByName, request, expected)
response = Bunch(loads(instance.response.payload.getvalue())['response'])
eq_(response.id, expected_id)
eq_(response.name, expected_name)
eq_(response.is_active, expected_is_active)
eq_(response.impl_name, expected_impl_name)
eq_(response.is_internal, expected_is_internal)
eq_(response.usage, 0)
示例8: get_response_data
def get_response_data(self):
return Bunch({'id':rand_int(), 'name':self.name, 'host':rand_string(), 'port':rand_int(),
'queue_manager':rand_int(), 'channel':rand_string(),
'cache_open_send_queues':rand_bool(), 'cache_open_receive_queues':rand_bool(),
'use_shared_connections':rand_bool(), 'ssl':rand_bool(),
'needs_mcd':rand_bool(), 'max_chars_printed':rand_int(),
'ssl_cipher_spec':rand_string(), 'ssl_key_repository':rand_string()})
示例9: test_response
def test_response(self):
request = {'cluster_id': rand_int()}
expected_keys = get_data().keys()
expected_data = tuple(get_data() for x in range(rand_int(10)))
expected = Expected()
for datum in expected_data:
item = ChannelAMQP()
for key in expected_keys:
value = getattr(datum, key)
setattr(item, key, value)
expected.add(item)
instance = self.invoke(GetList, request, expected)
response = loads(instance.response.payload.getvalue())['response']
for idx, item in enumerate(response):
expected = expected_data[idx]
given = Bunch(item)
for key in expected_keys:
given_value = getattr(given, key)
expected_value = getattr(expected, key)
eq_(given_value, expected_value)
示例10: test_not_implemented_error
def test_not_implemented_error(self):
inner = FakeInnerResponse({}, rand_int(), rand_string(), rand_int())
response_data = (inner, rand_bool(), rand_int(), rand_int(), None)
self.assertRaises(NotImplementedError, _Response, *response_data)
self.assertRaises(NotImplementedError, _StructuredResponse(*response_data).load_func)
self.assertRaises(NotImplementedError, _StructuredResponse(*response_data).set_has_data)
示例11: get_response_data
def get_response_data(self):
return Bunch(
{'id':rand_int(), 'name':rand_string(), 'is_active':rand_bool(), 'def_id':rand_int(),
'delivery_mode':rand_int(), 'priority':rand_int(), 'def_name':rand_string(),
'content_type':rand_string(), 'content_encoding':rand_string(),
'cexpiration':rand_int(), 'user_id':rand_string(),
'app_id':rand_string()}
)
示例12: get_job
def get_job(name=None, interval_in_seconds=None, start_time=None, max_repeats=None, callback=None):
name = name or rand_string()
interval_in_seconds = interval_in_seconds or rand_int()
start_time = start_time or rand_date_utc()
callback = callback or dummy_callback
return Job(rand_int(), name, SCHEDULER.JOB_TYPE.INTERVAL_BASED, Interval(in_seconds=interval_in_seconds),
start_time, callback, max_repeats=max_repeats)
示例13: test_publish_custom_attrs
def test_publish_custom_attrs(self):
self._check_publish(
**{
"mime_type": rand_string(),
"priority": rand_int(),
"expiration": rand_int(1000, 2000),
"msg_id": rand_string(),
}
)
示例14: test_get_callback_consumers
def test_get_callback_consumers(self):
ps = RedisPubSub(self.kvdb, self.key_prefix)
msg_value = '"msg_value"'
topic = Topic('/test/delete')
ps.add_topic(topic)
producer = Client('Producer', 'producer')
ps.add_producer(producer, topic)
id1 = 'Consumer CB1'
name1 = 'consumer-cb1'
sub_key1 = new_cid()
callback_id1 = rand_int()
id2 = 'Consumer CB2'
name2 = 'consumer-cb2'
sub_key2 = new_cid()
callback_id2 = rand_int()
consumer_cb1 = Consumer(id1, name1, sub_key=sub_key1, delivery_mode=PUB_SUB.DELIVERY_MODE.CALLBACK_URL.id,
callback_id=callback_id1)
consumer_cb2 = Consumer(id2, name2, sub_key=sub_key2, delivery_mode=PUB_SUB.DELIVERY_MODE.CALLBACK_URL.id,
callback_id=callback_id2)
consumer_pull = Consumer('Consumer pull', 'consumer-pull', sub_key=new_cid(), delivery_mode=PUB_SUB.DELIVERY_MODE.PULL.id)
consumer_inactive = Consumer(
'Consumer pull', 'consumer-pull', is_active=False, sub_key=new_cid(), delivery_mode=PUB_SUB.DELIVERY_MODE.PULL.id)
ps.add_consumer(consumer_cb1, topic)
ps.add_consumer(consumer_cb2, topic)
ps.add_consumer(consumer_pull, topic) # This one should not be returned because it's a pull one
ps.add_consumer(consumer_inactive, topic) # This one should not be returned because it's inactive
consumers = list(ps.get_callback_consumers())
# Only 2 are returned, the rest won't make it
eq_(len(consumers), 2)
# Sort by each consumer's ID, i.e. in lexicographical order
consumers.sort(key=attrgetter('id'))
consumer1 = consumers[0]
eq_(consumer1.id, id1)
eq_(consumer1.name, name1)
eq_(consumer1.is_active, True)
eq_(consumer1.sub_key, sub_key1)
eq_(consumer1.callback_id, callback_id1)
consumer2 = consumers[1]
eq_(consumer2.id, id2)
eq_(consumer2.name, name2)
eq_(consumer2.is_active, True)
eq_(consumer2.sub_key, sub_key2)
eq_(consumer2.callback_id, callback_id2)
示例15: test_job_greenlets
def test_job_greenlets(self):
data = {'spawned':[], 'stopped': []}
class FakeGreenlet(object):
def __init__(self, run):
self.run = self._run = run
def kill(self, *args, **kwargs):
data['stopped'].append([self, args, kwargs])
def spawn(job):
g = FakeGreenlet(job)
data['spawned'].append(g)
return g
with patch('gevent.spawn', spawn):
test_wait_time = 0.5
job_sleep_time = 10
job_max_repeats = 30
job1 = Job(rand_int(), 'a', SCHEDULER.JOB_TYPE.INTERVAL_BASED, Interval(seconds=0.1), max_repeats=job_max_repeats)
job1.wait_sleep_time = job_sleep_time
job2 = Job(rand_int(), 'b', SCHEDULER.JOB_TYPE.INTERVAL_BASED, Interval(seconds=0.1), max_repeats=job_max_repeats)
job2.wait_sleep_time = job_sleep_time
scheduler = Scheduler(dummy_callback)
scheduler.lock = RLock()
scheduler.iter_cb = iter_cb
scheduler.iter_cb_args = (scheduler, datetime.utcnow() + timedelta(seconds=test_wait_time))
scheduler.create(job1, spawn=False)
scheduler.create(job2, spawn=False)
scheduler.run()
self.assertEquals(scheduler.job_greenlets[job1.name]._run, job1.run)
self.assertEquals(scheduler.job_greenlets[job2.name]._run, job2.run)
self.assertTrue(job1.keep_running)
self.assertTrue(job2.keep_running)
scheduler.unschedule(job1)
self.assertFalse(job1.keep_running)
self.assertTrue(job2.keep_running)
self.assertNotIn(job1.name, scheduler.job_greenlets)
self.assertEquals(scheduler.job_greenlets[job2.name]._run, job2.run)
self.assertEquals(len(data['stopped']), 1)
g, args, kwargs = data['stopped'][0]
self.assertIs(g.run.im_func, job1.run.im_func) # That's how we know it was job1 deleted not job2
self.assertIs(args, ())
self.assertDictEqual(kwargs, {'timeout':2.0})