Beispiel #1
0
        public async Task <IAnalyticsResult <T> > AnalyticsQueryAsync <T>(string statement, AnalyticsOptions?options = default)
        {
            options ??= new AnalyticsOptions();

            if (!options.TimeoutValue.HasValue)
            {
                options.Timeout(_context.ClusterOptions.AnalyticsTimeout);
            }

            if (string.IsNullOrWhiteSpace(options.ClientContextIdValue))
            {
                options.ClientContextId(Guid.NewGuid().ToString());
            }

            ThrowIfNotBootstrapped();

            if (options.RetryStrategyValue == null)
            {
                options.RetryStrategy(_retryStrategy);
            }

            async Task <IAnalyticsResult <T> > Func()
            {
                var client1  = LazyAnalyticsClient.Value;
                var options1 = options;

                return(await client1.QueryAsync <T>(statement, options1).ConfigureAwait(false));
            }

            //for measuring latencies
            var recorder = _meter.ValueRecorder(OuterRequestSpans.ServiceSpan.AnalyticsQuery);

            return(await _retryOrchestrator.RetryAsync(Func, AnalyticsRequest.Create(statement, recorder, options)).ConfigureAwait(false));
        }
Beispiel #2
0
        public async Task Test_Analytics(string file, HttpStatusCode httpStatusCode, Type errorType, bool readOnly)
        {
            var retryOrchestrator = CreateRetryOrchestrator();

            using (var response = ResourceHelper.ReadResourceAsStream(@"Documents\Analytics\" + file))
            {
                var buffer = new byte[response.Length];
                response.Read(buffer, 0, buffer.Length);

                var responses = GetResponses(20, buffer, httpStatusCode);
                var client    = MockedHttpClients.AnalyticsClient(responses);

                using var cts = new CancellationTokenSource();
                cts.CancelAfter(1000);

                var statement = "SELECT * FROM `bar`;";
                var options   = new AnalyticsOptions();
                options.Timeout(TimeSpan.FromSeconds(1000));
                options.CancellationToken(cts.Token);
                options.Readonly(readOnly);

                async Task <IAnalyticsResult <dynamic> > Send()
                {
                    var client1 = client;

                    return(await client1.QueryAsync <dynamic>(statement, options));
                }

                var meter = NoopMeter.Instance;
                await AssertThrowsIfExpectedAsync(errorType, () => retryOrchestrator.RetryAsync(Send, AnalyticsRequest.Create(statement, meter.ValueRecorder("analytics"), options)));
            }
        }