camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bob Browning (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CAMEL-7276) camel-quartz - use of management name to provide default scheduler name breaks context isolation
Date Thu, 06 Mar 2014 13:42:44 GMT
Bob Browning created CAMEL-7276:
-----------------------------------

             Summary: camel-quartz - use of management name to provide default scheduler name
breaks context isolation
                 Key: CAMEL-7276
                 URL: https://issues.apache.org/jira/browse/CAMEL-7276
             Project: Camel
          Issue Type: Bug
          Components: camel-quartz
    Affects Versions: 2.12.3
            Reporter: Bob Browning


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.

{code}
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.
 *
 * @author Bob Browning <bob.browning@pressassociation.com>
 */
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");
  }

}
{code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message