/** * Test failed consumer stop due to scheduler exception. * * @throws SchedulerException */ @Test(expected = RuntimeException.class) public void test_failed_stop_due_to_schedulerException() throws SchedulerException { final JobKey jobKey = new JobKey("flowName", "moduleName"); // expectations mockery.checking( new Expectations() { { // get flow and module name from the job exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); // unschedule the job exactly(1).of(scheduler).checkExists(jobKey); will(returnValue(Boolean.TRUE)); exactly(1).of(scheduler).deleteJob(jobKey); will(throwException(new SchedulerException())); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.stop(); mockery.assertIsSatisfied(); }
/** * Test successful consumer stop. * * @throws SchedulerException */ @Test public void test_successful_stop() throws SchedulerException { final JobKey jobKey = new JobKey("flowName", "moduleName"); // expectations mockery.checking( new Expectations() { { exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); // unschedule the job exactly(1).of(scheduler).checkExists(jobKey); will(returnValue(Boolean.TRUE)); exactly(1).of(scheduler).deleteJob(jobKey); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setJobDetail(mockJobDetail); scheduledConsumer.stop(); mockery.assertIsSatisfied(); }
/** * Test failed consumer start. * * @throws SchedulerException */ @Test(expected = RuntimeException.class) public void test_failed_start_due_to_parserException() throws SchedulerException { final JobKey jobKey = new JobKey("flowName", "moduleName"); // expectations mockery.checking( new Expectations() { { // get flow and module name from the job exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); // access configuration for details exactly(1).of(consumerConfiguration).getCronExpression(); will(returnValue("* * * * ? ?")); // schedule the job exactly(1).of(scheduler).scheduleJob(mockJobDetail, trigger); will(throwException(new ParseException("test", 0))); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.start(); mockery.assertIsSatisfied(); }
@Test public void test_execute_when_messageProvider_message_is_null_when_in_recovery_and_reinstate_business_schedule() throws SchedulerException { final MessageProvider mockMessageProvider = mockery.mock(MessageProvider.class); final JobKey jobKey = new JobKey(""); // expectations mockery.checking( new Expectations() { { exactly(1).of(mockMessageProvider).invoke(jobExecutionContext); will(returnValue(null)); exactly(1).of(consumerConfiguration).isEager(); will(returnValue(false)); exactly(2).of(mockManagedResourceRecoveryManager).isRecovering(); will(returnValue(true)); // cancel recovery exactly(1).of(mockManagedResourceRecoveryManager).cancel(); // nope, consumer is not running exactly(1).of(scheduler).isShutdown(); will(returnValue(false)); exactly(1).of(scheduler).isInStandbyMode(); will(returnValue(false)); exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); exactly(1).of(scheduler).checkExists(jobKey); will(returnValue(false)); // start consumer exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); exactly(1).of(consumerConfiguration).getCronExpression(); will(returnValue("*")); exactly(1).of(scheduler).scheduleJob(mockJobDetail, trigger); will(returnValue(new Date())); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setEventFactory(flowEventFactory); scheduledConsumer.setEventListener(eventListener); scheduledConsumer.setManagedEventIdentifierService(mockManagedEventIdentifierService); scheduledConsumer.setManagedResourceRecoveryManager(mockManagedResourceRecoveryManager); scheduledConsumer.setMessageProvider(mockMessageProvider); scheduledConsumer.setJobDetail(mockJobDetail); scheduledConsumer.setConfiguration(consumerConfiguration); // test scheduledConsumer.execute(jobExecutionContext); // assert mockery.assertIsSatisfied(); }
@Test public void test_execute_when_messageProvider_message_is_not_null_and_consumer_is_eager_existing_eagerTrigger() throws SchedulerException { final FlowEvent mockFlowEvent = mockery.mock(FlowEvent.class); final String identifier = "testId"; final JobKey jobKey = new JobKey("flowName", "moduleName"); final JobDetail jobDetail = mockery.mock(JobDetail.class); // expectations mockery.checking( new Expectations() { { exactly(1).of(mockManagedResourceRecoveryManager).isRecovering(); will(returnValue(false)); // schedule the job exactly(1) .of(mockManagedEventIdentifierService) .getEventIdentifier(jobExecutionContext); will(returnValue(identifier)); exactly(1).of(flowEventFactory).newEvent(identifier, jobExecutionContext); will(returnValue(mockFlowEvent)); exactly(1).of(eventListener).invoke(mockFlowEvent); exactly(1).of(consumerConfiguration).isEager(); will(returnValue(true)); exactly(1).of(jobDetail).getKey(); will(returnValue(jobKey)); exactly(1).of(scheduler).checkExists(with(any(TriggerKey.class))); will(returnValue(true)); exactly(1) .of(scheduler) .rescheduleJob(with(any(TriggerKey.class)), with(any(Trigger.class))); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setEventFactory(flowEventFactory); scheduledConsumer.setEventListener(eventListener); scheduledConsumer.setManagedEventIdentifierService(mockManagedEventIdentifierService); scheduledConsumer.setManagedResourceRecoveryManager(mockManagedResourceRecoveryManager); scheduledConsumer.setJobDetail(jobDetail); // test scheduledConsumer.execute(jobExecutionContext); // assert mockery.assertIsSatisfied(); }
@Test public void test_execute_when_messageProvider_message_is_null_not_in_recovery() throws SchedulerException { final FlowEvent mockFlowEvent = mockery.mock(FlowEvent.class); final MessageProvider mockMessageProvider = mockery.mock(MessageProvider.class); final String identifier = "testId"; // expectations mockery.checking( new Expectations() { { exactly(1).of(mockMessageProvider).invoke(jobExecutionContext); will(returnValue(null)); // schedule the job exactly(0) .of(mockManagedEventIdentifierService) .getEventIdentifier(jobExecutionContext); will(returnValue(identifier)); exactly(0).of(flowEventFactory).newEvent(identifier, jobExecutionContext); will(returnValue(mockFlowEvent)); exactly(0).of(eventListener).invoke(mockFlowEvent); exactly(1).of(mockManagedResourceRecoveryManager).isRecovering(); will(returnValue(false)); exactly(1).of(consumerConfiguration).isEager(); will(returnValue(false)); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setEventFactory(flowEventFactory); scheduledConsumer.setEventListener(eventListener); scheduledConsumer.setManagedEventIdentifierService(mockManagedEventIdentifierService); scheduledConsumer.setManagedResourceRecoveryManager(mockManagedResourceRecoveryManager); scheduledConsumer.setMessageProvider(mockMessageProvider); // test scheduledConsumer.execute(jobExecutionContext); // assert mockery.assertIsSatisfied(); }