diff --git a/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/CosmosFactory.java b/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/CosmosFactory.java index 3f59a7b04dd1..ca15da64c989 100644 --- a/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/CosmosFactory.java +++ b/sdk/cosmos/azure-spring-data-cosmos/src/main/java/com/azure/spring/data/cosmos/CosmosFactory.java @@ -81,7 +81,10 @@ private CosmosClientBuilder getCosmosClientBuilderFromConfig(CosmosConfig cosmos final CosmosClientBuilder cosmosClientBuilder = cosmosConfig.getCosmosClientBuilder(); cosmosClientBuilder.contentResponseOnWriteEnabled(true); final String userAgentSuffixValue = getUserAgentSuffixValue(cosmosClientBuilder); - final String userAgentSuffix = getUserAgentSuffix() + userAgentSuffixValue; + String userAgentSuffix = getUserAgentSuffix(); + if (!userAgentSuffixValue.contains(userAgentSuffix)) { + userAgentSuffix += userAgentSuffixValue; + } return cosmosConfig.getCosmosClientBuilder().userAgentSuffix(userAgentSuffix); } diff --git a/sdk/cosmos/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java b/sdk/cosmos/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java index a7f06d1a5b19..75a4399caa85 100644 --- a/sdk/cosmos/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java +++ b/sdk/cosmos/azure-spring-data-cosmos/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageablePersonRepositoryIT.java @@ -32,8 +32,8 @@ @ContextConfiguration(classes = TestRepositoryConfig.class) public class PageablePersonRepositoryIT { - private static final int TOTAL_CONTENT_SIZE = 50; - public static final long ONE_KB = 1024L; + private static final int TOTAL_CONTENT_SIZE = 25; + public static final int ONE_KB = 1024; private static final CosmosEntityInformation entityInformation = new CosmosEntityInformation<>(PageablePerson.class); @@ -63,7 +63,7 @@ public void setUp() { for (int i = 0; i < TOTAL_CONTENT_SIZE; i++) { final List hobbies = new ArrayList<>(); hobbies.add(StringUtils.repeat("hobbies-" + UUID.randomUUID().toString(), - (int) ONE_KB * 10)); + ONE_KB * 10)); final List
address = new ArrayList<>(); address.add(new Address("postalCode-" + UUID.randomUUID().toString(), "street-" + UUID.randomUUID().toString(), @@ -85,18 +85,18 @@ public static void afterClassCleanup() { // Cosmos DB can return any number of documents less than or equal to requested page size // Because of available RUs, the number of return documents vary. // With documents more than 10 KB, and collection RUs 400, - // it usually return documents less than total content size. + // it usually return documents less than total 12 documents. - // This test covers the case where page size is greater than returned documents + // This test covers the case where page size is greater than returned documents limit @Test - public void testFindAllWithPageSizeGreaterThanReturned() { - final Set outputSet = findAllWithPageSize(30, false); + public void testFindAllWithPageSizeGreaterThanReturnedLimit() { + final Set outputSet = findAllWithPageSize(15, true); assertThat(outputSet).isEqualTo(personSet); } - // This test covers the case where page size is less than returned documents + // This test covers the case where page size is less than returned documents limit @Test - public void testFindAllWithPageSizeLessThanReturned() { + public void testFindAllWithPageSizeLessThanReturnedLimit() { final Set outputSet = findAllWithPageSize(5, false); assertThat(outputSet).isEqualTo(personSet); } @@ -104,23 +104,25 @@ public void testFindAllWithPageSizeLessThanReturned() { // This test covers the case where page size is greater than total number of documents @Test public void testFindAllWithPageSizeGreaterThanTotal() { - final Set outputSet = findAllWithPageSize(120, true); + final Set outputSet = findAllWithPageSize(50, true); assertThat(outputSet).isEqualTo(personSet); } private Set findAllWithPageSize(int pageSize, boolean checkContentLimit) { final CosmosPageRequest pageRequest = new CosmosPageRequest(0, pageSize, null); Page page = repository.findAll(pageRequest); - final Set outputSet = new HashSet<>(page.getContent()); + List content = page.getContent(); + final Set outputSet = new HashSet<>(content); if (checkContentLimit) { // Make sure CosmosDB returns less number of documents than requested // This will verify the functionality of new pagination implementation - assertThat(page.getContent().size()).isLessThan(pageSize); + assertThat(content.size()).isLessThan(pageSize); } while (page.hasNext()) { final Pageable pageable = page.nextPageable(); page = repository.findAll(pageable); - outputSet.addAll((page.getContent())); + content = page.getContent(); + outputSet.addAll((content)); } return outputSet; }