forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alwaysUsePagedFluxMaxItemCount (Azure#36847)
* alwaysUsePagedFluxMaxItemCount --------- Co-authored-by: annie-mac <xinlian@microsoft.com>
- Loading branch information
Showing
13 changed files
with
404 additions
and
166 deletions.
There are no files selected for viewing
280 changes: 182 additions & 98 deletions
280
...-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncContainer.java
Large diffs are not rendered by default.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
...ain/java/com/azure/cosmos/encryption/implementation/CosmosEncryptionQueryTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.cosmos.encryption.implementation; | ||
|
||
import com.azure.cosmos.BridgeInternal; | ||
import com.azure.cosmos.implementation.CosmosPagedFluxOptions; | ||
import com.azure.cosmos.implementation.ItemDeserializer; | ||
import com.azure.cosmos.implementation.query.Transformer; | ||
import com.azure.cosmos.models.FeedResponse; | ||
import com.azure.cosmos.models.ModelBridgeInternal; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.core.scheduler.Scheduler; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
public class CosmosEncryptionQueryTransformer<T> implements Transformer<T> { | ||
private final Scheduler encryptionScheduler; | ||
private final EncryptionProcessor encryptionProcessor; | ||
private final ItemDeserializer itemDeserializer; | ||
private final Class<T> classType; | ||
private final boolean isChangeFeed; | ||
|
||
public CosmosEncryptionQueryTransformer( | ||
Scheduler encryptionScheduler, | ||
EncryptionProcessor encryptionProcessor, | ||
ItemDeserializer itemDeserializer, | ||
Class<T> classType, | ||
Boolean isChangeFeed) { | ||
this.encryptionScheduler = encryptionScheduler; | ||
this.encryptionProcessor = encryptionProcessor; | ||
this.itemDeserializer = itemDeserializer; | ||
this.classType = classType; | ||
this.isChangeFeed = isChangeFeed; | ||
} | ||
|
||
@Override | ||
public Function<CosmosPagedFluxOptions, Flux<FeedResponse<T>>> transform(Function<CosmosPagedFluxOptions, Flux<FeedResponse<JsonNode>>> func) { | ||
return queryDecryptionTransformer(this.classType, this.isChangeFeed, func); | ||
} | ||
|
||
private <T> Function<CosmosPagedFluxOptions, Flux<FeedResponse<T>>> queryDecryptionTransformer( | ||
Class<T> classType, | ||
boolean isChangeFeed, | ||
Function<CosmosPagedFluxOptions, Flux<FeedResponse<JsonNode>>> func) { | ||
return func.andThen(flux -> | ||
flux.publishOn(encryptionScheduler) | ||
.flatMap( | ||
page -> { | ||
boolean useEtagAsContinuation = isChangeFeed; | ||
boolean isNoChangesResponse = isChangeFeed ? | ||
ModelBridgeInternal.getNoChangesFromFeedResponse(page) | ||
: false; | ||
List<Mono<JsonNode>> jsonNodeArrayMonoList = | ||
page.getResults().stream().map(jsonNode -> decryptResponseNode(jsonNode)).collect(Collectors.toList()); | ||
return Flux.concat(jsonNodeArrayMonoList).map( | ||
item -> this.itemDeserializer.convert(classType, item) | ||
).collectList().map(itemList -> BridgeInternal.createFeedResponseWithQueryMetrics(itemList, | ||
page.getResponseHeaders(), | ||
BridgeInternal.queryMetricsFromFeedResponse(page), | ||
ModelBridgeInternal.getQueryPlanDiagnosticsContext(page), | ||
useEtagAsContinuation, | ||
isNoChangesResponse, | ||
page.getCosmosDiagnostics()) | ||
); | ||
} | ||
) | ||
); | ||
} | ||
|
||
Mono<JsonNode> decryptResponseNode( | ||
JsonNode jsonNode) { | ||
|
||
if (jsonNode == null) { | ||
return Mono.empty(); | ||
} | ||
|
||
return this.encryptionProcessor.decryptJsonNode( | ||
jsonNode); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/CosmosReadAllItemsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.cosmos.rx; | ||
|
||
import com.azure.cosmos.CosmosAsyncClient; | ||
import com.azure.cosmos.CosmosAsyncContainer; | ||
import com.azure.cosmos.CosmosClientBuilder; | ||
import com.azure.cosmos.TestObject; | ||
import com.azure.cosmos.implementation.FeedResponseListValidator; | ||
import com.azure.cosmos.models.CosmosQueryRequestOptions; | ||
import com.azure.cosmos.models.PartitionKey; | ||
import com.azure.cosmos.util.CosmosPagedFlux; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Factory; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.UUID; | ||
|
||
public class CosmosReadAllItemsTests extends TestSuiteBase { | ||
private final static int TIMEOUT = 30000; | ||
private CosmosAsyncClient client; | ||
private CosmosAsyncContainer container; | ||
|
||
@Factory(dataProvider = "clientBuildersWithSessionConsistency") | ||
public CosmosReadAllItemsTests(CosmosClientBuilder clientBuilder) { | ||
super(clientBuilder); | ||
} | ||
|
||
@Test(groups = { "query" }, timeOut = 2 * TIMEOUT) | ||
public void readMany_UsePageSizeInPagedFluxOption() { | ||
|
||
// first creating few items | ||
String pkValue = UUID.randomUUID().toString(); | ||
int itemCount = 10; | ||
for (int i = 0; i < itemCount; i++) { | ||
TestObject testObject = TestObject.create(pkValue); | ||
this.container.createItem(testObject).block(); | ||
} | ||
|
||
CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions(); | ||
|
||
FeedResponseListValidator<TestObject> validator1 = | ||
new FeedResponseListValidator | ||
.Builder<TestObject>() | ||
.totalSize(itemCount) | ||
.numberOfPages(2) | ||
.build(); | ||
CosmosPagedFlux<TestObject> queryObservable1 = | ||
this.container.readAllItems(new PartitionKey(pkValue), cosmosQueryRequestOptions, TestObject.class); | ||
|
||
validateQuerySuccess(queryObservable1.byPage(5), validator1, TIMEOUT); | ||
|
||
CosmosQueryRequestOptions options = new CosmosQueryRequestOptions(); | ||
options.setMaxDegreeOfParallelism(2); | ||
|
||
FeedResponseListValidator<TestObject> validator2 = | ||
new FeedResponseListValidator | ||
.Builder<TestObject>() | ||
.totalSize(itemCount) | ||
.numberOfPages(1) | ||
.build(); | ||
validateQuerySuccess(queryObservable1.byPage(), validator2, TIMEOUT); | ||
} | ||
|
||
@AfterClass(groups = { "query" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) | ||
public void afterClass() { | ||
safeClose(client); | ||
} | ||
|
||
@BeforeClass(groups = { "query" }, timeOut = SETUP_TIMEOUT) | ||
public void before_TopQueryTests() { | ||
this.client = getClientBuilder().buildAsyncClient(); | ||
this.container = getSharedSinglePartitionCosmosContainer(client); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.