Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
from aws_advanced_python_wrapper.host_selector import (
HighestWeightHostSelector, HostSelector, RandomHostSelector,
RoundRobinHostSelector, WeightedRandomHostSelector)
from aws_advanced_python_wrapper.sql_alchemy_connection_provider import PoolKey
from aws_advanced_python_wrapper.utils.log import Logger
from aws_advanced_python_wrapper.utils.messages import Messages
from aws_advanced_python_wrapper.utils.pool_key import PoolKey
Comment thread
karenc-bq marked this conversation as resolved.
from aws_advanced_python_wrapper.utils.properties import (Properties,
WrapperProperties)
from aws_advanced_python_wrapper.utils.rds_url_type import RdsUrlType
Expand Down Expand Up @@ -425,7 +425,6 @@ async def release_resources(self) -> None:

__all__ = [
"AsyncPooledConnectionProvider",
"PoolKey",
# Private but re-exported for tests:
"_AsyncPool",
"_PooledAsyncConnectionProxy",
Expand Down
27 changes: 1 addition & 26 deletions aws_advanced_python_wrapper/sql_alchemy_connection_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
RoundRobinHostSelector, WeightedRandomHostSelector)
from aws_advanced_python_wrapper.plugin import CanReleaseResources
from aws_advanced_python_wrapper.utils.messages import Messages
from aws_advanced_python_wrapper.utils.pool_key import PoolKey
from aws_advanced_python_wrapper.utils.properties import (Properties,
WrapperProperties)
from aws_advanced_python_wrapper.utils.rds_url_type import RdsUrlType
Expand Down Expand Up @@ -188,29 +189,3 @@ def release_resources(self):
# Swallow exception, connections may already be dead
pass
SqlAlchemyPooledConnectionProvider._database_pools.clear()


class PoolKey:
def __init__(self, url: str, extra_key: Optional[str] = None):
self._url = url
self._extra_key = extra_key

def __eq__(self, other):
if isinstance(other, type(self)):
return self.__members() == other.__members()
else:
return False

def __hash__(self):
return hash(self.__members())

def __members(self) -> Tuple[str, Optional[str]]:
return self._url, self._extra_key

@property
def url(self):
return self._url

@property
def extra_key(self):
return self._extra_key
50 changes: 50 additions & 0 deletions aws_advanced_python_wrapper/utils/pool_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Cache key shared by the sync and async internal connection pool providers.

This lives in its own module, free of any pool implementation imports, so that
the async provider can key its pools identically without taking a dependency on
SQLAlchemy (which the sync provider requires but the async provider does not).
"""

from __future__ import annotations

from typing import Optional, Tuple


class PoolKey:
def __init__(self, url: str, extra_key: Optional[str] = None):
self._url = url
self._extra_key = extra_key

def __eq__(self, other):
if isinstance(other, type(self)):
return self.__members() == other.__members()
else:
return False

def __hash__(self):
return hash(self.__members())

def __members(self) -> Tuple[str, Optional[str]]:
return self._url, self._extra_key

@property
def url(self):
return self._url

@property
def extra_key(self):
return self._extra_key
4 changes: 2 additions & 2 deletions tests/unit/test_aio_pooled_connection_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import pytest

from aws_advanced_python_wrapper.aio.pooled_connection_provider import (
AsyncPooledConnectionProvider, PoolKey, _AsyncPool,
_PooledAsyncConnectionProxy)
AsyncPooledConnectionProvider, _AsyncPool, _PooledAsyncConnectionProxy)
from aws_advanced_python_wrapper.aio.storage.sliding_expiration_cache_async import \
AsyncSlidingExpirationCache
from aws_advanced_python_wrapper.errors import AwsWrapperError
from aws_advanced_python_wrapper.hostinfo import HostInfo, HostRole
from aws_advanced_python_wrapper.utils.pool_key import PoolKey
from aws_advanced_python_wrapper.utils.properties import (Properties,
WrapperProperties)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_pool_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from aws_advanced_python_wrapper.sql_alchemy_connection_provider import PoolKey
from aws_advanced_python_wrapper.utils.pool_key import PoolKey


def test_eq():
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_sql_alchemy_pooled_connection_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

from aws_advanced_python_wrapper.errors import AwsWrapperError
from aws_advanced_python_wrapper.hostinfo import HostInfo, HostRole
from aws_advanced_python_wrapper.sql_alchemy_connection_provider import (
PoolKey, SqlAlchemyPooledConnectionProvider)
from aws_advanced_python_wrapper.sql_alchemy_connection_provider import \
SqlAlchemyPooledConnectionProvider
from aws_advanced_python_wrapper.utils.pool_key import PoolKey
from aws_advanced_python_wrapper.utils.properties import (Properties,
WrapperProperties)
from aws_advanced_python_wrapper.utils.storage.sliding_expiration_cache import \
Expand Down