mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 05:53:33 -07:00
removed Season/SeasonProvider, updated dbBenchmark tests.
This commit is contained in:
parent
2ecd5ddb98
commit
d3be516fb2
34 changed files with 317 additions and 485 deletions
|
@ -1,117 +1,153 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class DbBenchmark
|
||||
public class DbBenchmark : TestBase
|
||||
{
|
||||
const int COUNT = 10000;
|
||||
private List<Episode> episodes;
|
||||
private List<EpisodeFile> files;
|
||||
const int Episodes_Per_Season = 20;
|
||||
private readonly List<int> seasonsNumbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
private readonly List<int> seriesIds = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
private readonly List<Episode> episodes = new List<Episode>();
|
||||
private readonly List<EpisodeFile> files = new List<EpisodeFile>();
|
||||
private readonly IRepository repo = MockLib.GetEmptyRepository();
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
[TestFixtureSetUp]
|
||||
public new void Setup()
|
||||
{
|
||||
|
||||
|
||||
episodes = new List<Episode>(COUNT);
|
||||
files = new List<EpisodeFile>(COUNT);
|
||||
base.Setup();
|
||||
|
||||
for (int i = 10; i < COUNT + 10; i++)
|
||||
foreach (var _seriesId in seriesIds)
|
||||
{
|
||||
var file = Builder<EpisodeFile>.CreateNew().With(c => c.EpisodeFileId = i).Build();
|
||||
files.Add(file);
|
||||
int seriesId = _seriesId;
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = seriesId)
|
||||
.With(s => s.Monitored = true)
|
||||
.Build();
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(c => c.EpisodeId = i)
|
||||
.And(c => c.EpisodeFileId = i)
|
||||
.And(c => c.Title = DateTime.Now.ToLongTimeString())
|
||||
.And(
|
||||
c =>
|
||||
c.Overview =
|
||||
@"This adds support for silverlight. Both the 3.5 CLR and a Silverlight 3
|
||||
version are included in the zip file. Also includes some other very minor bug fixes.").Build();
|
||||
repo.Add(series);
|
||||
|
||||
foreach (var _seasonNumber in seasonsNumbers)
|
||||
{
|
||||
for (int i = 1; i <= Episodes_Per_Season; i++)
|
||||
{
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.SeriesId = seriesId)
|
||||
.And(e => e.SeasonNumber = _seasonNumber)
|
||||
.And(e => e.EpisodeNumber = i)
|
||||
.And(e => e.Ignored = false)
|
||||
.And(e => e.TvDbEpisodeId = episodes.Count + 1)
|
||||
.And(e => e.AirDate = DateTime.Today.AddDays(-20))
|
||||
.Build();
|
||||
|
||||
episodes.Add(episode);
|
||||
|
||||
if (i < 10)
|
||||
{
|
||||
var epFile = Builder<EpisodeFile>.CreateNew()
|
||||
.With(e => e.SeriesId = seriesId)
|
||||
.And(e => e.SeasonNumber = _seasonNumber)
|
||||
.And(e => e.Path = Guid.NewGuid().ToString())
|
||||
.Build();
|
||||
|
||||
files.Add(epFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repo.AddMany(episodes);
|
||||
repo.AddMany(files);
|
||||
|
||||
episodes.Add(episode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void Insert_into_episodes()
|
||||
public void get_episode_by_series_seasons_episode_x1000()
|
||||
{
|
||||
var repo = MockLib.GetEmptyRepository();
|
||||
var epProvider = new EpisodeProvider(repo, null);
|
||||
|
||||
Thread.Sleep(1000);
|
||||
var sw = Stopwatch.StartNew();
|
||||
repo.AddMany(episodes);
|
||||
sw.Stop();
|
||||
|
||||
Console.WriteLine("Adding " + COUNT + " items at once took " + sw.Elapsed);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Insert_into_episodes_single()
|
||||
{
|
||||
var repo = MockLib.GetEmptyRepository();
|
||||
|
||||
Thread.Sleep(1000);
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
repo.Add(episodes[i]);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Console.WriteLine("Adding " + 100 + " single items took " + sw.Elapsed);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void get_episode_file()
|
||||
{
|
||||
var repo = MockLib.GetEmptyRepository();
|
||||
|
||||
repo.AddMany(episodes);
|
||||
repo.AddMany(files);
|
||||
|
||||
//var repoEpisodes = repo.All<Episode>().ToList();
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var count = 0;
|
||||
|
||||
var random = new Random();
|
||||
Console.WriteLine("Starting Test");
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
|
||||
|
||||
for (int i = 5000; i < 5000 + 1000; i++)
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
count++;
|
||||
var file = repo.Single<Episode>(random.Next(10, COUNT - 100)).EpisodeFile;
|
||||
epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10)).Should().NotBeNull();
|
||||
}
|
||||
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Console.WriteLine("Getting " + count + " episode files took " + sw.Elapsed);
|
||||
Console.WriteLine("Took " + sw.Elapsed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_episode_by_series_seasons_x500()
|
||||
{
|
||||
var epProvider = new EpisodeProvider(repo, null);
|
||||
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
|
||||
var random = new Random();
|
||||
Console.WriteLine("Starting Test");
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
for (int i = 0; i < 500; i++)
|
||||
{
|
||||
epProvider.GetEpisodesBySeason(6, random.Next(2, 5)).Should().NotBeNull();
|
||||
}
|
||||
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Console.WriteLine("Took " + sw.Elapsed);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void get_episode_file_count_x50()
|
||||
{
|
||||
var mocker = new AutoMoq.AutoMoqer();
|
||||
mocker.SetConstant(repo);
|
||||
mocker.SetConstant(mocker.Resolve<EpisodeProvider>());
|
||||
var mediaProvider = mocker.Resolve<MediaFileProvider>();
|
||||
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
|
||||
var random = new Random();
|
||||
Console.WriteLine("Starting Test");
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull();
|
||||
}
|
||||
|
||||
|
||||
sw.Stop();
|
||||
|
||||
Console.WriteLine("Took " + sw.Elapsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue