public void JobQueueManager_Can_Mark_Failure() { var testStore = new InMemoryTestStore(); var actor = Sys.ActorOf(Props.Create(() => new JobQueueLayerActor(new InMemoryTestStore()))); var jobInfo = JobCreator.Create((MockJob m) => m.MockMethod()); var myGuid = testStore.AddJob((MockJob m) => m.MockMethod(), null, null, "test"); var ourJob = InMemoryTestStore.jobPeeker["test"].FirstOrDefault(q => q.JobId == myGuid); actor.Tell(new MarkJobFailed(myGuid)); System.Threading.SpinWait.SpinUntil(() => false, TimeSpan.FromSeconds(2)); Xunit.Assert.Equal(JobStates.Failed, ourJob.Status); }
private static Timer StartSampleJobTimer(InMemoryTestStore store) { return(new Timer( (state) => { var counter = CounterClass.Counter; CounterClass.Counter = counter + 1; var counterString = counter.ToString(); store.AddJob((SampleJob job) => job.WriteSomething(counterString, DateTime.Now.ToString()), queueName: "sample"); }, null, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2))); }
public void JobExecutorShell_Will_Execute_Jobs() { var queueName = QueueNameHelper.CreateQueueName(); var jobStore = new InMemoryTestStore(); var executor = new HardInjectedJobExecutorShell <JobQueueLayerActor, JobWorkerActor, JobQueueCoordinator>(() => new JobQueueLayerActor(jobStore), () => new JobWorkerActor(new DefaultJobExecutor(new DefaultContainerFactory())), () => new JobQueueCoordinator(), null); executor.StartJobQueue(queueName, 5, 1, 1); jobStore.AddJob((ShellMockJob m) => m.DoThing(0), null, null, queueName); SpinWait.SpinUntil(() => false, TimeSpan.FromSeconds(8)); Xunit.Assert.Equal(1, ShellMockJob.MyCounter); }
public void JobQueueManager_Can_Get_Jobs() { var testStore = new InMemoryTestStore(); var actor = Sys.ActorOf(Props.Create(() => new JobQueueLayerActor(new InMemoryTestStore()))); var myGuid = testStore.AddJob((MockJob m) => m.MockMethod(), null, null, "test"); InMemoryTestStore.jobPeeker["test"].FirstOrDefault(q => q.JobId == myGuid); actor.Tell(new GetJobs("test", 10)); ExpectMsg <IEnumerable <IOddJobWithMetadata> >(duration: TimeSpan.FromSeconds(180)); }
public void JobQueueManager_Can_Mark_Retry() { var testStore = new InMemoryTestStore(); var actor = Sys.ActorOf(Props.Create(() => new JobQueueLayerActor(new InMemoryTestStore()))); var jobInfo = JobCreator.Create((MockJob m) => m.MockMethod()); var myGuid = testStore.AddJob((MockJob m) => m.MockMethod(), new RetryParameters(1, TimeSpan.FromSeconds(20)), null, "test"); var ourJob = InMemoryTestStore.jobPeeker["test"].FirstOrDefault(q => q.JobId == myGuid); var attemptTime = DateTime.Now; actor.Tell(new MarkJobInRetryAndIncrement(myGuid, attemptTime)); System.Threading.SpinWait.SpinUntil(() => false, TimeSpan.FromSeconds(2)); Xunit.Assert.Equal(JobStates.Retry, ourJob.Status); Xunit.Assert.Equal(1, ourJob.RetryParameters.RetryCount); Xunit.Assert.Equal(attemptTime, ourJob.RetryParameters.LastAttempt); }
public void JobExecutorShell_Will_Shutdown() { var queueName = QueueNameHelper.CreateQueueName(); //Warning: this test is a bit racy, due to the nature of JobExecutor and the scheduler. //Lowering the timeouts may cause false failures on the test, as the timer may fire before the shutdown is even called. var jobStore = new InMemoryTestStore(); var executor = new HardInjectedJobExecutorShell <JobQueueLayerActor, JobWorkerActor, JobQueueCoordinator>(() => new JobQueueLayerActor(jobStore), () => new JobWorkerActor(new DefaultJobExecutor(new DefaultContainerFactory())), () => new JobQueueCoordinator(), null); jobStore.AddJob((ShellShutdownMockJob1 m) => m.DoThing(0), null, null, queueName); executor.StartJobQueue(queueName, 5, 5, 5); executor.ShutDownQueue(queueName); SpinWait.SpinUntil(() => false, TimeSpan.FromSeconds(5)); Xunit.Assert.True(ShellShutdownMockJob1.MyCounter.ContainsKey(0) == false); }