예제 #1
0
    def test_close(self, mock_client, mock_qldb_session1, mock_qldb_session2, mock_close):
        mock_client.return_value = mock_client
        mock_client.max_pool_connections = DEFAULT_POOL_LIMIT
        pooled_qldb_driver = PooledQldbDriver(MOCK_LEDGER_NAME)
        pooled_qldb_driver._pool = Queue()
        pooled_qldb_driver._pool.put(mock_qldb_session1)
        pooled_qldb_driver._pool.put(mock_qldb_session2)

        pooled_qldb_driver.close()
        mock_close.assert_called_once_with()
        mock_qldb_session1.close.assert_called_once_with()
        mock_qldb_session2.close.assert_called_once_with()
예제 #2
0
    def test_get_session_existing_session(self, mock_client, mock_qldb_session, mock_pooled_qldb_session,
                                          mock_release_session, mock_bounded_semaphore, mock_atomic_integer,
                                          mock_logger_debug):
        mock_pooled_qldb_session.return_value = mock_pooled_qldb_session
        mock_client.return_value = mock_client
        mock_client.max_pool_connections = DEFAULT_POOL_LIMIT
        pooled_qldb_driver = PooledQldbDriver(MOCK_LEDGER_NAME)
        pooled_qldb_driver._pool = Queue()
        pooled_qldb_driver._pool.put(mock_qldb_session)

        session = pooled_qldb_driver.get_session()
        mock_qldb_session._abort_or_close.assert_called_once_with()
        mock_pooled_qldb_session.assert_called_once_with(mock_qldb_session, mock_release_session)
        self.assertEqual(session, mock_pooled_qldb_session)
        mock_bounded_semaphore().acquire.assert_called_once_with(timeout=DEFAULT_TIMEOUT_SECONDS)
        mock_atomic_integer().decrement.assert_called_once_with()
        self.assertEqual(mock_logger_debug.call_count, 2)