本文整理汇总了Python中haigha.channel_pool.ChannelPool类的典型用法代码示例。如果您正苦于以下问题:Python ChannelPool类的具体用法?Python ChannelPool怎么用?Python ChannelPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChannelPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_channel_when_two_free_and_one_closed
def test_get_channel_when_two_free_and_one_closed(self):
# Because we can't mock builtins ....
class Set(set):
def pop(self):
pass
conn = mock()
ch1 = mock()
ch1.closed = True
ch2 = mock()
ch2.closed = False
cp = ChannelPool(conn)
cp._free_channels = Set([ch1, ch2])
cp._channels = 2
# Because we want them in order
expect(cp._free_channels.pop).returns(
ch1).side_effect(super(Set, cp._free_channels).pop)
expect(cp._free_channels.pop).returns(
ch2).side_effect(super(Set, cp._free_channels).pop)
self.assertEquals(ch2, cp._get_channel())
self.assertEquals(set(), cp._free_channels)
assert_equals(2, cp._channels)
示例2: test_channel_closed_cb
def test_channel_closed_cb(self):
cp = ChannelPool(None)
cp._channels = 32
expect(cp._process_queue)
cp._channel_closed_cb('channel')
assert_equals(31, cp._channels)
示例3: test_publish_appends_to_queue_when_no_ready_channels
def test_publish_appends_to_queue_when_no_ready_channels(self):
cp = ChannelPool(None)
expect(cp._get_channel).returns(None)
cp.publish("arg1", "arg2", arg3="foo", cb="usercb")
self.assertEquals(set(), cp._free_channels)
assert_equals(deque([(("arg1", "arg2"), {"arg3": "foo", "cb": "usercb"})]), cp._queue)
示例4: test_get_channel_when_none_free
def test_get_channel_when_none_free(self):
conn = mock()
cp = ChannelPool(conn)
expect(conn.channel).returns( 'channel' )
self.assertEquals( 'channel', cp._get_channel() )
self.assertEquals( set(), cp._free_channels )
示例5: test_publish_appends_to_queue_when_no_ready_channels
def test_publish_appends_to_queue_when_no_ready_channels(self):
cp = ChannelPool(None)
expect(cp._get_channel).returns(None)
cp.publish('arg1', 'arg2', arg3='foo', cb='usercb')
self.assertEquals(set(), cp._free_channels)
assert_equals(deque([(('arg1', 'arg2'), {'arg3': 'foo', 'cb': 'usercb'})]),
cp._queue)
示例6: test_get_channel_returns_new_when_none_free_and_at_limit
def test_get_channel_returns_new_when_none_free_and_at_limit(self):
conn = mock()
cp = ChannelPool(conn, 1)
cp._channels = 1
stub(conn.channel)
self.assertEquals(None, cp._get_channel())
self.assertEquals(set(), cp._free_channels)
示例7: test_get_channel_when_one_free_and_not_closed
def test_get_channel_when_one_free_and_not_closed(self):
conn = mock()
ch = mock()
ch.closed = False
cp = ChannelPool(conn)
cp._free_channels = set([ch])
self.assertEquals(ch, cp._get_channel())
self.assertEquals(set(), cp._free_channels)
示例8: test_get_channel_returns_new_when_none_free_and_not_at_limit
def test_get_channel_returns_new_when_none_free_and_not_at_limit(self):
conn = mock()
cp = ChannelPool(conn)
cp._channels = 1
with expect(conn.channel).returns(mock()) as newchannel:
expect(newchannel.add_close_listener).args(cp._channel_closed_cb)
self.assertEquals(newchannel, cp._get_channel())
self.assertEquals(set(), cp._free_channels)
assert_equals(2, cp._channels)
示例9: test_publish_appends_to_queue_when_no_ready_channels_out_of_several
def test_publish_appends_to_queue_when_no_ready_channels_out_of_several(self):
ch1 = mock()
cp = ChannelPool(None)
ch1.active = False
expect(cp._get_channel).returns(ch1)
expect(cp._get_channel).returns(None)
cp.publish("arg1", "arg2", arg3="foo", cb="usercb")
self.assertEquals(set([ch1]), cp._free_channels)
assert_equals(deque([(("arg1", "arg2"), {"arg3": "foo", "cb": "usercb"})]), cp._queue)
示例10: test_publish_appends_to_queue_when_no_ready_channels_out_of_several
def test_publish_appends_to_queue_when_no_ready_channels_out_of_several(self):
ch1 = mock()
cp = ChannelPool(None)
ch1.active = False
expect(cp._get_channel).returns(ch1)
expect(cp._get_channel).returns(None)
cp.publish('arg1', 'arg2', arg3='foo', cb='usercb')
self.assertEquals(set([ch1]), cp._free_channels)
assert_equals(deque([(('arg1', 'arg2'), {'arg3': 'foo', 'cb': 'usercb'})]),
cp._queue)
示例11: test_publish_without_user_cb
def test_publish_without_user_cb(self):
ch = mock()
cp = ChannelPool(None)
expect(cp._get_channel).returns(ch)
expect(ch.publish_synchronous).args('arg1', 'arg2', cb=var('cb'), doit='harder')
cp.publish('arg1', 'arg2', doit='harder')
assert_equals(set(), cp._free_channels)
# run committed callback
var('cb').value()
assert_equals(set([ch]), cp._free_channels)
示例12: test_get_channel_when_two_free_and_all_closed
def test_get_channel_when_two_free_and_all_closed(self):
conn = mock()
ch1 = mock()
ch1.closed = True
ch2 = mock()
ch2.closed = True
cp = ChannelPool(conn)
cp._free_channels = set([ch1,ch2])
expect(conn.channel).returns('channel')
self.assertEquals( 'channel', cp._get_channel() )
self.assertEquals( set(), cp._free_channels )
示例13: test_publish_searches_for_active_channel
def test_publish_searches_for_active_channel(self):
ch1 = mock()
ch2 = mock()
ch3 = mock()
ch1.active = ch2.active = False
ch3.active = True
cp = ChannelPool(None)
expect(cp._get_channel).returns(ch1)
expect(cp._get_channel).returns(ch2)
expect(cp._get_channel).returns(ch3)
expect(ch3.publish_synchronous).args('arg1', 'arg2', cb=ignore())
cp.publish('arg1', 'arg2')
self.assertEquals(set([ch1, ch2]), cp._free_channels)
示例14: test_get_channel_when_two_free_and_all_closed
def test_get_channel_when_two_free_and_all_closed(self):
conn = mock()
ch1 = mock()
ch1.closed = True
ch2 = mock()
ch2.closed = True
cp = ChannelPool(conn)
cp._free_channels = set([ch1, ch2])
cp._channels = 2
with expect(conn.channel).returns(mock()) as newchannel:
expect(newchannel.add_close_listener).args(cp._channel_closed_cb)
self.assertEquals(newchannel, cp._get_channel())
self.assertEquals(set(), cp._free_channels)
assert_equals(3, cp._channels)
示例15: test_publish_without_user_cb
def test_publish_without_user_cb(self):
ch = mock()
cp = ChannelPool(None)
def test_committed_cb(cb):
# Because using this for side effects is kinda fugly, protect it
if not getattr(cb,'_called_yet',False):
cb()
setattr(cb, '_called_yet', True)
return True
expect(cp._get_channel).returns( ch )
expect(ch.publish_synchronous).args( 'arg1', 'arg2', cb=func(test_committed_cb), doit='harder' )
self.assertEquals( set(), cp._free_channels )
cp.publish( 'arg1', 'arg2', doit='harder' )
self.assertEquals( set([ch]), cp._free_channels )