Пример #1
0
        public async Task DoUpdateCarts(Cart[] carts)
        {
            var list = _times.GetOrAdd("updateCart", (n) => new LinkedList<long>());

            int groupId = 0;
            int cartIndex = 0;
            int nr = Interlocked.Increment(ref _count);
            while (nr <= _queries)
            {
                Cart cart = carts[cartIndex];
                cart.GroupId = _groups[groupId];
                cart.Items = new Dictionary<string, int> { { "item1", nr }, { "item2", nr } };

                long start = _stopwatch.ElapsedMilliseconds;

                await _manager.UpdateCartAsync(cart);

                long stop = _stopwatch.ElapsedMilliseconds;

                lock (list) list.AddLast(stop - start);

                groupId = (groupId + 1) % _groups.Length;
                cartIndex = (cartIndex + 1) % carts.Length;
                nr = Interlocked.Increment(ref _count);
            }
        }
Пример #2
0
        /// <summary>
        ///   Creates the cart async.
        /// </summary>
        /// <returns> </returns>
        public async Task<Cart> AddCartAsync(string groupId)
        {
            var c = new Cart {Id = Guid.NewGuid(), GroupId = groupId};

            using (var connection = new CqlConnection("cartDB"))
            {
                await connection.OpenAsync();

                var command = new CqlCommand(connection, "insert into Shop.Carts (id, groupId) values (?,?);");
                await command.PrepareAsync();
                command.Parameters.Set(c);
                await command.ExecuteNonQueryAsync();
                return c;
            }
        }
Пример #3
0
        public async Task DoAddItems(Cart[] carts)
        {
            var list = _times.GetOrAdd("addItems", (n) => new LinkedList<long>());

            int cartIndex = 0;
            int nr = Interlocked.Increment(ref _count);
            while (nr <= _queries)
            {
                Cart cart = carts[cartIndex];
                var items = new Dictionary<string, int> { { "item1_" + nr, nr }, { "item2_" + nr, nr } };

                long start = _stopwatch.ElapsedMilliseconds;

                await _manager.AddItemsAsync(cart.Id, items);

                long stop = _stopwatch.ElapsedMilliseconds;

                lock (list) list.AddLast(stop - start);

                cartIndex = (cartIndex + 1) % carts.Length;
                nr = Interlocked.Increment(ref _count);
            }
        }
Пример #4
0
        public async Task DoGetItems(Cart[] carts)
        {
            var list = _times.GetOrAdd("getItems", (n) => new LinkedList<long>());

            int cartIndex = 0;
            int nr = Interlocked.Increment(ref _count);
            while (nr <= _queries)
            {
                Cart cart = carts[cartIndex];

                long start = _stopwatch.ElapsedMilliseconds;

                await _manager.GetItemsAsync(cart.Id);

                long stop = _stopwatch.ElapsedMilliseconds;

                lock (list) list.AddLast(stop - start);

                cartIndex = (cartIndex + 1) % carts.Length;
                nr = Interlocked.Increment(ref _count);
            }
        }
Пример #5
0
        /// <summary>
        ///   Updates the cart async.
        /// </summary>
        /// <param name="c"> The c. </param>
        /// <returns> </returns>
        public async Task UpdateCartAsync(Cart c)
        {
            using (var connection = new CqlConnection("cartDB"))
            {
                await connection.OpenAsync();

                var command = new CqlCommand(connection, "update Shop.Carts set groupid=?, items=? where id=?;");
                await command.PrepareAsync();
                command.Parameters.Set(c);
                await command.ExecuteNonQueryAsync();
            }
        }