Example #1
0
    def test_closed_cb_without_final_frame(self):
        c = Channel(
            'connection', None, {
                20: ChannelClass,
                40: ExchangeClass,
                50: QueueClass,
                60: BasicClass,
                90: TransactionClass,
            })
        c._pending_events = 'foo'
        c._frame_buffer = 'foo'

        for val in c._class_map.values():
            expect(val._cleanup)
        expect(c._notify_close_listeners)

        c._closed_cb()
        assert_equals(deque([]), c._pending_events)
        assert_equals(deque([]), c._frame_buffer)
        assert_equals(None, c._connection)
        assert_false(hasattr(c, 'channel'))
        assert_false(hasattr(c, 'exchange'))
        assert_false(hasattr(c, 'queue'))
        assert_false(hasattr(c, 'basic'))
        assert_false(hasattr(c, 'tx'))
        assert_equals(None, c._class_map)
        assert_equals(set(), c._close_listeners)
Example #2
0
    def test_clear_synchronous_cb_when_pending_cb_doesnt_match_but_isnt_in_list(self):
        c = Channel(None, None, {})
        stub(c._flush_pending_events)
        c._pending_events = deque(['foo', 'bar'])

        assert_raises(ChannelError, c.clear_synchronous_cb, 'bar')
        assert_equals(deque(['foo', 'bar']), c._pending_events)
Example #3
0
  def test_clear_synchronous_cb_when_pending_cb_doesnt_match_but_isnt_in_list(self):
    c = Channel(None,None,{})
    stub( c._flush_pending_events )
    c._pending_events = deque(['foo', 'bar'])

    assertRaises( ChannelError, c.clear_synchronous_cb, 'bar' )
    assertEquals( deque(['foo','bar']), c._pending_events )
Example #4
0
    def test_closed_cb_without_final_frame(self):
        c = Channel('connection', None, {
            20: ChannelClass,
            40: ExchangeClass,
            50: QueueClass,
            60: BasicClass,
            90: TransactionClass,
        })
        c._pending_events = 'foo'
        c._frame_buffer = 'foo'

        for val in c._class_map.values():
            expect(val._cleanup)
        expect(c._notify_close_listeners)

        c._closed_cb()
        assert_equals(deque([]), c._pending_events)
        assert_equals(deque([]), c._frame_buffer)
        assert_equals(None, c._connection)
        assert_false(hasattr(c, 'channel'))
        assert_false(hasattr(c, 'exchange'))
        assert_false(hasattr(c, 'queue'))
        assert_false(hasattr(c, 'basic'))
        assert_false(hasattr(c, 'tx'))
        assert_equals(None, c._class_map)
        assert_equals(set(), c._close_listeners)
Example #5
0
  def test_clear_synchronous_cb_when_pending_cb_doesnt_match_but_isnt_in_list(self):
    c = Channel(None,None,{})
    c._pending_events = deque(['foo'])

    expect( c._flush_pending_events )

    assert_equals( 'bar', c.clear_synchronous_cb('bar') )
    assertEquals( deque(['foo']), c._pending_events )
Example #6
0
  def test_clear_synchronous_cb_when_pending_cb_doesnt_match_but_isnt_in_list(self):
    c = Channel(None,None)
    c._pending_events = ['foo']

    expect( c._flush_pending_events )

    c.clear_synchronous_cb( 'bar' )
    assertEquals( ['foo'], c._pending_events )
Example #7
0
  def test_clear_synchronous_cb_when_pending_cb_matches(self):
    c = Channel(None,None)
    c._pending_events = ['foo']

    expect( c._flush_pending_events )

    c.clear_synchronous_cb( 'foo' )
    assertEquals( [], c._pending_events )
Example #8
0
    def test_clear_synchronous_cb_when_pending_cb_matches(self):
        c = Channel(None, None)
        c._pending_events = ['foo']

        expect(c._flush_pending_events)

        c.clear_synchronous_cb('foo')
        assertEquals([], c._pending_events)
Example #9
0
    def test_clear_synchronous_cb_when_pending_cb_doesnt_match_but_isnt_in_list(self):
        c = Channel(None, None, {})
        c._pending_events = deque(['foo'])

        expect(c._flush_pending_events)

        assert_equals('bar', c.clear_synchronous_cb('bar'))
        assert_equals(deque(['foo']), c._pending_events)
