Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions sdk/cosmos/azure-cosmos/azure/cosmos/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def GetHeaders( # pylint: disable=too-many-statements,too-many-branches
headers = dict(default_headers)
options = options or {}

# SDK supported capabilities header for partition merge support
headers[http_constants.HttpHeaders.SDKSupportedCapabilities] = \
http_constants.SDKSupportedCapabilities.PARTITION_MERGE

# Generate a new activity ID for each request client side.
headers[http_constants.HttpHeaders.ActivityId] = GenerateGuidId()
if cosmos_client_connection.UseMultipleWriteLocations:
Expand Down
5 changes: 5 additions & 0 deletions sdk/cosmos/azure-cosmos/azure/cosmos/http_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ class _ErrorCodes:
# Linux Error Codes
LinuxConnectionReset = 131

class SDKSupportedCapabilities:
"""Constants of SDK supported capabilities.
"""
NONE = '0'
PARTITION_MERGE = '1'
Comment thread
allenkim0129 marked this conversation as resolved.

class StatusCodes:
"""HTTP status codes returned by the REST operations
Expand Down
37 changes: 37 additions & 0 deletions sdk/cosmos/azure-cosmos/tests/test_partition_merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The MIT License (MIT)
Comment thread
allenkim0129 marked this conversation as resolved.
Outdated
# Copyright (c) Microsoft Corporation. All rights reserved.

import unittest
import pytest

import azure.cosmos.cosmos_client as cosmos_client
import test_config
from azure.cosmos import http_constants

def response_hook(raw_response):
header = raw_response.http_request.headers
assert http_constants.HttpHeaders.SDKSupportedCapabilities in header
assert header[http_constants.HttpHeaders.SDKSupportedCapabilities] == \
http_constants.SDKSupportedCapabilities.PARTITION_MERGE

@pytest.mark.cosmosQuery
class TestPartitionMerge(unittest.TestCase):
configs = test_config.TestConfig
host = configs.host
masterKey = configs.masterKey
TEST_DATABASE_ID = configs.TEST_DATABASE_ID
TEST_CONTAINER_ID = configs.TEST_SINGLE_PARTITION_CONTAINER_ID

@classmethod
def setUpClass(cls):
cls.client = cosmos_client.CosmosClient(cls.host, cls.masterKey)
cls.database = cls.client.get_database_client(cls.TEST_DATABASE_ID)
cls.container = cls.database.get_container_client(cls.TEST_CONTAINER_ID)

def test_header_enabled_partition_merge(self):
# This test only runs read API to verify if the header was set correctly, because all APIs are using the same
# base method to set the header(GetHeaders).
self.container.read(raw_response_hook=response_hook)

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