Пример #1
0
 def test_close(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string):
         conn_context_functor = ConnectionContextPooled(config)
         conn_context_functor.connection()
         conn_context_functor.connection('dwight')
         conn_context_functor.connection('wilma')
         conn_context_functor.close()
         assert len(conn_context_functor.pool) == 0
 def test_force_reconnect(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string):
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         assert conn is conn_context_functor.pool[currentThread().getName()]
         conn_context_functor.force_reconnect()
         assert len(conn_context_functor.pool) == 0
         conn2 = conn_context_functor.connection()
         assert not conn == conn2
Пример #3
0
 def test_connection(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string):
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         assert conn is conn_context_functor.pool[currentThread().getName()]
         conn = conn_context_functor.connection('dwight')
         assert conn is conn_context_functor.pool['dwight']
         # get the same connection again to make sure it really is the same
         conn = conn_context_functor.connection()
         assert conn is conn_context_functor.pool[currentThread().getName()]
 def test_connection(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string):
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         assert conn is conn_context_functor.pool[currentThread().getName()]
         conn = conn_context_functor.connection('dwight')
         assert conn is conn_context_functor.pool['dwight']
         # get the same connection again to make sure it really is the same
         conn = conn_context_functor.connection()
         assert conn is conn_context_functor.pool[currentThread().getName()]
Пример #5
0
 def test_force_reconnect(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string) as mocked_pika_module:
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         self.assertTrue(
             conn is conn_context_functor.pool[currentThread().getName()]
         )
         conn_context_functor.force_reconnect()
         self.assertEqual(len(conn_context_functor.pool), 0)
         conn2 = conn_context_functor.connection()
         self.assertFalse(conn == conn2)
Пример #6
0
 def test_close(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string):
         conn_context_functor = ConnectionContextPooled(config)
         conn_context_functor.connection()
         conn_context_functor.connection('dwight')
         conn_context_functor.connection('wilma')
         conn_context_functor.close()
         eq_(len(conn_context_functor.pool), 0)
Пример #7
0
 def test_close(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string) as mocked_pika_module:
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         conn = conn_context_functor.connection('dwight')
         conn = conn_context_functor.connection('wilma')
         conn_context_functor.close()
         self.assertEqual(len(conn_context_functor.pool), 0)
Пример #8
0
 def test_force_reconnect(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string):
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         assert conn is conn_context_functor.pool[currentThread().getName()]
         conn_context_functor.force_reconnect()
         assert len(conn_context_functor.pool) == 0
         conn2 = conn_context_functor.connection()
         assert not conn == conn2
Пример #9
0
 def test_force_reconnect(self):
     config = self._setup_config()
     pika_string = 'socorro.external.rabbitmq.connection_context.pika'
     with patch(pika_string) as mocked_pika_module:
         conn_context_functor = ConnectionContextPooled(config)
         conn = conn_context_functor.connection()
         self.assertTrue(
             conn is conn_context_functor.pool[currentThread().getName()])
         conn_context_functor.force_reconnect()
         self.assertEqual(len(conn_context_functor.pool), 0)
         conn2 = conn_context_functor.connection()
         self.assertFalse(conn == conn2)
Пример #10
0
    def test_close_connection(self):
        config = self._setup_config()
        pika_string = 'socorro.external.rabbitmq.connection_context.pika'
        with patch(pika_string):
            conn_context_functor = ConnectionContextPooled(config)
            conn = conn_context_functor.connection('dwight')
            assert conn is conn_context_functor.pool['dwight']
            conn_context_functor.close_connection(conn)
            # should be no change
            assert conn is conn_context_functor.pool['dwight']
            assert len(conn_context_functor.pool) == 1

            conn_context_functor.close_connection(conn, True)
            with pytest.raises(KeyError):
                conn_context_functor.pool['dwight']()
            assert len(conn_context_functor.pool) == 0
