@Bean @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(DirectComponent.class) public DirectComponent configureDirectComponent(CamelContext camelContext, DirectComponentConfiguration configuration) throws Exception { DirectComponent component = new DirectComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters); return component; }
public void testGetComponent() { DefaultCamelContext ctx = new DefaultCamelContext(); ctx.disableJMX(); ctx.addComponent("log", new LogComponent()); LogComponent log = ctx.getComponent("log", LogComponent.class); assertNotNull(log); try { ctx.addComponent("direct", new DirectComponent()); ctx.getComponent("log", DirectComponent.class); fail("Should have thrown exception"); } catch (IllegalArgumentException e) { // expected } }
private void bindToRegistry(JndiRegistry jndi) throws Exception { Component comp = new DirectComponent(); comp.setCamelContext(context); Endpoint slow = comp.createEndpoint("direct:somename"); Consumer consumer = slow.createConsumer(new Processor() { public void process(Exchange exchange) throws Exception { template.send("mock:result", exchange); } }); consumer.start(); // bind our endpoint to the registry for ref to lookup jndi.bind("foo", slow); }
@Test public void queryGets1ValueBack() throws Exception { setupManagementStrategy(); Set<ObjectName> objectNames = new HashSet<ObjectName>(); objectNames.add(new ObjectName("org.apache.camel:type=routes,name=route1,*")); objectNames.add(new ObjectName("org.apache.camel:type=routes,name=route2,*")); MBeanServer mBeanServerMocked = Mockito.mock(MBeanServer.class); provideRouteStats(mBeanServerMocked, objectNames); provideAllRoutes(mBeanServerMocked, objectNames); //TODO: update as failing test DirectComponent component = new DirectComponent(); component.setCamelContext(context); DefaultChannel processor1 = new DefaultChannel(); processor1.setChildDefinition(new ToDefinition(new DirectEndpoint("direct:lb1", component))); DefaultChannel processor2 = new DefaultChannel(); processor2.setChildDefinition(new ToDefinition(new DirectEndpoint("direct:lb2", component))); List<Processor> processors = new LinkedList<Processor>(); processors.add(processor1); processors.add(processor2); MBeanRouteStatisticsCollector collector = new MBeanRouteStatisticsCollector(context, mBeanServerMocked, "route", false, false); List<RouteStatistics> stats = collector.query(processors, createExchange()); Assert.assertNotNull(stats); Assert.assertEquals(2, stats.size()); RouteStatistics first = stats.get(0); Assert.assertEquals(new Long(1), new Long(first.getInflightExchange())); Assert.assertEquals(new Long(20L), new Long(first.getMeanProcessingTime())); Assert.assertEquals(new Long(30L), new Long(first.getLastProcessingTime())); Assert.assertEquals("1", first.getLoad01()); Assert.assertEquals("5", first.getLoad05()); Assert.assertEquals("15", first.getLoad15()); }