protected override Task <WorkloadOperationResult> OnExecuteStep(IBucket bucket, int workloadIndex, int docIndex, Func <TimeSpan> getTiming)
        {
            var key       = DocKeyGenerator.Generate(workloadIndex, docIndex);
            var randomKey = DocKeyGenerator.Generate(workloadIndex, docIndex);

            if (UseSync)
            {
                var upsertResult = bucket.Upsert(key, SampleDocument);
                var getResult    = bucket.Get <string>(randomKey);

                return(Task.FromResult(
                           new WorkloadOperationResult(upsertResult.Success && getResult.Success, GetMessage(upsertResult, getResult), getTiming())
                           ));
            }

            return(Task.WhenAll(
                       bucket.UpsertAsync(key, SampleDocument), bucket.GetAsync <string>(randomKey)
                       )
                   .ContinueWith(tasks => new WorkloadOperationResult(tasks.Result[0].Success && tasks.Result[1].Success,
                                                                      GetMessage(tasks.Result[0], tasks.Result[1]),
                                                                      getTiming())
            {
                DocSize = GetDocSize(tasks.Result[1]) + SampleDocument.Length
            }));
        }
        /// <summary>
        /// Not included in timing. Could be used to perform setup logic.
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="workloadIndex"></param>
        /// <param name="docIndex"></param>
        protected override Task OnPreExecute(IBucket bucket, int workloadIndex, int docIndex)
        {
            var keys = DocKeyGenerator.GenerateAllKeys(workloadIndex, docIndex);

            return(Task.WhenAll(
                       keys.Select(key => bucket.UpsertAsync(key, SampleDocument))
                       ));
        }
Esempio n. 3
0
        protected override Task <WorkloadOperationResult> OnExecuteStep(IBucket bucket, int workloadIndex, int docIndex, Func <TimeSpan> getTiming)
        {
            var key = DocKeyGenerator.Generate(workloadIndex, docIndex);

            if (UseSync)
            {
                var upsertResult = bucket.Upsert(key, SampleDocument);
                return(Task.FromResult(
                           new WorkloadOperationResult(upsertResult.Success, upsertResult.Message, getTiming())
                           ));
            }

            return(bucket.UpsertAsync(key, SampleDocument)
                   .ContinueWith(task => new WorkloadOperationResult(task.Result.Success, task.Result.Message, getTiming())
            {
                DocSize = SampleDocument.Length
            }));
        }
        protected override Task <WorkloadOperationResult> OnExecuteStep(IBucket bucket, int workloadIndex, int docIndex, Func <TimeSpan> getTiming)
        {
            var key = DocKeyGenerator.Generate(workloadIndex, docIndex);

            if (UseSync)
            {
                var result = Randomizer.NextDouble() <= _mutationPercentage
                    ? bucket.Upsert(key, SampleDocument)
                    : bucket.Get <string>(key);

                return(Task.FromResult(
                           new WorkloadOperationResult(result.Success, result.Message, getTiming())
                           ));
            }

            return((Randomizer.NextDouble() <= _mutationPercentage
                    ? bucket.UpsertAsync(key, SampleDocument)
                    : bucket.GetAsync <string>(key))
                   .ContinueWith(
                       task => new WorkloadOperationResult(task.Result.Success, task.Result.Message, getTiming())
                       ));
        }