Esempio n. 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
Esempio n. 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()]
 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)
Esempio n. 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)
 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
 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)
Esempio n. 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)