Now generating unique ids for queue items sent to the api.
This commit is contained in:
parent
3c145c63f4
commit
c19a393f99
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Common.Crypto
|
||||
{
|
||||
public static class HashConverter
|
||||
{
|
||||
private static SHA1 HashAlgorithm = SHA1.Create();
|
||||
|
||||
public static int GetHashInt31(string target)
|
||||
{
|
||||
var hash = HashAlgorithm.ComputeHash(Encoding.Default.GetBytes(target));
|
||||
|
||||
return BitConverter.ToInt32(hash, 0) & 0x7fffffff;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -132,6 +132,7 @@
|
|||
<Compile Include="Expansive\TreeNodeList.cs" />
|
||||
<Compile Include="Extensions\Base64Extentions.cs" />
|
||||
<Compile Include="Extensions\DateTimeExtensions.cs" />
|
||||
<Compile Include="Crypto\HashConverter.cs" />
|
||||
<Compile Include="Extensions\Int64Extensions.cs" />
|
||||
<Compile Include="Extensions\StreamExtensions.cs" />
|
||||
<Compile Include="Extensions\XmlExtentions.cs" />
|
||||
|
|
|
@ -236,6 +236,7 @@
|
|||
<Compile Include="OrganizerTests\FileNameBuilderTests\MultiEpisodeFixture.cs" />
|
||||
<Compile Include="ParserTests\MiniSeriesEpisodeParserFixture.cs" />
|
||||
<Compile Include="Qualities\RevisionComparableFixture.cs" />
|
||||
<Compile Include="QueueTests\QueueServiceFixture.cs" />
|
||||
<Compile Include="RemotePathMappingsTests\RemotePathMappingServiceFixture.cs" />
|
||||
<Compile Include="OrganizerTests\CleanFixture.cs" />
|
||||
<Compile Include="MediaFiles\MediaFileServiceTests\FilterFixture.cs" />
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.Queue;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Test.QueueTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class QueueServiceFixture : CoreTest<QueueService>
|
||||
{
|
||||
private List<TrackedDownload> _trackedDownloads;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
var downloadItem = Builder<NzbDrone.Core.Download.DownloadClientItem>.CreateNew()
|
||||
.With(v => v.RemainingTime = TimeSpan.FromSeconds(10))
|
||||
.Build();
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(3)
|
||||
.All()
|
||||
.With(e => e.SeriesId = series.Id)
|
||||
.Build();
|
||||
|
||||
var remoteEpisode = Builder<RemoteEpisode>.CreateNew()
|
||||
.With(r => r.Series = series)
|
||||
.With(r => r.Episodes = new List<Episode>(episodes))
|
||||
.With(r => r.ParsedEpisodeInfo = new ParsedEpisodeInfo())
|
||||
.Build();
|
||||
|
||||
_trackedDownloads = Builder<TrackedDownload>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(v => v.DownloadItem = downloadItem)
|
||||
.With(v => v.RemoteEpisode = remoteEpisode)
|
||||
.Build()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void queue_items_should_have_id()
|
||||
{
|
||||
Subject.Handle(new TrackedDownloadRefreshedEvent(_trackedDownloads));
|
||||
|
||||
var queue = Subject.GetQueue();
|
||||
|
||||
queue.Should().HaveCount(3);
|
||||
|
||||
queue.All(v => v.Id > 0).Should().BeTrue();
|
||||
|
||||
var distinct = queue.Select(v => v.Id).Distinct().ToArray();
|
||||
|
||||
distinct.Should().HaveCount(3);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Crypto;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
|
@ -101,7 +102,7 @@ namespace NzbDrone.Core.Download.Pending
|
|||
|
||||
var queue = new Queue.Queue
|
||||
{
|
||||
Id = episode.Id ^ (pendingRelease.Id << 16),
|
||||
Id = HashConverter.GetHashInt31(string.Format("pending-{0}-ep{1}", pendingRelease.Id, episode.Id)),
|
||||
Series = pendingRelease.RemoteEpisode.Series,
|
||||
Episode = episode,
|
||||
Quality = pendingRelease.RemoteEpisode.ParsedEpisodeInfo.Quality,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Crypto;
|
||||
using NzbDrone.Core.Download.TrackedDownloads;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
|
@ -40,13 +41,13 @@ namespace NzbDrone.Core.Queue
|
|||
_eventAggregator.PublishEvent(new QueueUpdatedEvent());
|
||||
}
|
||||
|
||||
private static IEnumerable<Queue> MapQueue(TrackedDownload trackedDownload)
|
||||
private IEnumerable<Queue> MapQueue(TrackedDownload trackedDownload)
|
||||
{
|
||||
foreach (var episode in trackedDownload.RemoteEpisode.Episodes)
|
||||
{
|
||||
var queue = new Queue
|
||||
{
|
||||
Id = episode.Id ^ (trackedDownload.DownloadItem.DownloadId.GetHashCode() << 16),
|
||||
Id = HashConverter.GetHashInt31(string.Format("trackedDownload-{0}-ep{1}", trackedDownload.DownloadItem.DownloadId, episode.Id)),
|
||||
Series = trackedDownload.RemoteEpisode.Series,
|
||||
Episode = episode,
|
||||
Quality = trackedDownload.RemoteEpisode.ParsedEpisodeInfo.Quality,
|
||||
|
|
Loading…
Reference in New Issue