public void Can_list_tubes() { _mockSocket.Expect("list-tubes\r\n", "OK 23\r\n---\r\n- default\r\n- other\r\n"); var tubes = _client.GetTubes(); _mockSocket.Verify(); Assert.AreEqual(new[] { "default", "other" }, tubes.OrderBy(x => x).ToArray()); }
public void Producer_consumer_load_test_runs_forever() { var pool = ConnectionPool.GetPool(TestConfig.Host, TestConfig.Port); var tube = "forever-" + Guid.NewGuid().ToString(); Console.WriteLine("using tube: {0}", tube); var set = 0; while(true) { set++; var produced = new List<string>(); var consumed = new List<string>(); var n = 10000; var producerTimer = new Stopwatch(); var producer = new Thread(() => { using(var producerClient = new BeanstalkClient(pool)) { producerClient.CurrentTube = tube; producerTimer.Start(); for(var i = 0; i < n; i++) { var data = Guid.NewGuid().ToString(); produced.Add(data); producerClient.PutString(data); } producerTimer.Stop(); } }); producer.Start(); Thread.Sleep(1000); var consumerTimer = new Stopwatch(); using(var consumerClient = new BeanstalkClient(pool)) { consumerClient.WatchedTubes.Add(tube); consumerClient.WatchedTubes.Remove(BeanstalkClient.DEFAULT_TUBE); consumerTimer.Start(); while(consumed.Count < n) { var job = consumerClient.ReserveString(TimeSpan.Zero); consumed.Add(job.Data); consumerClient.Delete(job.JobId); } consumerTimer.Stop(); } producer.Join(); Assert.AreEqual(n, produced.Count, "wrong number of produced items"); Assert.AreEqual(n, consumed.Count, "wrong number of consumed items"); Assert.AreEqual(produced.OrderBy(x => x).ToArray(), consumed.OrderBy(x => x).ToArray()); Console.WriteLine("set {0} enqueue/dequeue: {1:0}/{2:0} items/sec", set, n / producerTimer.Elapsed.TotalSeconds, n / consumerTimer.Elapsed.TotalSeconds ); using(var client = new BeanstalkClient(pool)) { foreach(var t in client.GetTubes()) { var tubeStats = client.GetTubeStats(t); Console.WriteLine("{0}:total:{1}/buried:{2}/delayed:{3}/ready:{4}/reserved:{5}/urgent:{6}/waiting:{7}", tubeStats.Name, tubeStats.TotalJobs, tubeStats.CurrentBuriedJobs, tubeStats.CurrentDelayedJobs, tubeStats.CurrentReadyJobs, tubeStats.CurrentReservedJobs, tubeStats.CurrentUrgentJobs, tubeStats.CurrentWaiting ); } } } }
public void Producer_consumer_load_test_runs_forever() { var pool = ConnectionPool.GetPool(TestConfig.Host, TestConfig.Port); var tube = "forever-" + Guid.NewGuid().ToString(); Console.WriteLine("using tube: {0}", tube); var set = 0; while (true) { set++; var produced = new List <string>(); var consumed = new List <string>(); var n = 10000; var producerTimer = new Stopwatch(); var producer = new Thread(() => { using (var producerClient = new BeanstalkClient(pool)) { producerClient.CurrentTube = tube; producerTimer.Start(); for (var i = 0; i < n; i++) { var data = Guid.NewGuid().ToString(); produced.Add(data); producerClient.PutString(data); } producerTimer.Stop(); } }); producer.Start(); Thread.Sleep(1000); var consumerTimer = new Stopwatch(); using (var consumerClient = new BeanstalkClient(pool)) { consumerClient.WatchedTubes.Add(tube); consumerClient.WatchedTubes.Remove(BeanstalkClient.DEFAULT_TUBE); consumerTimer.Start(); while (consumed.Count < n) { var job = consumerClient.ReserveString(TimeSpan.Zero); consumed.Add(job.Data); consumerClient.Delete(job.JobId); } consumerTimer.Stop(); } producer.Join(); Assert.AreEqual(n, produced.Count, "wrong number of produced items"); Assert.AreEqual(n, consumed.Count, "wrong number of consumed items"); Assert.AreEqual(produced.OrderBy(x => x).ToArray(), consumed.OrderBy(x => x).ToArray()); Console.WriteLine("set {0} enqueue/dequeue: {1:0}/{2:0} items/sec", set, n / producerTimer.Elapsed.TotalSeconds, n / consumerTimer.Elapsed.TotalSeconds ); using (var client = new BeanstalkClient(pool)) { foreach (var t in client.GetTubes()) { var tubeStats = client.GetTubeStats(t); Console.WriteLine("{0}:total:{1}/buried:{2}/delayed:{3}/ready:{4}/reserved:{5}/urgent:{6}/waiting:{7}", tubeStats.Name, tubeStats.TotalJobs, tubeStats.CurrentBuriedJobs, tubeStats.CurrentDelayedJobs, tubeStats.CurrentReadyJobs, tubeStats.CurrentReservedJobs, tubeStats.CurrentUrgentJobs, tubeStats.CurrentWaiting ); } } } }