コード例 #1
0
        public void ProducerConcumerTest()
        {
            using (var client = new BeanstalkdClient(BeanstalkdHost))
            {
                Assert.AreEqual(TestTube, client.Use(TestTube));
                Assert.AreEqual(TestTube, client.CurrentTube);
                Assert.AreEqual(2, client.Watch(TestTube));
                Assert.True(client.Ignore("default"));

                Job job;
                Assert.AreEqual(ReserveStatus.Timeout, client.Reserve(0, out job));
                Assert.Less(0, client.Put(new byte[] { 97 }));
                Assert.AreEqual(1, client.StatsTube(TestTube).CurrentJobsReady);
                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(0, out job));
                Assert.AreEqual(97, job.Data[0]);
                Assert.AreEqual(1, client.StatsTube(TestTube).CurrentJobsReserved);
                Assert.AreEqual(JobStatus.Reserved, client.StatsJob(job.JobId).Status);
                Assert.True(client.Delete(job.JobId));

                Assert.AreEqual(0, client.StatsTube(TestTube).CurrentJobsReserved);
                Assert.AreEqual(0, client.StatsTube(TestTube).CurrentJobsReady);

                Assert.Less(0, client.Stats().ConnectionCount);
            }
        }
コード例 #2
0
        public void PeekTest()
        {
            using (var client = new BeanstalkdClient(BeanstalkdHost))
            {
                Assert.AreEqual(TestTube, client.Use(TestTube));
                Assert.AreEqual(TestTube, client.CurrentTube);
                Assert.AreEqual(2, client.Watch(TestTube));
                Assert.True(client.Ignore("default"));

                Assert.Less(0, client.Put(new byte[] { 97 }));
                Assert.AreEqual(1, client.StatsTube(TestTube).CurrentJobsReady);

                var job = client.PeekReady();
                Assert.NotNull(job);
                var jobId = job.JobId;
                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(out job));
                Assert.AreEqual(jobId, job.JobId);
                Assert.Null(client.PeekReady());
                Assert.True(client.Release(jobId, delay: 1));
                Assert.NotNull(client.PeekDelayed());
                Assert.AreEqual(jobId, client.PeekDelayed().JobId);

                Thread.Sleep(1500);

                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(out job));
                Assert.True(client.Bury(jobId));
                Assert.NotNull(client.PeekBuried());
                Assert.AreEqual(jobId, client.PeekBuried().JobId);

                Assert.AreEqual(1, client.Kick(1));
                Assert.NotNull(client.Peek(jobId));
                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(out job));
                Assert.True(client.Delete(job.JobId));
            }
        }
コード例 #3
0
        public void BuryTest()
        {
            using (var client = new BeanstalkdClient(BeanstalkdHost))
            {
                Assert.AreEqual(TestTube, client.Use(TestTube));
                Assert.AreEqual(TestTube, client.CurrentTube);
                Assert.AreEqual(2, client.Watch(TestTube));
                Assert.True(client.Ignore("default"));

                Assert.Less(0, client.Put(new byte[] { 97 }));
                Assert.AreEqual(1, client.StatsTube(TestTube).CurrentJobsReady);

                Job job;
                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(0, out job));
                Assert.True(client.Bury(job.JobId));

                Assert.AreEqual(JobStatus.Buried, client.StatsJob(job.JobId).Status);
                Assert.AreEqual(1, client.Kick(1));

                Assert.AreEqual(JobStatus.Ready, client.StatsJob(job.JobId).Status);

                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(0, out job));
                Assert.True(client.Delete(job.JobId));
            }
        }
コード例 #4
0
 public DefaultClientTest()
 {
     LogProvider.Current.Register((level, msg) => Console.WriteLine("[{0}] {1}", level, msg));
     using (var client = new BeanstalkdClient(BeanstalkdHost))
     {
         client.Watch(TestTube);
         client.Ignore("default");
         Job job;
         while (ReserveStatus.Reserved == client.Reserve(0, out job))
         {
             client.Delete(job.JobId);
         }
     }
 }
コード例 #5
0
 public JobBulkProducerTest()
 {
     LogProvider.Current.Register((level, msg) => Console.WriteLine("[{0}] {1}", level, msg));
     try
     {
         using (var client = new BeanstalkdClient(BeanstalkdHost))
         {
             client.Watch(TestTube);
             client.Ignore("default");
             Job job;
             while (ReserveStatus.Reserved == client.Reserve(0, out job))
             {
                 client.Delete(job.JobId);
             }
         }
     }
     catch (BeanstalkdException ex)
     {
         Console.WriteLine("Beanstalk error: {0}.", ex.Code);
     }
 }
コード例 #6
0
        public void DelayTest()
        {
            using (var client = new BeanstalkdClient(BeanstalkdHost))
            {
                Assert.AreEqual(TestTube, client.Use(TestTube));
                Assert.AreEqual(TestTube, client.CurrentTube);
                Assert.AreEqual(2, client.Watch(TestTube));
                Assert.True(client.Ignore("default"));

                Assert.Less(0, client.Put(new byte[] { 97 }, delay: 1));
                Assert.AreEqual(0, client.StatsTube(TestTube).CurrentJobsReady);

                Job job;
                Assert.AreEqual(ReserveStatus.Timeout, client.Reserve(0, out job));
                Thread.Sleep(1500);
                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(0, out job));
                Assert.AreEqual(97, job.Data[0]);
                Assert.AreEqual(JobStatus.Reserved, client.StatsJob(job.JobId).Status);
                Assert.True(client.Delete(job.JobId));
            }
        }
コード例 #7
0
        public void TouchTest()
        {
            using (var client = new BeanstalkdClient(BeanstalkdHost))
            {
                Assert.AreEqual(TestTube, client.Use(TestTube));
                Assert.AreEqual(TestTube, client.CurrentTube);
                Assert.AreEqual(2, client.Watch(TestTube));
                Assert.True(client.Ignore("default"));

                Job job;
                Assert.Less(0, client.Put(new byte[] { 97 }, ttr: 3));
                Assert.AreEqual(ReserveStatus.Reserved, client.Reserve(out job));
                var jobId = job.JobId;
                Thread.Sleep(2500);
                var timeLeft = client.StatsJob(jobId).TimeLeft;
                Assert.Greater(2, timeLeft);
                Assert.True(client.Touch(jobId));
                Assert.Less(timeLeft, client.StatsJob(jobId).TimeLeft);
                Assert.True(client.Delete(jobId));
            }
        }