public CosmosLinqQuery( ContainerCore container, CosmosResponseFactory responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, Expression expression, bool allowSynchronousQueryExecution) { this.container = container ?? throw new ArgumentNullException(nameof(container)); this.responseFactory = responseFactory ?? throw new ArgumentNullException(nameof(responseFactory)); this.queryClient = queryClient ?? throw new ArgumentNullException(nameof(queryClient)); this.continuationToken = continuationToken; this.cosmosQueryRequestOptions = cosmosQueryRequestOptions; this.Expression = expression ?? Expression.Constant(this); this.allowSynchronousQueryExecution = allowSynchronousQueryExecution; this.correlatedActivityId = Guid.NewGuid(); this.queryProvider = new CosmosLinqQueryProvider( container, responseFactory, queryClient, this.continuationToken, cosmosQueryRequestOptions, this.allowSynchronousQueryExecution, this.queryClient.OnExecuteScalarQueryCallback); }
public async ValueTask <bool> MoveNextAsync() { if (!await this.enumerator.MoveNextAsync()) { return(false); } TryCatch <CrossFeedRangePage <Pagination.ReadFeedPage, ReadFeedState> > monadicInnerReadFeedPage = this.enumerator.Current; if (monadicInnerReadFeedPage.Failed) { this.Current = TryCatch <ReadFeedPage> .FromException(monadicInnerReadFeedPage.Exception); return(true); } CrossFeedRangePage <Pagination.ReadFeedPage, ReadFeedState> innerReadFeedPage = monadicInnerReadFeedPage.Result; CrossFeedRangeState <ReadFeedState> crossFeedRangeState = innerReadFeedPage.State; ReadFeedCrossFeedRangeState? state = crossFeedRangeState != null ? new ReadFeedCrossFeedRangeState(crossFeedRangeState.Value) : (ReadFeedCrossFeedRangeState?)null; CosmosArray documents = CosmosQueryClientCore.ParseElementsFromRestStream( innerReadFeedPage.Page.Content, Documents.ResourceType.Document, cosmosSerializationOptions: null); ReadFeedPage page = new ReadFeedPage( documents, innerReadFeedPage.Page.RequestCharge, innerReadFeedPage.Page.ActivityId, state, innerReadFeedPage.Page.AdditionalHeaders); this.Current = TryCatch <ReadFeedPage> .FromResult(page); return(true); }
public CosmosLinqQuery( ContainerCore container, CosmosSerializer cosmosJsonSerializer, CosmosQueryClientCore queryClient, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution) : this( container, cosmosJsonSerializer, queryClient, cosmosQueryRequestOptions, null, allowSynchronousQueryExecution) { }
public CosmosLinqQueryProvider( ContainerCore container, CosmosSerializer cosmosJsonSerializer, CosmosQueryClientCore queryClient, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution, Action <IQueryable> onExecuteScalarQueryCallback = null) { this.container = container; this.cosmosJsonSerializer = cosmosJsonSerializer; this.queryClient = queryClient; this.cosmosQueryRequestOptions = cosmosQueryRequestOptions; this.allowSynchronousQueryExecution = allowSynchronousQueryExecution; this.onExecuteScalarQueryCallback = onExecuteScalarQueryCallback; }
public async Task TestInitialize() { await base.TestInit(); // Throughput needs to be large enough for multiple partitions ContainerResponse response = await this.database.CreateContainerAsync( Guid.NewGuid().ToString(), "/id", 15000, cancellationToken : this.cancellationToken); Assert.IsNotNull(response); Assert.IsNotNull(response.Container); Assert.IsNotNull(response.Resource); this.Container = (ContainerInlineCore)response; this.queryClientCore = new CosmosQueryClientCore(this.Container.ClientContext, this.Container); }
public CosmosLinqQuery( ContainerCore container, CosmosResponseFactory responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution) : this( container, responseFactory, queryClient, continuationToken, cosmosQueryRequestOptions, null, allowSynchronousQueryExecution) { }
public CosmosLinqQueryProvider( ContainerCore container, CosmosResponseFactory responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution, Action <IQueryable> onExecuteScalarQueryCallback = null) { this.container = container; this.responseFactory = responseFactory; this.queryClient = queryClient; this.continuationToken = continuationToken; this.cosmosQueryRequestOptions = cosmosQueryRequestOptions; this.allowSynchronousQueryExecution = allowSynchronousQueryExecution; this.onExecuteScalarQueryCallback = onExecuteScalarQueryCallback; }
public CosmosLinqQuery( ContainerInternal container, CosmosResponseFactoryInternal responseFactory, CosmosQueryClientCore queryClient, string continuationToken, QueryRequestOptions cosmosQueryRequestOptions, bool allowSynchronousQueryExecution, CosmosSerializationOptions serializationOptions = null) : this( container, responseFactory, queryClient, continuationToken, cosmosQueryRequestOptions, null, allowSynchronousQueryExecution, serializationOptions) { }
public async ValueTask <bool> MoveNextAsync() { if (!await this.enumerator.MoveNextAsync()) { throw new InvalidOperationException("Change Feed should always be able to move next."); } TryCatch <CrossFeedRangePage <Pagination.ChangeFeedPage, ChangeFeedState> > monadicInnerChangeFeedPage = this.enumerator.Current; if (monadicInnerChangeFeedPage.Failed) { this.Current = TryCatch <ChangeFeedPage> .FromException(monadicInnerChangeFeedPage.Exception); return(true); } CrossFeedRangePage <Pagination.ChangeFeedPage, ChangeFeedState> innerChangeFeedPage = monadicInnerChangeFeedPage.Result; CrossFeedRangeState <ChangeFeedState> crossFeedRangeState = innerChangeFeedPage.State; ChangeFeedCrossFeedRangeState state = new ChangeFeedCrossFeedRangeState(crossFeedRangeState.Value); ChangeFeedPage page = innerChangeFeedPage.Page switch { Pagination.ChangeFeedSuccessPage successPage => ChangeFeedPage.CreatePageWithChanges( CosmosQueryClientCore.ParseElementsFromRestStream( successPage.Content, Documents.ResourceType.Document, cosmosSerializationOptions: null), successPage.RequestCharge, successPage.ActivityId, state), Pagination.ChangeFeedNotModifiedPage notModifiedPage => ChangeFeedPage.CreateNotModifiedPage( notModifiedPage.RequestCharge, notModifiedPage.ActivityId, state), _ => throw new InvalidOperationException($"Unknown type: {innerChangeFeedPage.Page.GetType()}"), }; this.Current = TryCatch <ChangeFeedPage> .FromResult(page); return(true); }
public async Task TestKeyRangeCacheRefresh() { bool validate = false; bool pass = false; string expectedPath = null; HttpClientHandlerHelper httpClientHandler = new HttpClientHandlerHelper { RequestCallBack = (HttpRequestMessage request, CancellationToken cancellationToken) => { if (validate) { pass = request.RequestUri.LocalPath == expectedPath; } return(null); } }; using (CosmosClient client = TestCommon.CreateCosmosClient(builder => builder .WithConnectionModeGateway() .WithHttpClientFactory(() => new HttpClient(httpClientHandler)))) { ContainerInternal containerInternal = client.GetContainer(this.database.Id, this.Container.Id) as ContainerInternal; CosmosQueryClientCore queryClient = new CosmosQueryClientCore(client.ClientContext, containerInternal); NetworkAttachedDocumentContainer networkAttachedDocumentContainer = new NetworkAttachedDocumentContainer( containerInternal, queryClient, Guid.NewGuid()); // warm up the caches _ = await containerInternal.ReadItemStreamAsync("doesnotexist", PartitionKey.Null); ContainerProperties containerProperties = await containerInternal.GetCachedContainerPropertiesAsync(false, NoOpTrace.Singleton, default); expectedPath = "/" + containerProperties.SelfLink + "pkranges"; validate = true; TryCatch result = await networkAttachedDocumentContainer.MonadicRefreshProviderAsync( trace : NoOpTrace.Singleton, cancellationToken : default);
public CosmosLinqQuery( ContainerCore container, CosmosSerializer cosmosJsonSerializer, CosmosQueryClientCore queryClient, QueryRequestOptions cosmosQueryRequestOptions, Expression expression, bool allowSynchronousQueryExecution) { this.container = container ?? throw new ArgumentNullException(nameof(container)); this.cosmosJsonSerializer = cosmosJsonSerializer ?? throw new ArgumentNullException(nameof(cosmosJsonSerializer)); this.queryClient = queryClient ?? throw new ArgumentNullException(nameof(queryClient)); this.cosmosQueryRequestOptions = cosmosQueryRequestOptions; this.expression = expression ?? Expression.Constant(this); this.allowSynchronousQueryExecution = allowSynchronousQueryExecution; this.queryProvider = new CosmosLinqQueryProvider( container, cosmosJsonSerializer, queryClient, cosmosQueryRequestOptions, this.allowSynchronousQueryExecution, this.queryClient.DocumentQueryClient.OnExecuteScalarQueryCallback); this.correlatedActivityId = Guid.NewGuid(); }