Пример #11
0
    def test_close_connection(self):
        config = self._setup_config()
        pika_string = 'socorro.external.rabbitmq.connection_context.pika'
        with patch(pika_string):
            conn_context_functor = ConnectionContextPooled(config)
            conn = conn_context_functor.connection('dwight')
            ok_(conn is conn_context_functor.pool['dwight'])
            conn_context_functor.close_connection(conn)
            # should be no change
            ok_(conn is conn_context_functor.pool['dwight'])
            eq_(len(conn_context_functor.pool), 1)

            conn_context_functor.close_connection(conn, True)
            assert_raises(KeyError,
                          lambda: conn_context_functor.pool['dwight'])
            eq_(len(conn_context_functor.pool), 0)
Пример #12
0
    def test_close_connection(self):
        config = self._setup_config()
        pika_string = 'socorro.external.rabbitmq.connection_context.pika'
        with patch(pika_string) as mocked_pika_module:
            conn_context_functor = ConnectionContextPooled(config)
            conn = conn_context_functor.connection('dwight')
            self.assertTrue(conn is conn_context_functor.pool['dwight'])
            conn_context_functor.close_connection(conn)
            # should be no change
            self.assertTrue(conn is conn_context_functor.pool['dwight'])
            self.assertEqual(len(conn_context_functor.pool), 1)

            conn_context_functor.close_connection(conn, True)
            self.assertRaises(KeyError,
                              lambda: conn_context_functor.pool['dwight'])
            self.assertEqual(len(conn_context_functor.pool), 0)
    def test_close_connection(self):
        config = self._setup_config()
        pika_string = 'socorro.external.rabbitmq.connection_context.pika'
        with patch(pika_string):
            conn_context_functor = ConnectionContextPooled(config)
            conn = conn_context_functor.connection('dwight')
            assert conn is conn_context_functor.pool['dwight']
            conn_context_functor.close_connection(conn)
            # should be no change
            assert conn is conn_context_functor.pool['dwight']
            assert len(conn_context_functor.pool) == 1

            conn_context_functor.close_connection(conn, True)
            with pytest.raises(KeyError):
                conn_context_functor.pool['dwight']()
            assert len(conn_context_functor.pool) == 0
Пример #14
0
    def test_close_connection(self):
        config = self._setup_config()
        pika_string = 'socorro.external.rabbitmq.connection_context.pika'
        with patch(pika_string) as mocked_pika_module:
            conn_context_functor = ConnectionContextPooled(config)
            conn = conn_context_functor.connection('dwight')
            self.assertTrue(
                conn is conn_context_functor.pool['dwight']
            )
            conn_context_functor.close_connection(conn)
            # should be no change
            self.assertTrue(
                conn is conn_context_functor.pool['dwight']
            )
            self.assertEqual(len(conn_context_functor.pool), 1)

            conn_context_functor.close_connection(conn, True)
            self.assertRaises(
                KeyError,
                lambda : conn_context_functor.pool['dwight']
            )
            self.assertEqual(len(conn_context_functor.pool), 0)
Пример #15
0
    def test_close_connection(self):
        config = self._setup_config()
        pika_string = 'socorro.external.rabbitmq.connection_context.pika'
        with patch(pika_string):
            conn_context_functor = ConnectionContextPooled(config)
            conn = conn_context_functor.connection('dwight')
            ok_(
                conn is conn_context_functor.pool['dwight']
            )
            conn_context_functor.close_connection(conn)
            # should be no change
            ok_(
                conn is conn_context_functor.pool['dwight']
            )
            eq_(len(conn_context_functor.pool), 1)

            conn_context_functor.close_connection(conn, True)
            assert_raises(
                KeyError,
                lambda : conn_context_functor.pool['dwight']
            )
            eq_(len(conn_context_functor.pool), 0)
Пример #16
0
 def test_constructor(self):
     conn_context_functor = ConnectionContextPooled(self._setup_config)
     assert conn_context_functor.config is conn_context_functor.local_config
     assert len(conn_context_functor.pool) == 0
Пример #17
0
 def test_constructor(self):
     conn_context_functor = ConnectionContextPooled(self._setup_config)
     self.assertTrue(
         conn_context_functor.config is conn_context_functor.local_config
     )
     self.assertEqual(len(conn_context_functor.pool), 0)
Пример #18
0
 def test_constructor(self):
     conn_context_functor = ConnectionContextPooled(self._setup_config)
     ok_(conn_context_functor.config is conn_context_functor.local_config)
     eq_(len(conn_context_functor.pool), 0)