Search in sources :

Example 21 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class SpringCamelContextCustomDefaultThreadPoolProfileTest method testDefaultThreadPoolProfile.

public void testDefaultThreadPoolProfile() throws Exception {
    SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    ThreadPoolProfile profile = context.getExecutorServiceManager().getDefaultThreadPoolProfile();
    assertEquals(5, profile.getPoolSize().intValue());
    assertEquals(15, profile.getMaxPoolSize().intValue());
    assertEquals(25, profile.getKeepAliveTime().longValue());
    assertEquals(250, profile.getMaxQueueSize().intValue());
    assertEquals(true, profile.getAllowCoreThreadTimeOut().booleanValue());
    assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
}
Also used : ThreadPoolProfile(org.apache.camel.spi.ThreadPoolProfile) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 22 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class CamelSpringTestContextLoader method handleShutdownTimeout.

/**
     * Handles updating shutdown timeouts on Camel contexts based on {@link ShutdownTimeout}.
     *
     * @param context the initialized Spring context
     * @param testClass the test class being executed
     */
protected void handleShutdownTimeout(GenericApplicationContext context, Class<?> testClass) throws Exception {
    final int shutdownTimeout;
    final TimeUnit shutdownTimeUnit;
    if (testClass.isAnnotationPresent(ShutdownTimeout.class)) {
        shutdownTimeout = testClass.getAnnotation(ShutdownTimeout.class).value();
        shutdownTimeUnit = testClass.getAnnotation(ShutdownTimeout.class).timeUnit();
    } else {
        shutdownTimeout = 10;
        shutdownTimeUnit = TimeUnit.SECONDS;
    }
    CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {

        @Override
        public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
            LOG.info("Setting shutdown timeout to [{} {}] on CamelContext with name [{}].", new Object[] { shutdownTimeout, shutdownTimeUnit, contextName });
            camelContext.getShutdownStrategy().setTimeout(shutdownTimeout);
            camelContext.getShutdownStrategy().setTimeUnit(shutdownTimeUnit);
        }
    });
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) TimeUnit(java.util.concurrent.TimeUnit) DoToSpringCamelContextsStrategy(org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy) Breakpoint(org.apache.camel.spi.Breakpoint)

Example 23 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class CamelAnnotationsHandler method handleProvidesBreakpoint.

public static void handleProvidesBreakpoint(ConfigurableApplicationContext context, Class<?> testClass) throws Exception {
    Collection<Method> methods = getAllMethods(testClass);
    final List<Breakpoint> breakpoints = new LinkedList<Breakpoint>();
    for (Method method : methods) {
        if (AnnotationUtils.findAnnotation(method, ProvidesBreakpoint.class) != null) {
            Class<?>[] argTypes = method.getParameterTypes();
            if (argTypes.length != 0) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not a no-argument method.");
            } else if (!Breakpoint.class.isAssignableFrom(method.getReturnType())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but does not return a Breakpoint.");
            } else if (!Modifier.isStatic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not static.");
            } else if (!Modifier.isPublic(method.getModifiers())) {
                throw new IllegalArgumentException("Method [" + method.getName() + "] is annotated with ProvidesBreakpoint but is not public.");
            }
            try {
                breakpoints.add((Breakpoint) method.invoke(null));
            } catch (Exception e) {
                throw new RuntimeException("Method [" + method.getName() + "] threw exception during evaluation.", e);
            }
        }
    }
    if (breakpoints.size() != 0) {
        CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {

            public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
                Debugger debugger = camelContext.getDebugger();
                if (debugger == null) {
                    debugger = new DefaultDebugger();
                    camelContext.setDebugger(debugger);
                }
                for (Breakpoint breakpoint : breakpoints) {
                    LOGGER.info("Adding Breakpoint [{}] to CamelContext with name [{}].", breakpoint, contextName);
                    debugger.addBreakpoint(breakpoint);
                }
            }
        });
    }
}
Also used : Debugger(org.apache.camel.spi.Debugger) DefaultDebugger(org.apache.camel.impl.DefaultDebugger) Breakpoint(org.apache.camel.spi.Breakpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) DefaultDebugger(org.apache.camel.impl.DefaultDebugger)

Example 24 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class PojoCallable method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    spring = new ClassPathXmlApplicationContext("org/apache/camel/component/javaspace/spring.xml");
    SpringCamelContext ctx = SpringCamelContext.springCamelContext(spring);
    return ctx;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 25 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class JavaSpaceSendReceiveTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    spring = new ClassPathXmlApplicationContext("org/apache/camel/component/javaspace/spring.xml");
    SpringCamelContext ctx = SpringCamelContext.springCamelContext(spring);
    return ctx;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Aggregations

SpringCamelContext (org.apache.camel.spring.SpringCamelContext)30 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 DoToSpringCamelContextsStrategy (org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)5 Method (java.lang.reflect.Method)4 LinkedList (java.util.LinkedList)4 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)4 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)4 Breakpoint (org.apache.camel.spi.Breakpoint)4 Test (org.junit.Test)3 Properties (java.util.Properties)2 TimeUnit (java.util.concurrent.TimeUnit)2 Route (org.apache.camel.Route)2 DefaultDebugger (org.apache.camel.impl.DefaultDebugger)2 InterceptSendToMockEndpointStrategy (org.apache.camel.impl.InterceptSendToMockEndpointStrategy)2 Debugger (org.apache.camel.spi.Debugger)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Channel (org.apache.camel.Channel)1