public void TestRemoveJob() { //Add ta1 and ta2 TestAddJob2(); //Remove ta1 ITradeActivityItem item = jsm.RemoveJob(2); Assert.IsTrue(object.ReferenceEquals(item, ta1), "The removed instance must be same as ta1"); //Check if item was removed from all indices correctly. Assert.IsNull(jsm.GetJobByQueueID(2), "Wrong RemoveJob implementation."); Assert.AreEqual(1, jsm.GetJobsByServiceID(3).Count, "Wrong RemoveJob implementation."); Assert.AreEqual(1, jsm.GetJobsByStatus(JobStatus.Queued).Count, "Wrong RemoveJob implementation."); Assert.AreEqual( 1, jsm.GetJobsByStatusAndServiceID(JobStatus.Queued, 3).Count, "Wrong RemoveJob implementation."); //Try to Remove ta1 again item = jsm.RemoveJob(2); Assert.IsNull(item, "Must return null if job with given queueId is not present."); //Remove ta2 item = jsm.RemoveJob(3); Assert.IsTrue(object.ReferenceEquals(item, ta2), "The removed instance must be same as ta1"); //Check if item was removed from all indices correctly. Assert.IsNull(jsm.GetJobByQueueID(3), "Wrong RemoveJob implementation."); Assert.AreEqual(0, jsm.GetJobsByServiceID(3).Count, "Wrong RemoveJob implementation."); Assert.AreEqual(0, jsm.GetJobsByStatus(JobStatus.Queued).Count, "Wrong RemoveJob implementation."); Assert.AreEqual( 0, jsm.GetJobsByStatusAndServiceID(JobStatus.Queued, 3).Count, "Wrong RemoveJob implementation."); //Try to Remove ta2 again item = jsm.RemoveJob(3); Assert.IsNull(item, "Must return null if job with given queueId is not present."); }
public void TestDemo() { //Base operations // create JobStatusManager JobStatusManager jobManager = new JobStatusManager(); // add job jobManager.AddJob(job1); // Remove job jobManager.RemoveJob(job1.QueueID); // add a list of jobs jobManager.AddJobs(list); // Remove a list of jobs jobManager.RemoveJobs(list); //Get data for various criteria // get concrete job (QueueID is unique job identifier) ITradeActivityItem item1 = jobManager.GetJobByQueueID(2); // Get count of jobs with given status int jobsCount1 = jobManager.GetJobCountByStatus(JobStatus.Queued); // get jobs with given status ReadOnlyCollection <ITradeActivityItem> jobs2 = jobManager.GetJobsByStatus(JobStatus.Queued); // get jobs for given service ReadOnlyCollection <ITradeActivityItem> jobs3 = jobManager.GetJobsByServiceID(3); // Get count of jobs with given status for given service int jobCount2 = jobManager.GetJobCountByStatusServiceID(JobStatus.Queued, 3); // get jobs for given service and with given status ReadOnlyCollection <ITradeActivityItem> jobs4 = jobManager.GetJobsByStatusAndServiceID(JobStatus.Queued, 3); // get jobs for given service and with JobStatus.Queued status ReadOnlyCollection <ITradeActivityItem> jobs5 = jobManager.GetJobsForDispatch(3); // we can get exclusive access to JobStatusManager to execute not thread safe operations lock (jobManager.SyncRoot) { foreach (ITradeActivityItem job in jobs4) { Console.WriteLine(job.QueueID); } } //Monitor jobs for given criteria //The application can get read only wrapper for given condition once and uses it many times. //The wrapper provides read only access to collection of jobs for given criteria. // get jobs for dispatch once ReadOnlyCollection <ITradeActivityItem> jobs = jobManager.GetJobsForDispatch(3); // call by timer for example foreach (ITradeActivityItem job in jobs) { // process job } }