コード例 #1
0
        private async Task RunProducerInternalAsync(
            IProducerMethodQueue
            queue, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            bool sendViaBatch, int runTime, Guid id, LinqMethodTypes methodType)
        {
            var numberOfJobs = Convert.ToInt32(messageCount);

            switch (methodType)
            {
            case LinqMethodTypes.Compiled:
            {
                var jobs = Enumerable.Range(0, numberOfJobs)
                           .Select(i => GenerateMethod.CreateCompiled(id, runTime));
                await RunProducerInternalAsync(queue, generateData, sendViaBatch, jobs, numberOfJobs)
                .ConfigureAwait(false);
            }
            break;

#if NETFULL
            case LinqMethodTypes.Dynamic:
            {
                var jobs = Enumerable.Range(0, numberOfJobs)
                           .Select(i => GenerateMethod.CreateDynamic(id, runTime));
                await RunProducerInternalAsync(queue, generateData, sendViaBatch, jobs, numberOfJobs)
                .ConfigureAwait(false);
            }
            break;
#endif
            }
        }
コード例 #2
0
        private async Task RunProducerInternalAsync(
            IProducerMethodQueue
            queue, Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            bool sendViaBatch, IEnumerable <LinqExpressionToRun> jobs, int numberOfJobs)
        {
            if (sendViaBatch)
            {
                var messages = new List <QueueMessage <LinqExpressionToRun, IAdditionalMessageData> >(numberOfJobs);
                messages.AddRange(from job in jobs let data =
                                      generateData(queue.Configuration) select data != null ? new QueueMessage <LinqExpressionToRun, IAdditionalMessageData>(job, data) : new QueueMessage <LinqExpressionToRun, IAdditionalMessageData>(job, null));
                var results = await queue.SendAsync(messages).ConfigureAwait(false);

                Assert.False(results.HasErrors);
            }
            else
            {
                foreach (var job in jobs)
                {
                    var data = generateData(queue.Configuration);
                    if (data != null)
                    {
                        var result = await queue.SendAsync(job, data).ConfigureAwait(false);

                        Assert.False(result.HasError);
                    }
                    else
                    {
                        var result = await queue.SendAsync(job).ConfigureAwait(false);

                        Assert.False(result.HasError);
                    }
                }
            }
        }
コード例 #3
0
        private void RunProducerDynamicInternal(
            IProducerMethodQueue
            queue, long messageCount, Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            bool sendViaBatch, Guid id,
            Func <Guid, int, LinqExpressionToRun>
            generateTestMethod, int runTime)
        {
            var numberOfJobs = Convert.ToInt32(messageCount);
            var jobs         = Enumerable.Range(0, numberOfJobs)
                               .Select(i => generateTestMethod.Invoke(id, runTime));

            if (sendViaBatch)
            {
                var messages = new List <QueueMessage <LinqExpressionToRun, IAdditionalMessageData> >(numberOfJobs);
                messages.AddRange(from job in jobs
                                  let data = generateData(queue.Configuration)
                                             select
                                             data != null
                            ? new QueueMessage <LinqExpressionToRun, IAdditionalMessageData>(job, data)
                            : new QueueMessage <LinqExpressionToRun, IAdditionalMessageData>(job, null));
                var result    = queue.Send(messages);
                var errorList = result.Where(p => result.Any(l => p.SendingException != null))
                                .ToList();
                if (result.HasErrors)
                {
                    Assert.False(result.HasErrors, errorList[0].SendingException.ToString());
                }
                else
                {
                    Assert.False(result.HasErrors);
                }
            }
            else
            {
                Parallel.ForEach(jobs, job =>
                {
                    var data = generateData(queue.Configuration);
                    if (data != null)
                    {
                        var result  = queue.Send(job, data);
                        var message = string.Empty;
                        if (result.SendingException != null)
                        {
                            message = result.SendingException.ToString();
                        }
                        Assert.False(result.HasError, message);
                    }
                    else
                    {
                        var result  = queue.Send(job);
                        var message = string.Empty;
                        if (result.SendingException != null)
                        {
                            message = result.SendingException.ToString();
                        }
                        Assert.False(result.HasError, message);
                    }
                });
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SendToJobQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="dataStorage">The data storage.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 /// <param name="createJobMetaData">The create job meta data.</param>
 public SendToJobQueue(IProducerMethodQueue queue,
                       IDataStorage dataStorage,
                       IGetTimeFactory getTimeFactory,
                       CreateJobMetaData createJobMetaData
                       ) : base(queue, getTimeFactory)
 {
     _dataStorage       = dataStorage;
     _createJobMetaData = createJobMetaData;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqliteSendToJobQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="deleteMessageCommand">The delete message command.</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="createJobMetaData">The create job meta data.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 public SqliteSendToJobQueue(IProducerMethodQueue queue, IQueryHandler<DoesJobExistQuery, QueueStatuses> doesJobExist,
     ICommandHandlerWithOutput<DeleteMessageCommand, long> deleteMessageCommand,
     IQueryHandler<GetJobIdQuery, long> getJobId, CreateJobMetaData createJobMetaData,
     IGetTimeFactory getTimeFactory): base(queue, getTimeFactory)
 {
     _doesJobExist = doesJobExist;
     _deleteMessageCommand = deleteMessageCommand;
     _getJobId = getJobId;
     _createJobMetaData = createJobMetaData;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqliteSendToJobQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="deleteMessageCommand">The delete message command.</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="createJobMetaData">The create job meta data.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 public SqliteSendToJobQueue(IProducerMethodQueue queue, IQueryHandler <DoesJobExistQuery <IDbConnection, IDbTransaction>, QueueStatuses> doesJobExist,
                             ICommandHandlerWithOutput <DeleteMessageCommand, long> deleteMessageCommand,
                             IQueryHandler <GetJobIdQuery, long> getJobId, CreateJobMetaData createJobMetaData,
                             IGetTimeFactory getTimeFactory) : base(queue, getTimeFactory)
 {
     _doesJobExist         = doesJobExist;
     _deleteMessageCommand = deleteMessageCommand;
     _getJobId             = getJobId;
     _createJobMetaData    = createJobMetaData;
 }
コード例 #7
0
 /// <summary>Initializes a new instance of the <see cref="SqliteSendToJobQueue"/> class.</summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="removeMessage">The remove message.</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="createJobMetaData">The create job meta data.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 public SqliteSendToJobQueue(IProducerMethodQueue queue, IQueryHandler <DoesJobExistQuery <IDbConnection, IDbTransaction>, QueueStatuses> doesJobExist,
                             IRemoveMessage removeMessage,
                             IQueryHandler <GetJobIdQuery, long> getJobId, CreateJobMetaData createJobMetaData,
                             IGetTimeFactory getTimeFactory) : base(queue, getTimeFactory)
 {
     _doesJobExist      = doesJobExist;
     _removeMessage     = removeMessage;
     _getJobId          = getJobId;
     _createJobMetaData = createJobMetaData;
 }
コード例 #8
0
 public static IEnumerable<IQueueOutputMessage> RunDynamic(IProducerMethodQueue queue, int count, Func<IAdditionalMessageData> expiredDataFuture)
 {
     for (var i = 0; i < count; i++)
     {
         yield return queue.Send(new LinqExpressionToRun(
             "(message, workerNotification) => new SampleShared.TestClass().RunMe((IWorkerNotification)workerNotification, \"dynamic\", 2, new SampleShared.SomeInput(DateTime.UtcNow.ToString()))",
             new List<string> { "SampleShared.dll" }, //additional references
             new List<string> { "SampleShared" }), expiredDataFuture.Invoke()); //additional using statements
     }
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedisSendJobToQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="deleteMessageCommand">The delete message command.</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 /// <param name="jobSchedulerMetaData">The job scheduler meta data.</param>
 public RedisSendJobToQueue(IProducerMethodQueue queue, IQueryHandler<DoesJobExistQuery, QueueStatuses> doesJobExist,
     ICommandHandlerWithOutput<DeleteMessageCommand, bool> deleteMessageCommand,
     IQueryHandler<GetJobIdQuery, string> getJobId, 
     IGetTimeFactory getTimeFactory, 
     IJobSchedulerMetaData jobSchedulerMetaData): base(queue, getTimeFactory)
 {
     _doesJobExist = doesJobExist;
     _deleteMessageCommand = deleteMessageCommand;
     _getJobId = getJobId;
     _jobSchedulerMetaData = jobSchedulerMetaData;
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LiteDbSendJobToQueue"/> class.
 /// </summary>
 /// <param name="connectionInformation">The connection information.</param>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">The does job exist.</param>
 /// <param name="removeMessage">The remove message.</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="createJobMetaData">The create job meta data.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 public LiteDbSendJobToQueue(LiteDbConnectionManager connectionInformation, IProducerMethodQueue queue, IQueryHandler <DoesJobExistQuery, QueueStatuses> doesJobExist,
                             IRemoveMessage removeMessage,
                             IQueryHandler <GetJobIdQuery <int>, int> getJobId, CreateJobMetaData createJobMetaData,
                             IGetTimeFactory getTimeFactory) : base(queue, getTimeFactory)
 {
     _doesJobExist          = doesJobExist;
     _removeMessage         = removeMessage;
     _getJobId              = getJobId;
     _createJobMetaData     = createJobMetaData;
     _connectionInformation = connectionInformation;
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedisSendJobToQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="deleteMessageCommand">The delete message command.</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 /// <param name="jobSchedulerMetaData">The job scheduler meta data.</param>
 public RedisSendJobToQueue(IProducerMethodQueue queue, IQueryHandler <DoesJobExistQuery, QueueStatuses> doesJobExist,
                            ICommandHandlerWithOutput <DeleteMessageCommand, bool> deleteMessageCommand,
                            IQueryHandler <GetJobIdQuery, string> getJobId,
                            IGetTimeFactory getTimeFactory,
                            IJobSchedulerMetaData jobSchedulerMetaData) : base(queue, getTimeFactory)
 {
     _doesJobExist         = doesJobExist;
     _deleteMessageCommand = deleteMessageCommand;
     _getJobId             = getJobId;
     _jobSchedulerMetaData = jobSchedulerMetaData;
 }
コード例 #12
0
 public static IEnumerable<IQueueOutputMessage> RunStatic(IProducerMethodQueue queue, int count, Func<IAdditionalMessageData> expiredDataFuture)
 {
     for (var i = 0; i < count; i++)
     {
         yield return queue.Send((message, workerNotification) => new TestClass().RunMe(
             workerNotification,
             "a string",
             2,
             new SomeInput(DateTime.UtcNow.ToString())), expiredDataFuture.Invoke());
     }
 }
コード例 #13
0
 /// <summary>Initializes a new instance of the <see cref="RedisSendJobToQueue"/> class.</summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="removeMessage">removes a message</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 /// <param name="jobSchedulerMetaData">The job scheduler meta data.</param>
 public RedisSendJobToQueue(IProducerMethodQueue queue, IQueryHandler <DoesJobExistQuery, QueueStatuses> doesJobExist,
                            IRemoveMessage removeMessage,
                            IQueryHandler <GetJobIdQuery, string> getJobId,
                            IGetTimeFactory getTimeFactory,
                            IJobSchedulerMetaData jobSchedulerMetaData) : base(queue, getTimeFactory)
 {
     _doesJobExist         = doesJobExist;
     _removeMessage        = removeMessage;
     _getJobId             = getJobId;
     _jobSchedulerMetaData = jobSchedulerMetaData;
 }
コード例 #14
0
 /// <summary>Initializes a new instance of the <see cref="PostgreSqlSendJobToQueue"/> class.</summary>
 /// <param name="queue">The queue.</param>
 /// <param name="doesJobExist">Query for determining if a job already exists</param>
 /// <param name="getJobId">The get job identifier.</param>
 /// <param name="createJobMetaData">The create job meta data.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 /// <param name="removeMessage"></param>
 /// <inheritdoc />
 public PostgreSqlSendJobToQueue(IProducerMethodQueue queue, IQueryHandler <DoesJobExistQuery <NpgsqlConnection, NpgsqlTransaction>, QueueStatuses> doesJobExist,
                                 IQueryHandler <GetJobIdQuery, long> getJobId,
                                 CreateJobMetaData createJobMetaData,
                                 IGetTimeFactory getTimeFactory,
                                 IRemoveMessage removeMessage) : base(queue, getTimeFactory)
 {
     _doesJobExist      = doesJobExist;
     _getJobId          = getJobId;
     _createJobMetaData = createJobMetaData;
     _removeMessage     = removeMessage;
 }
コード例 #15
0
 private void RunProducerDynamic(
     IProducerMethodQueue queue,
     QueueConnection queueConnection,
     long messageCount,
     Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
     Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
     bool sendViaBatch, Guid id,
     Func <Guid, int, LinqExpressionToRun> generateTestMethod, int runTime, ICreationScope scope)
 {
     RunProducerDynamicInternal(queue, messageCount, generateData, sendViaBatch, id, generateTestMethod, runTime);
     LoggerShared.CheckForErrors(queueConnection.Queue);
     verify(queueConnection, queue.Configuration, messageCount, scope);
 }
コード例 #16
0
        public static async Task<List<IQueueOutputMessage>> RunDynamicAsync(IProducerMethodQueue queue, int count, Func<IAdditionalMessageData> expiredDataFuture)
        {
            var results = new List<IQueueOutputMessage>(count);
            for (var i = 0; i < count; i++)
            {
                var result = await queue.SendAsync(new LinqExpressionToRun(
                    "(message, workerNotification) => new SampleShared.TestClass().RunMe((IWorkerNotification)workerNotification, \"dynamic\", 2, new SampleShared.SomeInput(DateTime.UtcNow.ToString()))",
                    new List<string> { "SampleShared.dll" }, //additional references
                    new List<string> { "SampleShared" }), expiredDataFuture.Invoke()); //additional using statements
                results.Add(result);
            }

            return results;
        }
コード例 #17
0
 private void RunProducerCompiled(
     IProducerMethodQueue queue,
     QueueConnection queueConnection,
     long messageCount,
     Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
     Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify,
     bool sendViaBatch, Guid id,
     Func <Guid, int, Expression <Action <IReceivedMessage <MessageExpression>, IWorkerNotification> > >
     generateTestMethod, int runTime, ICreationScope scope)
 {
     RunProducerCompiledInternal(queue, messageCount, generateData, sendViaBatch, id, generateTestMethod, runTime);
     LoggerShared.CheckForErrors(queueConnection.Queue);
     verify(queueConnection, queue.Configuration, messageCount, scope);
 }
コード例 #18
0
        private async Task RunProducerAsync(
            IProducerMethodQueue queue,
            QueueConnection queueConnection,
            long messageCount,
            Func <QueueProducerConfiguration, AdditionalMessageData> generateData,
            Action <QueueConnection, QueueProducerConfiguration, long, ICreationScope> verify, bool sendViaBatch,
            int runTime, Guid id, LinqMethodTypes type, ICreationScope scope)
        {
            await RunProducerInternalAsync(queue, messageCount, generateData, sendViaBatch, runTime, id, type)
            .ConfigureAwait(false);

            LoggerShared.CheckForErrors(queueConnection.Queue);
            verify(queueConnection,
                   queue.Configuration, messageCount, scope);
        }
コード例 #19
0
        public static async Task<List<IQueueOutputMessage>> RunStaticAsync(IProducerMethodQueue queue, int count, Func<IAdditionalMessageData> expiredDataFuture)
        {
            var results = new List<IQueueOutputMessage>(count);
            for (var i = 0; i < count; i++)
            {
                var result = await queue.SendAsync((message, workerNotification) => new TestClass().RunMe(
                    workerNotification,
                    "a string",
                    2,
                    new SomeInput(DateTime.UtcNow.ToString())), expiredDataFuture.Invoke());
                results.Add(result);
            }

            return results;
        }
コード例 #20
0
        public static void RunLoop(IProducerMethodQueue queue, Func <IAdditionalMessageData> expiredDataInstant, Func <IAdditionalMessageData> expiredDataFuture)
        {
            var keepRunning = true;

            while (keepRunning)
            {
                Console.WriteLine(@"To test heartbeat recovery, force kill your consumer after starting to process record(s)
To test rollbacks, cancel the consumer by pressing any button. Easier to test with longer running jobs.

Sync
a) Send 1 static job
b) Send 1 dynamic job

Async
c) Send 1 static job
d) Send 1 dynamic job

q) Quit");
                var key = char.ToLower(Console.ReadKey(true).KeyChar);
                switch (key)
                {
                case 'a':
                    HandleResults.Handle(RunStatic(queue, 1, expiredDataFuture), Log.Logger);
                    break;

                case 'b':
                    HandleResults.Handle(RunDynamic(queue, 1, expiredDataFuture), Log.Logger);
                    break;

                case 'c':
                    HandleResults.Handle(RunStaticAsync(queue, 1, expiredDataFuture).Result, Log.Logger);
                    break;

                case 'd':
                    HandleResults.Handle(RunDynamicAsync(queue, 1, expiredDataFuture).Result, Log.Logger);
                    break;

                case 'q':
                    Console.WriteLine("Quitting");
                    keepRunning = false;
                    break;
                }
            }
        }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ASendJobToQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 protected ASendJobToQueue(IProducerMethodQueue queue,
                           IGetTimeFactory getTimeFactory)
 {
     Queue          = queue;
     GetTimeFactory = getTimeFactory;
 }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ASendJobToQueue" /> class.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="getTimeFactory">The get time factory.</param>
 protected ASendJobToQueue(IProducerMethodQueue queue, 
     IGetTimeFactory getTimeFactory)
 {
     Queue = queue;
     GetTimeFactory = getTimeFactory;
 }