Ejemplo n.º 1
0
 public void Sleep100ms(IMetricCollector collector)
 {
     using (collector.StartCollection())
     {
         Thread.Sleep(100);
     }
 }
Ejemplo n.º 2
0
 public void Calibration_100ms_controlled(IMetricCollector collector)
 {
     Thread.Sleep(100);
     using (collector.StartCollection())
     {
         Thread.Sleep(100);
     }
 }
Ejemplo n.º 3
0
        public void ToList(IMetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .AsNoTracking();

                using (collector.StartCollection())
                {
                    for (var i = 0; i < 10; i++)
                    {
                        query.ToList();
                    }
                }

                Assert.Equal(0, query.Count());
            }
        }
Ejemplo n.º 4
0
        public void LoadAll(IMetricCollector collector, bool tracking, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products.ApplyTracking(tracking);

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        query.ToList();
                    }
                }

                Assert.Equal(1000, query.Count());
                Assert.False(tracking && (queriesPerIteration != 1), "Multiple queries per iteration not valid for tracking queries");
            }
        }
Ejemplo n.º 5
0
        public void Update(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: true);
                context.Customers.AttachRange(customers);

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Customers.Update(customer);
                    }
                }
            }
        }
        public void Update(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(20000, setPrimaryKeys: true);
                customers.ForEach(c => context.Customers.Attach(c));

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void Remove(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(1000, setPrimaryKeys: true);
                customers.ForEach(c => context.Customers.Attach(c));

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Customers.Remove(customer);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void SameQueryInstance(IMetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                using (collector.StartCollection())
                {
                    var val   = 11;
                    var query = context.Products.Where(p => p.ProductId < val);

                    for (var i = 0; i < _funcletizationIterationCount; i++)
                    {
                        var result = query.ToList();

                        Assert.Equal(10, result.Count);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void Count(IMetricCollector collector, bool caching, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .ApplyCaching(caching);

                using (collector.StartCollection())
                {
                    for (int i = 0; i < queriesPerIteration; i++)
                    {
                        query.Count();
                    }
                }

                Assert.Equal(1000, query.Count());
            }
        }
        public void Update(IMetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                using (context.Database.BeginTransaction())
                {
                    foreach (var customer in context.Customers)
                    {
                        customer.FirstName += " Modified";
                    }

                    collector.StartCollection();
                    var records = context.SaveChanges();
                    collector.StopCollection();

                    Assert.Equal(1000, records);
                }
            }
        }
Ejemplo n.º 11
0
        public async Task Delete(IMetricCollector collector, bool async)
        {
            using (var context = _fixture.CreateContext())
            {
                using (context.Database.BeginTransaction())
                {
                    context.Customers.RemoveRange(context.Customers.ToList());

                    collector.StartCollection();
                    var records = async
                        ? await context.SaveChangesAsync()
                        : context.SaveChanges();

                    collector.StopCollection();

                    Assert.Equal(1000, records);
                }
            }
        }
Ejemplo n.º 12
0
        public void OrderBy(IMetricCollector collector, bool tracking, bool caching, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext(queryCachingEnabled: caching))
            {
                var query = context.Products
                            .ApplyTracking(tracking)
                            .OrderBy(p => p.Retail);

                using (collector.StartCollection())
                {
                    for (int i = 0; i < queriesPerIteration; i++)
                    {
                        query.ToList();
                    }
                }

                Assert.Equal(1000, query.Count());
                Assert.False(tracking && queriesPerIteration != 1, "Multiple queries per iteration not valid for tracking queries");
            }
        }
Ejemplo n.º 13
0
        public async Task Insert(IMetricCollector collector, bool async)
        {
            using (var context = _fixture.CreateContext())
            {
                using (context.Database.BeginTransaction())
                {
                    var customers = _fixture.CreateCustomers(1000, setPrimaryKeys: false);
                    context.Customers.AddRange(customers);

                    collector.StartCollection();
                    var records = async
                        ? await context.SaveChangesAsync()
                        : context.SaveChanges();

                    collector.StopCollection();

                    Assert.Equal(1000, records);
                }
            }
        }
Ejemplo n.º 14
0
        public void StoredProcedure(IMetricCollector collector, bool tracking, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .FromSql("EXECUTE dbo.SearchProducts @p0, @p1", 10, 14)
                            .ApplyTracking(tracking);

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        query.ToList();
                    }
                }

                Assert.Equal(500, query.Count());
                Assert.False(tracking && (queriesPerIteration != 1), "Multiple queries per iteration not valid for tracking queries");
            }
        }
Ejemplo n.º 15
0
        public void SelectParameterized(IMetricCollector collector, bool tracking, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .FromSql("SELECT * FROM dbo.Product WHERE CurrentPrice >= @p0 AND CurrentPrice <= @p1", 10, 14)
                            .ApplyTracking(tracking);

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        query.ToList();
                    }
                }

                Assert.Equal(500, query.Count());
                Assert.False(tracking && (queriesPerIteration != 1), "Multiple queries per iteration not valid for tracking queries");
            }
        }
Ejemplo n.º 16
0
        public void AttachChildren(IMetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var customers = _fixture.CreateCustomers(1000, setPrimaryKeys: true);
                var orders    = _fixture.CreateOrders(customers, ordersPerCustomer: 1, setPrimaryKeys: true);
                customers.ForEach(c => context.Customers.Attach(c));

                Assert.All(orders, o => Assert.Null(o.Customer));

                using (collector.StartCollection())
                {
                    foreach (var order in orders)
                    {
                        context.Orders.Attach(order);
                    }
                }

                Assert.All(orders, o => Assert.NotNull(o.Customer));
            }
        }
Ejemplo n.º 17
0
        public void AttachParents(IMetricCollector collector)
        {
            using (var context = _fixture.CreateContext())
            {
                var customers = _fixture.CreateCustomers(1000, setPrimaryKeys: true);
                var orders    = _fixture.CreateOrders(customers, ordersPerCustomer: 1, setPrimaryKeys: true);
                orders.ForEach(o => context.Orders.Attach(o));

                Assert.All(customers, c => Assert.Null(c.Orders));

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Customers.Attach(customer);
                    }
                }

                Assert.All(customers, c => Assert.Equal(1, c.Orders.Count));
            }
        }
        public async Task Update(IMetricCollector collector, bool disableBatching, bool async)
        {
            using (var context = _fixture.CreateContext(disableBatching))
            {
                using (context.Database.BeginTransaction())
                {
                    foreach (var customer in context.Customers)
                    {
                        customer.FirstName += " Modified";
                    }

                    collector.StartCollection();
                    var records = async
                        ? await context.SaveChangesAsync()
                        : context.SaveChanges();

                    collector.StopCollection();

                    Assert.Equal(1000, records);
                }
            }
        }
        // NOTE: Composition is done on client, so there is no async version
        public void SelectComposed(IMetricCollector collector, bool tracking, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products
                            .SqlQuery("SELECT * FROM dbo.Products")
                            .ApplyTracking(tracking)
                            .Where(p => p.CurrentPrice >= 10 && p.CurrentPrice <= 14)
                            .OrderBy(p => p.Name);

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        query.ToList();
                    }
                }

                Assert.Equal(500, query.Count());
                Assert.False(tracking && (queriesPerIteration != 1), "Multiple queries per iteration not valid for tracking queries");
            }
        }
Ejemplo n.º 20
0
        public void Include(IMetricCollector collector, bool tracking, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Customers
                            .ApplyTracking(tracking)
                            .Include(c => c.Orders);

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        query.ToList();
                    }
                }

                var result = query.ToList();
                Assert.Equal(1000, result.Count);
                Assert.Equal(2000, result.SelectMany(c => c.Orders).Count());
                Assert.False(tracking && (queriesPerIteration != 1), "Multiple queries per iteration not valid for tracking queries");
            }
        }
Ejemplo n.º 21
0
        public void AddParents(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(1000, setPrimaryKeys: true);
                var orders    = _fixture.CreateOrders(customers, ordersPerCustomer: 1, setPrimaryKeys: false);
                context.Orders.AddRange(orders);

                Assert.All(customers, c => Assert.Null(c.Orders));

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Customers.Add(customer);
                    }
                }

                Assert.All(customers, c => Assert.Equal(1, c.Orders.Count));
            }
        }
Ejemplo n.º 22
0
        public void AttachChildren(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.ChangeTracker.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(1000, setPrimaryKeys: true);
                var orders    = _fixture.CreateOrders(customers, ordersPerCustomer: 1, setPrimaryKeys: true);
                context.Customers.AttachRange(customers);

                Assert.All(orders, o => Assert.Null(o.Customer));

                using (collector.StartCollection())
                {
                    foreach (var order in orders)
                    {
                        context.Orders.Attach(order);
                    }
                }

                Assert.All(orders, o => Assert.NotNull(o.Customer));
            }
        }
Ejemplo n.º 23
0
        public void AddChildren(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(5000, setPrimaryKeys: true);
                var orders    = _fixture.CreateOrders(customers, ordersPerCustomer: 2, setPrimaryKeys: false);
                customers.ForEach(c => context.Customers.Attach(c));

                Assert.All(orders, o => Assert.Null(o.Customer));

                using (collector.StartCollection())
                {
                    foreach (var order in orders)
                    {
                        context.Orders.Add(order);
                    }
                }

                Assert.All(orders, o => Assert.NotNull(o.Customer));
            }
        }
Ejemplo n.º 24
0
        public void AttachParents(IMetricCollector collector, bool autoDetectChanges)
        {
            using (var context = _fixture.CreateContext())
            {
                context.Configuration.AutoDetectChangesEnabled = autoDetectChanges;

                var customers = _fixture.CreateCustomers(5000, setPrimaryKeys: true);
                var orders    = _fixture.CreateOrders(customers, ordersPerCustomer: 2, setPrimaryKeys: true);
                orders.ForEach(o => context.Orders.Attach(o));

                Assert.All(customers, c => Assert.Null(c.Orders));

                using (collector.StartCollection())
                {
                    foreach (var customer in customers)
                    {
                        context.Customers.Attach(customer);
                    }
                }

                Assert.All(customers, c => Assert.Equal(2, c.Orders.Count));
            }
        }
Ejemplo n.º 25
0
        public async Task Count(IMetricCollector collector, bool async, int queriesPerIteration)
        {
            using (var context = _fixture.CreateContext())
            {
                var query = context.Products;

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        if (async)
                        {
                            await query.CountAsync();
                        }
                        else
                        {
                            query.Count();
                        }
                    }
                }

                Assert.Equal(1000, query.Count());
            }
        }
        public async Task PredicateAcrossOptionalNavigationFilteredResults(IMetricCollector collector, bool async, int queriesPerIteration)
        {
            using (var context = AdventureWorksFixture.CreateContext())
            {
                var query = context.Store.Where(s => s.SalesPerson.Bonus > 3000);

                using (collector.StartCollection())
                {
                    for (var i = 0; i < queriesPerIteration; i++)
                    {
                        if (async)
                        {
                            await query.ToListAsync();
                        }
                        else
                        {
                            query.ToList();
                        }
                    }
                }

                Assert.Equal(466, query.Count());
            }
        }