public void ShouldBatchQueriesToSolr() { List <long[]> hashes = new List <long[]>(); const int FingerprintsCount = 256; for (int i = 0; i < FingerprintsCount; ++i) { hashes.Add(new long[25]); } List <int> batchSizes = new List <int>(); solrQueryBuilder.Setup(bld => bld.BuildReadQueryForHashesAndThreshold(It.IsAny <IEnumerable <long[]> >(), 5)) .Returns("query") .Callback((IEnumerable <long[]> h, int t) => batchSizes.Add(h.Count())); solr.Setup(opr => opr.Query(It.IsAny <SolrQuery>(), It.IsAny <QueryOptions>())).Returns(new SolrQueryResults <SubFingerprintDTO>()); var allResults = subFingerprintDao.ReadSubFingerprints(hashes, 5, new string[0]); CollectionAssert.AreEqual( new List <int> { SubFingerprintDao.BatchSize, SubFingerprintDao.BatchSize, FingerprintsCount % SubFingerprintDao.BatchSize }, batchSizes); }
public void ReadByTrackGroupIdWorksAsExpectedTest() { var firstTrack = new TrackData(string.Empty, "first-artist", "title", "album", 1986, 197d); var secondTrack = new TrackData(string.Empty, "second-artist", "title", "album", 1986, 197d); var firstTrackReference = trackDao.InsertTrack(firstTrack); var secondTrackReference = trackDao.InsertTrack(secondTrack); var hashedFingerprintsForFirstTrack = HashFingerprintsForTrack( firstTrackReference, new[] { "first-group-id" }); var hashedFingerprintsForSecondTrack = HashFingerprintsForTrack( secondTrackReference, new[] { "second-group-id" }); const int ThresholdVotes = 25; foreach (var hashedFingerprint in hashedFingerprintsForFirstTrack) { var subFingerprintData = subFingerprintDao.ReadSubFingerprints( hashedFingerprint.HashBins, ThresholdVotes, new[] { "first-group-id" }).ToList(); Assert.AreEqual(1, subFingerprintData.Count); Assert.AreEqual(firstTrackReference, subFingerprintData[0].TrackReference); subFingerprintData = subFingerprintDao.ReadSubFingerprints( hashedFingerprint.HashBins, ThresholdVotes, new[] { "second-group-id" }).ToList(); Assert.AreEqual(1, subFingerprintData.Count); Assert.AreEqual(secondTrackReference, subFingerprintData[0].TrackReference); subFingerprintData = subFingerprintDao.ReadSubFingerprints( hashedFingerprint.HashBins, ThresholdVotes, new[] { "first-group-id", "second-group-id", "third-group-id" }).ToList(); Assert.AreEqual(2, subFingerprintData.Count); } }
public void ReadByTrackGroupIdWorksAsExpectedTest() { var firstTrack = new TrackInfo("isrc1", "title", "artist", new Dictionary <string, string> { { "group-id", "first-group-id" } }); var secondTrack = new TrackInfo("isrc2", "title", "artist", new Dictionary <string, string> { { "group-id", "second-group-id" } }); var firstTrackData = trackDao.InsertTrack(firstTrack, 120d); var secondTrackData = trackDao.InsertTrack(secondTrack, 120d); var hashedFingerprintsForFirstTrack = fingerprintCommandBuilder .BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(audioService) .Hash() .Result; //.OrderBy(e => e.StartsAt); InsertHashedFingerprintsForTrack(hashedFingerprintsForFirstTrack.Audio, firstTrackData.TrackReference); var hashedFingerprintsForSecondTrack = fingerprintCommandBuilder .BuildFingerprintCommand() .From(GetAudioSamples()) .UsingServices(audioService) .Hash() .Result; //.OrderBy(e => e.StartsAt); InsertHashedFingerprintsForTrack(hashedFingerprintsForSecondTrack.Audio, secondTrackData.TrackReference); const int thresholdVotes = 25; foreach (var hashedFingerprint in hashedFingerprintsForFirstTrack.Audio) { var subFingerprintData = subFingerprintDao.ReadSubFingerprints( new[] { hashedFingerprint.HashBins }, new DefaultQueryConfiguration { ThresholdVotes = thresholdVotes, YesMetaFieldsFilters = firstTrack.MetaFields }).ToList(); subFingerprintData.Count.Should().Be(1); firstTrackData.TrackReference.Get <ulong>().Should().Be(subFingerprintData[0].TrackReference.Get <ulong>()); subFingerprintData = subFingerprintDao.ReadSubFingerprints( new[] { hashedFingerprint.HashBins }, new DefaultQueryConfiguration { ThresholdVotes = thresholdVotes, YesMetaFieldsFilters = secondTrack.MetaFields }).ToList(); subFingerprintData.Count.Should().Be(1); secondTrackData.TrackReference.Get <ulong>().Should().Be(subFingerprintData[0].TrackReference.Get <ulong>()); subFingerprintData = subFingerprintDao.ReadSubFingerprints( new[] { hashedFingerprint.HashBins }, new DefaultQueryConfiguration { ThresholdVotes = thresholdVotes }).ToList(); subFingerprintData.Count.Should().Be(2); } }