private Task ProduceContactActionsAsync(TrackActionQuery query, ITargetBlock <Action[]> actionQueue) { return(ProduceParticipantActionsAsync( () => _searchServices.FindContactsAsync(query.ContactQuery), contacts => _searchServices.FindActionsByContactsAsync(query.ActionQuery, contacts), actionQueue, _batchOptions.Value.ContactActionsDatabaseSearchMaxDegreeOfParallelism ).Unwrap()); }
public async Task should_return_actions_by_contact_query() { var query = new TrackActionQuery { ContactQuery = new ContactQuery() }; ISearchServices searchServices = Substitute.For <ISearchServices>(); searchServices.FindContactsAsync(Arg.Any <ContactQuery>()).Returns(Task.FromResult(new[] { Task.FromResult(Enumerable.Range(0, 20).ToArray()), Task.FromResult(Enumerable.Range(20, 7).ToArray()) }.AsEnumerable())); searchServices.FindActionsByContactsAsync(Arg.Any <ActionQuery>(), Arg.Is <int[]>(contacts => contacts.Length == 15)).Returns(Task.FromResult(new[] { new Action(10, new DateTime(2001, 10, 2)), new Action(9, new DateTime(2001, 9, 2)) })); searchServices.FindActionsByContactsAsync(Arg.Any <ActionQuery>(), Arg.Is <int[]>(contacts => contacts.Length == 12)).Returns(Task.FromResult(new[] { new Action(1, new DateTime(2001, 1, 2)), new Action(4, new DateTime(2001, 4, 2)), new Action(5, new DateTime(2001, 5, 2)) })); TrackActionSearchService sut = new TrackActionSearchService(searchServices, Options.Create(new BatchProcessingConfig { BatchSize = 15 })); var actions = await sut.FindActionsAsync(query); actions.ShouldBeEqualTo(new[] { new Action(10, new DateTime(2001, 10, 2)), new Action(9, new DateTime(2001, 9, 2)), new Action(5, new DateTime(2001, 5, 2)), new Action(4, new DateTime(2001, 4, 2)), new Action(1, new DateTime(2001, 1, 2)) }); }
public async Task <Action[]> FindActionsByContactsAsync(ActionQuery query, int[] contacts) { var i = _counter++; Console.WriteLine($"[{_sw.Elapsed}] [{i}] FindActionsByContactsAsync invoking"); try { return(await _searchServices.FindActionsByContactsAsync(query, contacts)); } finally { Console.WriteLine($"[{_sw.Elapsed}] [{i}] FindActionsByContactsAsync invoked"); } }