Stop() 공개 메소드

Stops the worker.
public Stop ( bool force ) : void
force bool A value indicating whether to force the worker to stop, even if work will be abandoned.
리턴 void
예제 #1
0
        public void WorkerDispose()
        {
            IJob job = new TestJob() { Id = Guid.NewGuid() };
            SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None };

            QueueRecord queued = new QueueRecord()
            {
                Id = 12,
                ApplicationName = BlueCollarSection.Section.ApplicationName,
                Data = JsonConvert.SerializeObject(job),
                JobName = job.Name,
                JobType = JobSerializer.GetTypeName(job.GetType()),
                QueuedOn = DateTime.UtcNow,
                QueueName = "*",
                TryNumber = 1
            };

            var transaction = new Mock<IDbTransaction>();

            var repository = new Mock<IRepository>();
            repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object);
            repository.Setup(r => r.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(transaction.Object);
            repository.Setup(r => r.GetQueued(It.IsAny<string>(), It.IsAny<QueueNameFilters>(), It.IsAny<DateTime>(), It.IsAny<IDbTransaction>())).Returns(queued);
            repository.Setup(r => r.GetWorkingSignals(It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<IDbTransaction>())).Returns(signals);

            var factory = new Mock<IRepositoryFactory>();
            factory.Setup(f => f.Create()).Returns(repository.Object);

            var logger = new Mock<ILogger>();
            Worker worker = null;

            try
            {
                worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object);
                worker.Start();
                Thread.Sleep(1500);
                worker.Stop(false);
                worker.Dispose();

                Assert.IsFalse(worker.LoopThreadsAreAlive);
                worker = null;
            }
            finally
            {
                if (worker != null)
                {
                    worker.Dispose();
                }
            }
        }
예제 #2
0
        public void WorkerStop()
        {
            var transaction = new Mock<IDbTransaction>();
            var repository = new Mock<IRepository>();
            repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object);
            repository.Setup(r => r.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(transaction.Object);
            var factory = new Mock<IRepositoryFactory>();
            factory.Setup(f => f.Create()).Returns(repository.Object);
            var logger = new Mock<ILogger>();

            using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", null, 1, false, factory.Object, logger.Object))
            {
                worker.Start();
                worker.Stop(false);
                Thread.Sleep(1);
                Assert.AreEqual(WorkerStatus.Stopped, worker.Status);
            }
        }