Created
May 2, 2011 15:43
-
-
Save abolibibelot/951801 to your computer and use it in GitHub Desktop.
somedispatch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void RecordDispatchTest() | |
{ | |
var ads = new FlushingQueue<RecordModel> {Threshold = 2000}; | |
var noAds = new FlushingQueue<RecordModel> {Threshold = 2000}; | |
var rootDir = Directory.GetCurrentDirectory(); | |
ads.FilenameProvider = () => rootDir + "/ads_" + Guid.NewGuid() + "_ads.txt"; | |
noAds.FilenameProvider = () => rootDir + "/no_" + Guid.NewGuid() + "_noads.txt"; | |
var rnd = new Random(); | |
var records = (from i in Enumerable.Range(1, 100000) | |
let rand = rnd.NextDouble() | |
select new {Record = new RecordModel {Feature = rand < 0.25 ? "toto" : "Ads"}, Rand = rand }) | |
//.Do(z => Console.WriteLine(z.Rand)) | |
.Select(z => z.Record); | |
Action<RecordModel> adFilter = r => { if (r.Feature == "Ads") ads.Enqueue(r); }; | |
Action<RecordModel> noAdFilter = r => { if (r.Feature != "Ads") noAds.Enqueue(r); }; | |
records.DispatchTo(new[] {adFilter, noAdFilter}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment