Updated Branches: refs/heads/camel-2.12.x 7b9e13e2a -> 3f1edb04f refs/heads/master eafa69511 -> c6f05fa09
Added unit test Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c6f05fa0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c6f05fa0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c6f05fa0 Branch: refs/heads/master Commit: c6f05fa09113233b4121094492f8909e07a6e873 Parents: eafa695 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Oct 25 13:11:09 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Oct 25 13:11:09 2013 +0200 ---------------------------------------------------------------------- .../netty/http/ManagedNettyEndpointTest.java | 85 ++++++++++++++++++++ 1 file changed, 85 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c6f05fa0/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java new file mode 100644 index 0000000..986c1b7 --- /dev/null +++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/ManagedNettyEndpointTest.java @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.netty.http; + +import java.util.Set; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.management.DefaultManagementNamingStrategy; +import org.junit.Test; + +public class ManagedNettyEndpointTest extends BaseNettyTest { + + @Override + protected boolean useJmx() { + return true; + } + + protected CamelContext createCamelContext() throws Exception { + CamelContext context = super.createCamelContext(); + DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context.getManagementStrategy().getManagementNamingStrategy(); + naming.setHostName("localhost"); + naming.setDomainName("org.apache.camel"); + return context; + } + + protected MBeanServer getMBeanServer() { + return context.getManagementStrategy().getManagementAgent().getMBeanServer(); + } + + @Test + public void testManagement() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + + // should not add 100 endpoints + getMockEndpoint("mock:foo").expectedMessageCount(100); + for (int i = 0; i < 100; i++) { + String out = template.requestBody("netty-http:http://localhost:{{port}}/foo?param" + i + "=value" + i, "Hello World", String.class); + assertEquals("param" + i + "=value" + i, out); + } + assertMockEndpointsSatisfied(); + + MBeanServer mbeanServer = getMBeanServer(); + + ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"http://0.0.0.0:" + getPort() + "/foo\""); + mbeanServer.isRegistered(on); + + // should only be 2 endpoints in JMX + Set<ObjectName> set = getMBeanServer().queryNames(new ObjectName("*:context=localhost/camel-1,type=endpoints,*"), null); + assertEquals(2, set.size()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("netty-http:http://0.0.0.0:{{port}}/foo") + .to("mock:foo") + .transform().header(Exchange.HTTP_QUERY); + } + }; + } + +}