Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
Unknown
Description
I tried to write a Ribbon Load Balancer test that would send requests to two application paths on the same server and port. Because org.apache.camel.cloud.ServiceDefinition has no notion of context path, I used the ServiceDefinition.metadata to define it and in the serviceCall I used an expression .expression().simple("jetty:http://${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}/${header.CamelServiceCallServiceMeta[contextPath]}") to use it.
However, the test is not passing because RibbonServiceLoadBalancer.RibbonServerList.asRibbonServerList(List<ServiceDefinition>) is not passing the medata map to RibbonServiceDefinition. The test passes as expected when RibbonServerList.asRibbonServerList() is fixed.
Here is the test:
package org.apache.camel.component.ribbon.cloud; import java.util.Collections; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.ribbon.RibbonConfiguration; import org.apache.camel.impl.cloud.StaticServiceDiscovery; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class RibbonServiceCallRouteMetadataTest extends CamelTestSupport { @Test public void testServiceCall() throws Exception { getMockEndpoint("mock:app1").expectedMessageCount(1); getMockEndpoint("mock:app2").expectedMessageCount(1); getMockEndpoint("mock:result").expectedMessageCount(2); String out = template.requestBody("direct:start", null, String.class); String out2 = template.requestBody("direct:start", null, String.class); assertEquals("app2", out); assertEquals("app1", out2); assertMockEndpointsSatisfied(); } @Override protected RoutesBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() throws Exception { // setup a static ribbon server list with these 2 servers to start with StaticServiceDiscovery servers = new StaticServiceDiscovery(); servers.addServer("myService", "localhost", 9090, Collections.singletonMap("contextPath", "app1")); servers.addServer("myService", "localhost", 9090, Collections.singletonMap("contextPath", "app2")); RibbonConfiguration configuration = new RibbonConfiguration(); RibbonServiceLoadBalancer loadBalancer = new RibbonServiceLoadBalancer(configuration); from("direct:start") .serviceCall() .name("myService") .expression().simple("jetty:http://${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}/${header.CamelServiceCallServiceMeta[contextPath]}") .loadBalancer(loadBalancer) .serviceDiscovery(servers) .end() .to("mock:result"); from("jetty:http://localhost:9090/app1") .to("mock:app1") .transform().constant("app1"); from("jetty:http://localhost:9090/app2") .to("mock:app2") .transform().constant("app2"); } }; } }
Attachments
Issue Links
- links to