public void SerializationSerialize() { var job = new TestSerializationJob() { A = new Guid("1854ef1b-3937-476a-8b32-56436a7b6feb").ToString(), B = "Hello, world!", C = new DateTime(1982, 5, 28).ToUniversalTime() }; string data = JobSerializer.Serialize(job); Assert.AreEqual(@"{""A"":""1854ef1b-3937-476a-8b32-56436a7b6feb"",""B"":""Hello, world!"",""C"":""1982-05-28T07:00:00Z""}", data); }
protected override void ProcessRecord() { List <Job> jobList = JobSerializer.Deserialize(MDPath); if (Json) { Item.JsonIndented = JsonIndented; WriteObject(JobSerializer.Serialize(jobList, Item.EXTENSION_JSON)); Item.JsonIndented = false; } else if (Xml) { WriteObject(JobSerializer.Serialize(jobList, Item.EXTENSION_XML)); } else { WriteObject(JobSerializer.Serialize(jobList, Item.EXTENSION_MD)); } }
public void BenchmarkDequeueAndExecute1000Jobs() { ManualResetEvent handle = new ManualResetEvent(false); Queue <QueueRecord> queue = new Queue <QueueRecord>(); TestJob job = new TestJob() { SleepDuration = 10 }; string typeName = JobSerializer.GetTypeName(job.GetType()); for (int i = 0; i < 1000; i++) { job.Id = Guid.NewGuid(); queue.Enqueue( new QueueRecord() { Id = i + 1, ApplicationName = BlueCollarSection.Section.ApplicationName, Data = JobSerializer.Serialize(job), JobName = job.Name, JobType = typeName, QueuedOn = DateTime.UtcNow, QueueName = "*", TryNumber = 1 }); } SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None }; 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.CreateWorking(It.IsAny <WorkingRecord>(), It.IsAny <IDbTransaction>())).Returns((WorkingRecord r, IDbTransaction t) => { r.Id = 1; return(r); }); repository.Setup(r => r.GetWorkingSignals(It.IsAny <long>(), It.IsAny <long?>(), It.IsAny <IDbTransaction>())).Returns(signals); repository.Setup(r => r.GetQueued(It.IsAny <string>(), It.IsAny <QueueNameFilters>(), It.IsAny <DateTime>(), It.IsAny <IDbTransaction>())) .Returns( () => { var r = queue.Dequeue(); if (queue.Count == 0) { handle.Set(); } return(r); }); var factory = new Mock <IRepositoryFactory>(); factory.Setup(f => f.Create()).Returns(repository.Object); var logger = new Mock <ILogger>(); Stopwatch stopwatch = new Stopwatch(); using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", QueueNameFilters.Any(), 1, false, factory.Object, logger.Object)) { stopwatch.Start(); worker.Start(); handle.WaitOne(); worker.Stop(false); stopwatch.Stop(); } this.TestContext.WriteLine("1,000 jobs with 10ms execution times were dequeued and executed in {0:N3}s.", stopwatch.Elapsed.TotalSeconds); }