Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-7276

camel-quartz - use of management name to provide default scheduler name breaks context isolation

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.12.3
    • Fix Version/s: 2.12.4, 2.13.0
    • Component/s: camel-quartz
    • Labels:
      None
    • Estimated Complexity:
      Unknown
    • Regression:
      Regression

      Description

      When using the camel-quartz component in an unmanged context with multiple camel contexts, for example in a JUnit test case, causes the scheduler to be created with the instance name "DefaultQuartzScheduler" which is then shared across all camel context's within the same jvm.

      This is in contradiction of the previous behaviour that uses `getCamelContext.getName()` which isolates the scheduler by denoting that the default instance is specific to the camel context.

      package org.apache.camel.component.quartz;
      
      import org.apache.camel.CamelContext;
      import org.apache.camel.impl.DefaultCamelContext;
      import org.apache.camel.management.JmxSystemPropertyKeys;
      import org.junit.Test;
      import org.quartz.Scheduler;
      import org.quartz.SchedulerException;
      
      import static org.junit.Assert.assertNotEquals;
      import static org.junit.Assert.assertNotSame;
      
      /**
       * Test regression of camel-context isolation of default scheduler instance introduced in CAMEL-7034.
       */
      public class QuartzComponentCamelContextSchedulerIsolationTest {
      
        @Test
        public void testSchedulerIsolation_unmanaged() throws Exception {
          disableJMX();
          testSchedulerIsolation();
        }
      
        @Test
        public void testSchedulerIsolation_managed() throws Exception {
          enableJMX();
          testSchedulerIsolation();
        }
      
        private void testSchedulerIsolation() throws Exception {
          CamelContext context = createCamelContext();
          context.start();
      
          CamelContext anotherContext = createCamelContext();
          assertNotEquals(anotherContext.getName(), context.getName());
          assertNotEquals(anotherContext, context);
      
          assertNotSame(getDefaultScheduler(context), getDefaultScheduler(anotherContext));
        }
      
        /**
         * Create a new camel context instance.
         */
        private DefaultCamelContext createCamelContext() {
          return new DefaultCamelContext();
        }
      
        /**
         * Get the quartz component for the provided camel context.
         */
        private QuartzComponent getQuartzComponent(CamelContext context) {
          return context.getComponent("quartz", QuartzComponent.class);
        }
      
        /**
         * Get the default scheduler for the provided camel context.
         */
        private Scheduler getDefaultScheduler(CamelContext context) throws SchedulerException {
          return getQuartzComponent(context).getFactory().getScheduler();
        }
      
        /**
         * Disables the JMX agent.
         */
        private void disableJMX() {
          System.setProperty(JmxSystemPropertyKeys.DISABLED, "true");
        }
      
        /**
         * Enables the JMX agent.
         */
        private void enableJMX() {
          System.setProperty(JmxSystemPropertyKeys.DISABLED, "false");
        }
      
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                davsclaus Claus Ibsen
                Reporter:
                ukcrpb6 Bob Browning
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: