public virtual void testCompetingJobAcquisitionMetricReporting()
        {
            // given
            for (var i = 0; i < 3; i++)
            {
                runtimeService.StartProcessInstanceByKey("asyncServiceTaskProcess");
            }

            // replace job executor
            var jobExecutor1 = new ControllableJobExecutor((ProcessEngineImpl)ProcessEngine);

            processEngineConfiguration.SetJobExecutor(jobExecutor1);
            var jobExecutor2 = new ControllableJobExecutor((ProcessEngineImpl)ProcessEngine);

            var jobAcquisitionThread1 = jobExecutor1.AcquisitionThreadControl;
            var jobAcquisitionThread2 = jobExecutor2.AcquisitionThreadControl;

            // when both executors are waiting to finish acquisition
            jobExecutor1.Start();
            jobAcquisitionThread1.WaitForSync();                // wait before starting acquisition
            jobAcquisitionThread1.MakeContinueAndWaitForSync(); // wait before finishing acquisition

            jobExecutor2.Start();
            jobAcquisitionThread2.WaitForSync();                // wait before starting acquisition
            jobAcquisitionThread2.MakeContinueAndWaitForSync(); // wait before finishing acquisition

            // thread 1 is able to acquire all jobs
            jobAcquisitionThread1.MakeContinueAndWaitForSync();
            // thread 2 cannot acquire any jobs since they have been locked (and executed) by thread1 meanwhile
            jobAcquisitionThread2.MakeContinueAndWaitForSync();

            processEngineConfiguration.DbMetricsReporter.ReportNow();

            // then
            var acquisitionAttempts = managementService.CreateMetricsQuery()
                                      .Name(ESS.FW.Bpm.Engine.Management.Metrics.JobAcquisitionAttempt)
                                      .Sum();

            // each job executor twice (since the controllable thread always waits when already acquiring jobs)
            Assert.AreEqual(2 + 2, acquisitionAttempts);

            var acquiredJobs = managementService.CreateMetricsQuery()
                               .Name(ESS.FW.Bpm.Engine.Management.Metrics.JobAcquiredSuccess)
                               .Sum();

            Assert.AreEqual(3, acquiredJobs);

            var acquiredJobsFailure = managementService.CreateMetricsQuery()
                                      .Name(ESS.FW.Bpm.Engine.Management.Metrics.JobAcquiredFailure)
                                      .Sum();

            Assert.AreEqual(3, acquiredJobsFailure);

            // cleanup
            jobExecutor1.Shutdown();
            jobExecutor2.Shutdown();

            processEngineConfiguration.DbMetricsReporter.ReportNow();
        }
Example #2
0
        public virtual void testCompetingJobAcquisitionMetricReporting()
        {
            // given
            for (int i = 0; i < 3; i++)
            {
                runtimeService.startProcessInstanceByKey("asyncServiceTaskProcess");
            }

            // replace job executor
            ControllableJobExecutor jobExecutor1 = new ControllableJobExecutor((ProcessEngineImpl)processEngine);

            processEngineConfiguration.JobExecutor = jobExecutor1;
            ControllableJobExecutor jobExecutor2 = new ControllableJobExecutor((ProcessEngineImpl)processEngine);

            ThreadControl jobAcquisitionThread1 = jobExecutor1.AcquisitionThreadControl;
            ThreadControl jobAcquisitionThread2 = jobExecutor2.AcquisitionThreadControl;

            // when both executors are waiting to finish acquisition
            jobExecutor1.start();
            jobAcquisitionThread1.waitForSync();                // wait before starting acquisition
            jobAcquisitionThread1.makeContinueAndWaitForSync(); // wait before finishing acquisition

            jobExecutor2.start();
            jobAcquisitionThread2.waitForSync();                // wait before starting acquisition
            jobAcquisitionThread2.makeContinueAndWaitForSync(); // wait before finishing acquisition

            // thread 1 is able to acquire all jobs
            jobAcquisitionThread1.makeContinueAndWaitForSync();
            // thread 2 cannot acquire any jobs since they have been locked (and executed) by thread1 meanwhile
            jobAcquisitionThread2.makeContinueAndWaitForSync();

            processEngineConfiguration.DbMetricsReporter.reportNow();

            // then
            long acquisitionAttempts = managementService.createMetricsQuery().name(Metrics.JOB_ACQUISITION_ATTEMPT).sum();

            // each job executor twice (since the controllable thread always waits when already acquiring jobs)
            assertEquals(2 + 2, acquisitionAttempts);

            long acquiredJobs = managementService.createMetricsQuery().name(Metrics.JOB_ACQUIRED_SUCCESS).sum();

            assertEquals(3, acquiredJobs);

            long acquiredJobsFailure = managementService.createMetricsQuery().name(Metrics.JOB_ACQUIRED_FAILURE).sum();

            assertEquals(3, acquiredJobsFailure);

            // cleanup
            jobExecutor1.shutdown();
            jobExecutor2.shutdown();

            processEngineConfiguration.DbMetricsReporter.reportNow();
        }
 public ControllableAcquisitionCommand(ControllableJobExecutor outerInstance, ConcurrencyTestCase.ThreadControl threadControl, int numJobsToAcquire) : base(threadControl)
 {
     _outerInstance    = outerInstance;
     _numJobsToAcquire = numJobsToAcquire;
 }
 public ControllableJobAcquisitionCommandFactory(ControllableJobExecutor outerInstance)
 {
     _outerInstance = outerInstance;
 }