Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cosmos] fix endpoint_discovery logic to be user-configurable #21778

Merged
merged 3 commits into from
Nov 22, 2021
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
3 changes: 2 additions & 1 deletion sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def _build_connection_policy(kwargs):
policy.RequestTimeout
policy.ConnectionMode = kwargs.pop('connection_mode', None) or policy.ConnectionMode
policy.ProxyConfiguration = kwargs.pop('proxy_config', None) or policy.ProxyConfiguration
policy.EnableEndpointDiscovery = kwargs.pop('enable_endpoint_discovery', None) or policy.EnableEndpointDiscovery
policy.EnableEndpointDiscovery = kwargs.pop('enable_endpoint_discovery') \
if 'enable_endpoint_discovery' in kwargs.keys() else policy.EnableEndpointDiscovery
policy.PreferredLocations = kwargs.pop('preferred_locations', None) or policy.PreferredLocations
policy.UseMultipleWriteLocations = kwargs.pop('multiple_write_locations', None) or \
policy.UseMultipleWriteLocations
Expand Down
50 changes: 50 additions & 0 deletions sdk/cosmos/azure-cosmos/test/test_user_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# The MIT License (MIT)
# Copyright (c) 2021 Microsoft Corporation

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import unittest

import azure.cosmos.cosmos_client as cosmos_client
import pytest
from test_config import _test_config


# This test class serves to test user-configurable options and verify they are
# properly set and saved into the different object instances that use these
# user-configurable settings.

pytestmark = pytest.mark.cosmosEmulator

@pytest.mark.usefixtures("teardown")
class TestUserConfigs(unittest.TestCase):

def test_enable_endpoint_discovery(self):
client_false = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey,
enable_endpoint_discovery=False)
client_default = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey)
client_true = cosmos_client.CosmosClient(url=_test_config.host, credential=_test_config.masterKey,
enable_endpoint_discovery=True)

self.assertFalse(client_false.client_connection.connection_policy.EnableEndpointDiscovery)
self.assertTrue(client_default.client_connection.connection_policy.EnableEndpointDiscovery)
self.assertTrue(client_true.client_connection.connection_policy.EnableEndpointDiscovery)

if __name__ == "__main__":
unittest.main()