Example #10
0
    def test_clear_synchronous_cb_when_pending_cb_matches(self):
        c = Channel(None, None, {})
        c._pending_events = deque(['foo'])

        expect(c._flush_pending_events)

        assert_equals('foo', c.clear_synchronous_cb('foo'))
        assert_equals(deque([]), c._pending_events)
Example #11
0
    def test_clear_synchronous_cb_when_pending_cb_matches(self):
        c = Channel(None, None, {})
        c._pending_events = deque(['foo'])

        expect(c._flush_pending_events)

        assert_equals('foo', c.clear_synchronous_cb('foo'))
        assertEquals(deque([]), c._pending_events)
Example #12
0
    def test_clear_synchronous_cb_when_pending_cb_doesnt_match_but_isnt_in_list(
            self):
        c = Channel(None, None)
        c._pending_events = ['foo']

        expect(c._flush_pending_events)

        c.clear_synchronous_cb('bar')
        assertEquals(['foo'], c._pending_events)
Example #13
0
    def test_flush_pending_events_flushes_all_leading_frames(self):
        conn = mock()
        c = Channel(conn, 42, {})
        f1 = MethodFrame(1, 2, 3)
        f2 = MethodFrame(1, 2, 3)
        f3 = MethodFrame(1, 2, 3)
        c._pending_events = deque([f1, f2, 'cb', f3])

        expect(conn.send_frame).args(f1)
        expect(conn.send_frame).args(f2)

        c._flush_pending_events()
        assert_equals(deque(['cb', f3]), c._pending_events)
Example #14
0
    def test_flush_pending_events_flushes_all_leading_frames(self):
        conn = mock()
        c = Channel(conn, 42, {})
        f1 = MethodFrame(1, 2, 3)
        f2 = MethodFrame(1, 2, 3)
        f3 = MethodFrame(1, 2, 3)
        c._pending_events = deque([f1, f2, 'cb', f3])

        expect(conn.send_frame).args(f1)
        expect(conn.send_frame).args(f2)

        c._flush_pending_events()
        assertEquals(deque(['cb', f3]), c._pending_events)
Example #15
0
    def test_closed_cb_without_final_frame(self):
        c = Channel(mock(), None, self._CLASS_MAP)
        c._pending_events = 'foo'
        c._frame_buffer = 'foo'

        for val in c._class_map.values():
            expect(val._cleanup)
        expect(c._notify_close_listeners)

        c._closed_cb()
        assert_equals(deque([]), c._pending_events)
        assert_equals(deque([]), c._frame_buffer)
        assert_equals(None, c._connection)
        assert_false(hasattr(c, 'channel'))
        assert_false(hasattr(c, 'exchange'))
        assert_false(hasattr(c, 'queue'))
        assert_false(hasattr(c, 'basic'))
        assert_false(hasattr(c, 'tx'))
        assert_equals(None, c._class_map)
        assert_equals(set(), c._close_listeners)
Example #16
0
    def test_closed_cb_without_final_frame(self):
        c = Channel(mock(), None, self._CLASS_MAP)
        c._pending_events = 'foo'
        c._frame_buffer = 'foo'

        for val in c._class_map.values():
            expect(val._cleanup)
        expect(c._notify_close_listeners)

        c._closed_cb()
        assert_equals(deque([]), c._pending_events)
        assert_equals(deque([]), c._frame_buffer)
        assert_equals(None, c._connection)
        assert_false(hasattr(c, 'channel'))
        assert_false(hasattr(c, 'exchange'))
        assert_false(hasattr(c, 'queue'))
        assert_false(hasattr(c, 'basic'))
        assert_false(hasattr(c, 'tx'))
        assert_equals(None, c._class_map)
        assert_equals(set(), c._close_listeners)
Example #17
0
    def test_closed_cb_without_final_frame(self):
        c = Channel(
            "connection",
            None,
            {20: ChannelClass, 40: ExchangeClass, 50: QueueClass, 60: BasicClass, 90: TransactionClass},
        )
        c._pending_events = "foo"
        c._frame_buffer = "foo"

        for val in c._class_map.values():
            expect(val._cleanup)
        expect(c._notify_close_listeners)

        c._closed_cb()
        assert_equals(deque([]), c._pending_events)
        assert_equals(deque([]), c._frame_buffer)
        assert_equals(None, c._connection)
        assert_false(hasattr(c, "channel"))
        assert_false(hasattr(c, "exchange"))
        assert_false(hasattr(c, "queue"))
        assert_false(hasattr(c, "basic"))
        assert_false(hasattr(c, "tx"))
        assert_equals(None, c._class_map)
        assert_equals(set(), c._close_listeners)