public void CanRunQueueJob() { const int workItemCount = 10000; var metrics = new InMemoryMetricsClient(); var queue = new RedisQueue<SampleQueueWorkItem>(SharedConnection.GetMuxer(), null, null, 0, TimeSpan.Zero); queue.AttachBehavior(new MetricsQueueBehavior<SampleQueueWorkItem>(metrics, "test")); metrics.StartDisplayingStats(TimeSpan.FromMilliseconds(100), _writer); Task.Factory.StartNew(() => { Parallel.For(0, workItemCount, i => { queue.Enqueue(new SampleQueueWorkItem { Created = DateTime.Now, Path = "somepath" + i }); }); }); var job = new SampleQueueJob(queue, metrics); job.RunUntilEmpty(); metrics.DisplayStats(_writer); Assert.Equal(0, queue.GetQueueStats().Queued); }
public void CanRunQueueJob() { const int workItemCount = 10000; var metrics = new InMemoryMetricsClient(); var queue = new RedisQueue <SampleQueueWorkItem>(SharedConnection.GetMuxer(), null, null, 0, TimeSpan.Zero, metrics: metrics); Task.Factory.StartNew(() => { Parallel.For(0, workItemCount, i => { queue.Enqueue(new SampleQueueWorkItem { Created = DateTime.Now, Path = "somepath" + i }); }); }); var job = new SampleQueueJob(queue, metrics); job.RunUntilEmpty(); metrics.DisplayStats(); Assert.Equal(0, queue.GetQueueCount()); }
public override IServiceProvider Bootstrap() { var container = new Container(); container.Options.AllowOverridingRegistrations = true; container.Register<IAmADependency, MyDependency>(); var muxer = ConnectionMultiplexer.Connect("localhost"); container.RegisterSingleton(muxer); var q1 = new RedisQueue<PingRequest>(muxer); var q2 = new RedisQueue<PingRequest>(muxer); container.RegisterSingleton<IQueue<PingRequest>>(() => q2); Task.Run(() => { var startDate = DateTime.Now; while (startDate.AddSeconds(30) > DateTime.Now) { Console.WriteLine("Enqueueing ping."); q1.Enqueue(new PingRequest {Data = "Hi"}); Thread.Sleep(RandomData.GetInt(100, 1000)); } }); return container; }