public void StartStopTest() { var scheduledRunner = new BatchRunner <Param, bool>(TimeSpan.FromMilliseconds(100), 10, 1024, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000), new BatchWorker()); scheduledRunner.Start(); Thread.Sleep(100); scheduledRunner.Stop(); }
public void EnqueueAndWaitTest() { var scheduledRunner = new BatchRunner <Param, bool>(TimeSpan.FromMilliseconds(100), 10, 1024, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000), new BatchWorker()); scheduledRunner.Start(); var result = scheduledRunner.EnqueueAndWaitItem(new Param()); scheduledRunner.Stop(); Assert.IsTrue(result); }
public void StoppingEnqueueWaitTest() { var scheduledRunner = new BatchRunner <Param, bool>(TimeSpan.FromMilliseconds(100), 10, 1024, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000), new BatchWorker()); scheduledRunner.Start(); var @event = new ManualResetEvent(false); var workItem = new WorkItem <Param, bool>(@event, new Param()); scheduledRunner.Stop(); scheduledRunner.EnqueueItem(workItem); @event.WaitOne(scheduledRunner.WaitTime); Assert.IsFalse(workItem.Result); }
public static void Start(IBatchParameters batchParameters, IMessagingServiceClient messagingServiceClient) { var batchWorkerRecord = new BatchWorkerRecord(messagingServiceClient); var batchWorkerReceiveAndForget = new BatchWorkerReceiveAndForget(messagingServiceClient); var batchWorkerPeek = new BatchWorkerPeek(messagingServiceClient); var batchWorkerCommit = new BatchWorkerCommit(messagingServiceClient); BatchRunnerReceiveAndForget = new BatchRunner <long, OutgoingMessageToStoreWithState>( batchParameters.MessagingReceiveAndForgetCollectionTime, batchParameters.MessagingReceiveAndForgetCollectionBatch, batchParameters.MessagingReceiveAndForgetFlushBatch, batchParameters.MessagingReceiveAndForgetOperationTimeout, batchParameters.MessagingReceiveAndForgetWorkerStopTimeout, batchWorkerReceiveAndForget); BatchRunnerPeek = new BatchRunner <long, OutgoingMessageToStoreWithState>( batchParameters.MessagingPeekCollectionTime, batchParameters.MessagingPeekCollectionBatch, batchParameters.MessagingPeekFlushBatch, batchParameters.MessagingPeekOperationTimeout, batchParameters.MessagingPeekWorkerStopTimeout, batchWorkerPeek); BatchRunnerCommit = new BatchRunner <long, OutgoingState>( batchParameters.MessagingCommitCollectionTime, batchParameters.MessagingCommitCollectionBatch, batchParameters.MessagingCommitFlushBatch, batchParameters.MessagingCommitOperationTimeout, batchParameters.MessagingCommitWorkerStopTimeout, batchWorkerCommit); BatchRunnerRecord = new BatchRunner <OutgoingMessageToStore, OutgoingState>( batchParameters.MessagingRecordCollectionTime, batchParameters.MessagingRecordCollectionBatch, batchParameters.MessagingRecordFlushBatch, batchParameters.MessagingRecordOperationTimeout, batchParameters.MessagingRecordWorkerStopTimeout, batchWorkerRecord); BatchRunnerReceiveAndForget.Start(); BatchRunnerPeek.Start(); BatchRunnerCommit.Start(); BatchRunnerRecord.Start(); }
public void EnqueueAndWaitManyItemsAbove64Test() { bool wasOk = false; var thread = new Thread(() => { var scheduledRunner = new BatchRunner <Param, bool>(TimeSpan.FromMilliseconds(100), 10, 1024, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000), new BatchWorkerFullOk()); scheduledRunner.Start(); var result = scheduledRunner.EnqueueAndWaitManyItems(Enumerable.Range(0, 1000).Select(p => new Param())); scheduledRunner.Stop(); wasOk = result.All(t => t.Result); }); thread.SetApartmentState(ApartmentState.MTA); thread.Start(); thread.Join(); Assert.IsTrue(wasOk); }
public void EnqueueWaitFailTooTest() { var scheduledRunner = new BatchRunner <Param, bool>(TimeSpan.FromMilliseconds(100), 10, 1024, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000), new BatchWorker()); scheduledRunner.Start(); var event1 = new ManualResetEvent(false); var workItem1 = new WorkItem <Param, bool>(event1, new Param()); scheduledRunner.EnqueueItem(workItem1); var event2 = new ManualResetEvent(false); var workItem2 = new WorkItem <Param, bool>(event2, new Param()); scheduledRunner.EnqueueItem(workItem2); event1.WaitOne(scheduledRunner.WaitTime); event2.WaitOne(scheduledRunner.WaitTime); scheduledRunner.Stop(); Assert.IsTrue(workItem1.Result); Assert.IsFalse(workItem2.Result); }