Exemple #1
0
        public virtual void TestJobCommandsWithMessage()
        {
            var commandExecutor = processEngineConfiguration.CommandExecutorTxRequired;
            var jobExecutor     = processEngineConfiguration.JobExecutor;
            var jobId           = commandExecutor.Execute(new CommandAnonymousInnerClass(this));

            var acquiredJobs = commandExecutor.Execute(new AcquireJobsCmd(jobExecutor));
            var jobIdsList   = acquiredJobs.JobIdBatches;

            Assert.AreEqual(1, jobIdsList.Count);

            var jobIds = jobIdsList[0];

            IList <string> expectedJobIds = new List <string>();

            expectedJobIds.Add(jobId);

            Assert.AreEqual(expectedJobIds, new List <string>(jobIds));
            Assert.AreEqual(0, TweetHandler.Messages.Count);

            ExecuteJobHelper.ExecuteJob(jobId, commandExecutor);

            Assert.AreEqual("i'm coding a test", TweetHandler.Messages[0]);
            Assert.AreEqual(1, TweetHandler.Messages.Count);

            ClearDatabase();
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @SuppressWarnings("unchecked") public void shouldBeAbleToReplaceLoggingHandler()
        public virtual void shouldBeAbleToReplaceLoggingHandler()
        {
            ExecuteJobHelper.ExceptionLoggingHandler originalHandler = ExecuteJobHelper.LOGGING_HANDLER;
            CollectingHandler collectingHandler = new CollectingHandler();
            Exception         exception         = new Exception();

            try
            {
                ExecuteJobHelper.LOGGING_HANDLER = collectingHandler;
                CommandExecutor failingCommandExecutor = mock(typeof(CommandExecutor));
                when(failingCommandExecutor.execute(any(typeof(Command)))).thenThrow(exception);

                // when
                ExecuteJobHelper.executeJob("10", failingCommandExecutor);

                fail("exception expected");
            }
            catch (Exception e)
            {
                // then
                Exception collectedException = collectingHandler.collectedExceptions["10"];
                assertEquals(collectedException, e);
                assertEquals(collectedException, exception);
            }
            finally
            {
                ExecuteJobHelper.LOGGING_HANDLER = originalHandler;
            }
        }
Exemple #3
0
        public virtual void testJobCommandsWithMessage()
        {
            CommandExecutor commandExecutor = processEngineConfiguration.CommandExecutorTxRequired;
            JobExecutor     jobExecutor     = processEngineConfiguration.JobExecutor;
            string          jobId           = commandExecutor.execute(new CommandAnonymousInnerClass(this));

            AcquiredJobs            acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
            IList <IList <string> > jobIdsList   = acquiredJobs.JobIdBatches;

            assertEquals(1, jobIdsList.Count);

            IList <string> jobIds = jobIdsList[0];

            IList <string> expectedJobIds = new List <string>();

            expectedJobIds.Add(jobId);

            assertEquals(expectedJobIds, new List <string>(jobIds));
            assertEquals(0, tweetHandler.Messages.Count);

            ExecuteJobHelper.executeJob(jobId, commandExecutor);

            assertEquals("i'm coding a test", tweetHandler.Messages[0]);
            assertEquals(1, tweetHandler.Messages.Count);

            clearDatabase();
        }
Exemple #4
0
 public override void run()
 {
     try
     {
         JobFailureCollector jobFailureCollector = new JobFailureCollector(jobId);
         ExecuteJobHelper.executeJob(jobId, outerInstance.processEngineConfiguration.CommandExecutorTxRequired, jobFailureCollector, new ControlledCommand <Void>(activeThread, new ExecuteJobsCmd(jobId, jobFailureCollector)));
     }
     catch (OptimisticLockingException e)
     {
         this.exception = e;
     }
     LOG.debug(Name + " ends");
 }
Exemple #5
0
        public virtual void TestJobCommandsWithTimer()
        {
            // clock gets automatically reset in LogTestCase.RunTest
            ClockUtil.CurrentTime = new DateTime(SomeTime);

            var commandExecutor = processEngineConfiguration.CommandExecutorTxRequired;
            var jobExecutor     = processEngineConfiguration.JobExecutor;

            var jobId = commandExecutor.Execute(new CommandAnonymousInnerClass2(this));

            var acquiredJobs = commandExecutor.Execute(new AcquireJobsCmd(jobExecutor));
            var jobIdsList   = acquiredJobs.JobIdBatches;

            Assert.AreEqual(0, jobIdsList.Count);

            IList <string> expectedJobIds = new List <string>();

            //ClockUtil.CurrentTime = new DateTime(SomeTime).AddSeconds(20 * Second);
            ClockUtil.CurrentTime = ClockUtil.CurrentTime.AddSeconds(20 * Second);

            acquiredJobs = commandExecutor.Execute(new AcquireJobsCmd(jobExecutor, jobExecutor.MaxJobsPerAcquisition));
            jobIdsList   = acquiredJobs.JobIdBatches;
            Assert.AreEqual(1, jobIdsList.Count);

            var jobIds = jobIdsList[0];

            expectedJobIds.Add(jobId);
            Assert.AreEqual(expectedJobIds, new List <string>(jobIds));

            Assert.AreEqual(0, TweetHandler.Messages.Count);

            ExecuteJobHelper.ExecuteJob(jobId, commandExecutor);

            Assert.AreEqual("i'm coding a test", TweetHandler.Messages[0]);
            Assert.AreEqual(1, TweetHandler.Messages.Count);

            ClearDatabase();
        }
Exemple #6
0
        public virtual void testJobCommandsWithTimer()
        {
            // clock gets automatically reset in LogTestCase.runTest
            ClockUtil.CurrentTime = new DateTime(SOME_TIME);

            CommandExecutor commandExecutor = processEngineConfiguration.CommandExecutorTxRequired;
            JobExecutor     jobExecutor     = processEngineConfiguration.JobExecutor;

            string jobId = commandExecutor.execute(new CommandAnonymousInnerClass2(this));

            AcquiredJobs            acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor));
            IList <IList <string> > jobIdsList   = acquiredJobs.JobIdBatches;

            assertEquals(0, jobIdsList.Count);

            IList <string> expectedJobIds = new List <string>();

            ClockUtil.CurrentTime = new DateTime(SOME_TIME + (20 * SECOND));

            acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor, jobExecutor.MaxJobsPerAcquisition));
            jobIdsList   = acquiredJobs.JobIdBatches;
            assertEquals(1, jobIdsList.Count);

            IList <string> jobIds = jobIdsList[0];

            expectedJobIds.Add(jobId);
            assertEquals(expectedJobIds, new List <string>(jobIds));

            assertEquals(0, tweetHandler.Messages.Count);

            ExecuteJobHelper.executeJob(jobId, commandExecutor);

            assertEquals("i'm coding a test", tweetHandler.Messages[0]);
            assertEquals(1, tweetHandler.Messages.Count);

            clearDatabase();
        }
Exemple #7
0
 public virtual void executeJob(string jobId)
 {
     ExecuteJobHelper.executeJob(jobId, commandExecutor);
 }