public void verify_job_filter_by_custom_properties() { QueueHandler sut = CreateAGenericJob(new QueueInfo("test", "tika", ""), customData: new Dictionary <String, Object>() { { "foo", 6 }, { "bar", "test" }, }); HandleStreamToCreateJob(sut, customData: new Dictionary <String, Object>() { { "foo", 42 }, { "bar", "the ultimate answer" }, }); var nextJob = sut.GetNextJob("identity", "handle", null, new Dictionary <string, Object>() { { "notexisting", 11 } }); Assert.That(nextJob, Is.Null); nextJob = sut.GetNextJob("identity", "handle", null, new Dictionary <string, Object>() { { "foo", 42 } }); Assert.That(nextJob.HandleCustomData["bar"], Is.EqualTo("the ultimate answer")); nextJob = sut.GetNextJob("identity", "handle", null, new Dictionary <string, Object>() { { "foo", 6 } }); Assert.That(nextJob.HandleCustomData["bar"], Is.EqualTo("test")); }
public void verify_max_number_of_falure() { var info = new QueueInfo("test", "tika", ""); info.MaxNumberOfFailure = 2; QueueHandler sut = CreateAGenericJob(info); var nextJob = sut.GetNextJob("", "handle", null, null); Assert.That(nextJob, Is.Not.Null); var jobId = nextJob.Id; sut.SetJobExecuted(nextJob.Id, "Error 42", null); nextJob = sut.GetNextJob("", "handle", null, null); Assert.That(nextJob, Is.Not.Null); sut.SetJobExecuted(nextJob.Id, "Error 42", null); nextJob = sut.GetNextJob("", "handle", null, null); Assert.That(nextJob, Is.Null, "After two failure the job should not be returned anymore"); var collection = _db.GetCollection <QueuedJob>("queue.test"); var job = collection.Find(Builders <QueuedJob> .Filter.Eq(j => j.Id, jobId)).SingleOrDefault(); Assert.That(job.ExecutionError, Is.EqualTo("Error 42")); Assert.That(job.ErrorCount, Is.EqualTo(2)); Assert.That(job.Status, Is.EqualTo(QueuedJobExecutionStatus.Failed)); }
public void Verify_job_filter_by_job_properties() { var info = new QueueInfo("test", "tika", ""); QueueHandler sut = GetSut(info); var job1 = HandleStreamToCreateJob(sut, fileName: "pippo.xlsx"); var job2 = HandleStreamToCreateJob(sut, fileName: "pippo.docx"); var nextJob = sut.GetNextJob( "identity", "handle", null, new Dictionary <string, object>() { ["file_ext"] = "pptx" }); Assert.That(nextJob, Is.Null); nextJob = sut.GetNextJob( "identity", "handle", null, new Dictionary <string, object>() { ["file_ext"] = "docx" }); Assert.That(nextJob, Is.Not.Null); Assert.That(nextJob.Id, Is.EqualTo(job2)); }
public void verify_get_next_job_not_give_executing_job() { QueueHandler sut = CreateAGenericJob(new QueueInfo("test", "tika", "")); var nextJob = sut.GetNextJob("", "handle", null, null); Assert.That(nextJob, Is.Not.Null); nextJob = sut.GetNextJob("", "handle", null, null); Assert.That(nextJob, Is.Null); }
public void verify_job_filter_by_tenant_id() { var none = new TenantId("tenant_none"); var foo = new TenantId("tenant_foo"); var bar = new TenantId("tenant_bar"); QueueHandler sut = CreateAGenericJob(new QueueInfo("test", "tika", ""), tenant: foo); HandleStreamToCreateJob(sut, bar); var nextJob = sut.GetNextJob("identity", "handle", none, null); Assert.That(nextJob, Is.Null); nextJob = sut.GetNextJob("identity", "handle", bar, null); Assert.That(nextJob.TenantId, Is.EqualTo(bar)); nextJob = sut.GetNextJob("identity", "handle", foo, null); Assert.That(nextJob.TenantId, Is.EqualTo(foo)); }
public void verify_not_duplicate_jobs_on_same_blob_id() { QueueHandler sut = CreateAGenericJob(new QueueInfo("test", "tika", "")); var nextJob = sut.GetNextJob("identity", "handle", null, null); var collection = _db.GetCollection <QueuedJob>("queue.test"); var job = collection.Find(Builders <QueuedJob> .Filter.Eq(j => j.Id, nextJob.Id)).SingleOrDefault(); Assert.That(job.ExecutingIdentity, Is.EqualTo("identity")); }
public void verify_job_is_generated_with_custom_parameters() { var info = new QueueInfo("test", "tika", ""); info.Parameters = new Dictionary <string, string>() { { "Custom", "CustomValue" } }; QueueHandler sut = CreateAGenericJob(info); var nextJob = sut.GetNextJob("", "handle", null, null); Assert.That(nextJob.Parameters["Custom"], Is.EqualTo("CustomValue")); }
public void verify_set_error_status() { var info = new QueueInfo("test", "tika", ""); info.MaxNumberOfFailure = 2; QueueHandler sut = CreateAGenericJob(info); var nextJob = sut.GetNextJob("", "handle", null, null); sut.SetJobExecuted(nextJob.Id, "Error 42", null); var collection = _db.GetCollection <QueuedJob>("queue.test"); var job = collection.Find(Builders <QueuedJob> .Filter.Eq(j => j.Id, nextJob.Id)).SingleOrDefault(); Assert.That(job.ExecutionError, Is.EqualTo("Error 42")); Assert.That(job.ErrorCount, Is.EqualTo(1)); Assert.That(job.Status, Is.EqualTo(QueuedJobExecutionStatus.ReQueued)); }