1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 23:13:24 +01:00
Radarr/NzbDrone.Core.Test/dbBenchmark.cs

243 lines
6.7 KiB
C#
Raw Normal View History

2011-05-30 08:47:11 +02:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
2011-05-30 08:47:11 +02:00
using FizzWare.NBuilder;
using FluentAssertions;
2011-06-02 23:06:46 +02:00
using NUnit.Framework;
using NzbDrone.Core.Providers;
2011-05-30 08:47:11 +02:00
using NzbDrone.Core.Repository;
2011-06-19 20:56:32 +02:00
using NzbDrone.Core.Repository.Quality;
2011-05-30 08:47:11 +02:00
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
2011-06-19 20:56:32 +02:00
using PetaPoco;
2011-05-30 08:47:11 +02:00
namespace NzbDrone.Core.Test
{
[TestFixture]
2011-11-04 00:23:54 +01:00
[Explicit]
[Category("Benchmark")]
2011-05-30 08:47:11 +02:00
// ReSharper disable InconsistentNaming
2011-11-13 08:27:16 +01:00
public class DbBenchmark : CoreTest
2011-05-30 08:47:11 +02:00
{
const int Episodes_Per_Season = 20;
2011-06-05 08:02:31 +02:00
private readonly List<int> seasonsNumbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
private readonly List<int> seriesIds = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
private readonly List<Episode> episodes = new List<Episode>();
private readonly List<EpisodeFile> files = new List<EpisodeFile>();
2011-06-19 20:56:32 +02:00
private IDatabase db;
2011-06-18 03:46:22 +02:00
[TestFixtureSetUp]
2011-10-24 07:54:09 +02:00
public void Setup()
2011-05-30 08:47:11 +02:00
{
db = TestDbHelper.GetEmptyDatabase();
int currentFileId = 0;
2011-05-30 08:47:11 +02:00
2011-06-19 20:56:32 +02:00
var qulityProfile = new QualityProfile
{
Name = "TestProfile",
Allowed = new List<QualityTypes> { QualityTypes.DVD, QualityTypes.Bluray1080p },
Cutoff = QualityTypes.DVD
};
db.Insert(qulityProfile);
foreach (var _seriesId in seriesIds)
2011-05-30 08:47:11 +02:00
{
int seriesId = _seriesId;
var series = Builder<Series>.CreateNew()
.With(s => s.SeriesId = seriesId)
.With(s => s.Monitored = true)
.Build();
2011-06-19 20:56:32 +02:00
db.Insert(series);
foreach (var _seasonNumber in seasonsNumbers)
{
for (int i = 1; i <= Episodes_Per_Season; i++)
{
var epFileId = 0;
if (i < 10)
{
var epFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.SeriesId = seriesId)
2011-06-19 20:56:32 +02:00
.And(e => e.SeasonNumber = _seasonNumber)
.And(e => e.Path = Guid.NewGuid().ToString())
.Build();
files.Add(epFile);
currentFileId++;
epFileId = currentFileId;
}
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.EpisodeFileId = epFileId)
.And(e => e.AirDate = DateTime.Today.AddDays(-20))
.Build();
episodes.Add(episode);
}
}
2011-06-05 08:02:31 +02:00
}
2011-06-19 20:56:32 +02:00
db.InsertMany(episodes);
db.InsertMany(files);
}
2011-05-30 08:47:11 +02:00
[Test]
2011-06-05 08:02:31 +02:00
public void get_episode_by_series_seasons_episode_x5000()
2011-05-30 08:47:11 +02:00
{
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(db);
Mocker.Resolve<SeriesProvider>();
2011-12-15 05:15:53 +01:00
var epProvider = Mocker.Resolve<EpisodeProvider>();
2011-05-30 08:47:11 +02:00
Thread.Sleep(1000);
var random = new Random();
Console.WriteLine("Starting Test");
2011-05-30 08:47:11 +02:00
var sw = Stopwatch.StartNew();
2011-06-05 08:02:31 +02:00
for (int i = 0; i < 5000; i++)
{
2011-06-19 20:56:32 +02:00
var ep = epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10));
ep.Series.Should().NotBeNull();
}
2011-05-30 08:47:11 +02:00
sw.Stop();
Console.WriteLine("Took " + sw.Elapsed);
2011-05-30 08:47:11 +02:00
}
[Test]
2011-06-05 08:02:31 +02:00
public void get_episode_by_series_seasons_x1000()
2011-05-30 08:47:11 +02:00
{
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(db);
Mocker.Resolve<SeriesProvider>();
2011-06-19 20:56:32 +02:00
2011-12-15 05:15:53 +01:00
var epProvider = Mocker.Resolve<EpisodeProvider>();
2011-05-30 08:47:11 +02:00
Thread.Sleep(1000);
var random = new Random();
Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew();
2011-06-05 08:02:31 +02:00
for (int i = 0; i < 1000; i++)
2011-05-30 08:47:11 +02:00
{
epProvider.GetEpisodesBySeason(6, random.Next(2, 5)).Should().NotBeNull();
2011-05-30 08:47:11 +02:00
}
2011-05-30 08:47:11 +02:00
sw.Stop();
Console.WriteLine("Took " + sw.Elapsed);
2011-05-30 08:47:11 +02:00
}
[Test]
2011-06-05 08:02:31 +02:00
public void get_episode_file_count_x100()
2011-05-30 08:47:11 +02:00
{
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(db);
Mocker.Resolve<SeriesProvider>();
Mocker.Resolve<EpisodeProvider>();
var mediaProvider = Mocker.Resolve<MediaFileProvider>();
2011-05-30 08:47:11 +02:00
Thread.Sleep(1000);
var random = new Random();
Console.WriteLine("Starting Test");
2011-05-30 08:47:11 +02:00
var sw = Stopwatch.StartNew();
2011-06-05 08:02:31 +02:00
for (int i = 0; i < 100; i++)
2011-05-30 08:47:11 +02:00
{
mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull();
2011-05-30 08:47:11 +02:00
}
2011-06-05 08:02:31 +02:00
sw.Stop();
Console.WriteLine("Took " + sw.Elapsed);
}
[Test]
2011-06-19 20:56:32 +02:00
public void get_episode_file_count_x1000()
2011-06-05 08:02:31 +02:00
{
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(db);
Mocker.Resolve<SeriesProvider>();
Mocker.Resolve<EpisodeProvider>();
var mediaProvider = Mocker.Resolve<MediaFileProvider>();
2011-06-05 08:02:31 +02:00
Thread.Sleep(1000);
var random = new Random();
Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew();
2011-06-19 20:56:32 +02:00
for (int i = 0; i < 1000; i++)
2011-06-05 08:02:31 +02:00
{
2011-06-19 20:56:32 +02:00
mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull();
2011-06-05 08:02:31 +02:00
}
2011-05-30 08:47:11 +02:00
sw.Stop();
Console.WriteLine("Took " + sw.Elapsed);
2011-05-30 08:47:11 +02:00
}
[Test]
2011-06-19 22:43:47 +02:00
public void get_season_count_x500()
{
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(db);
var provider = Mocker.Resolve<EpisodeProvider>();
Thread.Sleep(1000);
var random = new Random();
Console.WriteLine("Starting Test");
var sw = Stopwatch.StartNew();
2011-06-19 22:43:47 +02:00
for (int i = 0; i < 500; i++)
{
2011-06-19 20:56:32 +02:00
provider.GetSeasons(random.Next(1, 10)).Should().HaveSameCount(seasonsNumbers);
}
sw.Stop();
Console.WriteLine("Took " + sw.Elapsed);
}
2011-06-19 20:56:32 +02:00
2011-05-30 08:47:11 +02:00
}
}