Adding content retrieval performance test

This commit is contained in:
Morten Christensen
2012-11-08 19:23:25 -01:00
parent ac9ab759e9
commit 21ca6fbc96
3 changed files with 212 additions and 1 deletions

View File

@@ -0,0 +1,185 @@
using System;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Services
{
[TestFixture]
public class ContentServicePerformanceTest : BaseDatabaseFactoryTest
{
[SetUp]
public override void Initialize()
{
base.Initialize();
CreateTestData();
}
[Test]
public void Creating_100_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 100);
// Act
Stopwatch watch = Stopwatch.StartNew();
ServiceContext.ContentService.Save(pages, 0);
watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine("100 content items saved in {0} ms", elapsed);
// Assert
Assert.That(pages.Any(x => x.HasIdentity == false), Is.False);
}
[Test]
public void Creating_1000_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 1000);
// Act
Stopwatch watch = Stopwatch.StartNew();
ServiceContext.ContentService.Save(pages, 0);
watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine("100 content items saved in {0} ms", elapsed);
// Assert
Assert.That(pages.Any(x => x.HasIdentity == false), Is.False);
}
[Test]
public void Getting_100_Uncached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 100);
ServiceContext.ContentService.Save(pages, 0);
var provider = new PetaPocoUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
var contentTypeRepository = new ContentTypeRepository(unitOfWork);
var repository = new ContentRepository(unitOfWork, NullCacheProvider.Current, contentTypeRepository);
// Act
Stopwatch watch = Stopwatch.StartNew();
var contents = repository.GetAll();
watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine("100 content items retrieved in {0} ms without caching", elapsed);
// Assert
Assert.That(contents.Any(x => x.HasIdentity == false), Is.False);
Assert.That(contents.Any(x => x == null), Is.False);
}
[Test, Ignore]
public void Getting_1000_Uncached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 1000);
ServiceContext.ContentService.Save(pages, 0);
var provider = new PetaPocoUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
var contentTypeRepository = new ContentTypeRepository(unitOfWork);
var repository = new ContentRepository(unitOfWork, NullCacheProvider.Current, contentTypeRepository);
// Act
Stopwatch watch = Stopwatch.StartNew();
var contents = repository.GetAll();
watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine("1000 content items retrieved in {0} ms without caching", elapsed);
// Assert
//Assert.That(contents.Any(x => x.HasIdentity == false), Is.False);
//Assert.That(contents.Any(x => x == null), Is.False);
}
[Test]
public void Getting_100_Cached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 100);
ServiceContext.ContentService.Save(pages, 0);
var provider = new PetaPocoUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
var contentTypeRepository = new ContentTypeRepository(unitOfWork);
var repository = new ContentRepository(unitOfWork, InMemoryCacheProvider.Current, contentTypeRepository);
// Act
var contents = repository.GetAll();
Stopwatch watch = Stopwatch.StartNew();
var contentsCached = repository.GetAll();
watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine("100 content items retrieved in {0} ms with caching", elapsed);
// Assert
Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False);
Assert.That(contentsCached.Any(x => x == null), Is.False);
Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count()));
}
[Test, Ignore]
public void Getting_1000_Cached_Items()
{
// Arrange
var contentType = ServiceContext.ContentTypeService.GetContentType(1045);
var pages = MockedContent.CreateTextpageContent(contentType, -1, 1000);
ServiceContext.ContentService.Save(pages, 0);
var provider = new PetaPocoUnitOfWorkProvider();
var unitOfWork = provider.GetUnitOfWork();
var contentTypeRepository = new ContentTypeRepository(unitOfWork);
var repository = new ContentRepository(unitOfWork, InMemoryCacheProvider.Current, contentTypeRepository);
// Act
var contents = repository.GetAll();
Stopwatch watch = Stopwatch.StartNew();
var contentsCached = repository.GetAll();
watch.Stop();
var elapsed = watch.ElapsedMilliseconds;
Console.WriteLine("1000 content items retrieved in {0} ms with caching", elapsed);
// Assert
//Assert.That(contentsCached.Any(x => x.HasIdentity == false), Is.False);
//Assert.That(contentsCached.Any(x => x == null), Is.False);
//Assert.That(contentsCached.Count(), Is.EqualTo(contents.Count()));
}
[TearDown]
public override void TearDown()
{
base.TearDown();
}
public void CreateTestData()
{
//Create and Save ContentType "textpage" -> 1045
ContentType contentType = MockedContentTypes.CreateTextpageContentType();
ServiceContext.ContentTypeService.Save(contentType);
}
}
}

View File

@@ -1,4 +1,5 @@
using Umbraco.Core.Models;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
namespace Umbraco.Tests.TestHelpers.Entities
@@ -53,5 +54,29 @@ namespace Umbraco.Tests.TestHelpers.Entities
return content;
}
public static IEnumerable<Content> CreateTextpageContent(IContentType contentType, int parentId, int amount)
{
var list = new List<Content>();
for (int i = 0; i < amount; i++)
{
var name = "Textpage No-" + i;
var content = new Content(parentId, contentType) { Name = name, Language = "en-US", ParentId = parentId, Template = "~/masterpages/umbTextPage.master", Creator = new Profile(0, "Administrator"), Writer = new Profile(0, "Administrator") };
object obj =
new
{
title = name + " title",
bodyText = string.Format("This is a textpage based on the {0} ContentType", contentType.Alias),
keywords = "text,page,meta",
metaDescription = "This is the meta description for a textpage"
};
content.PropertyValues(obj);
list.Add(content);
}
return list;
}
}
}

View File

@@ -145,6 +145,7 @@
<Compile Include="Routing\NiceUrlsProviderWithDomainsTests.cs" />
<Compile Include="Routing\uQueryGetNodeIdByUrlTests.cs" />
<Compile Include="Routing\UrlsWithNestedDomains.cs" />
<Compile Include="Services\ContentServicePerformanceTest.cs" />
<Compile Include="Services\ContentServiceTests.cs" />
<Compile Include="Surface\PluginControllerAreaTests.cs" />
<Compile Include="Templates\MasterPageHelperTests.cs" />