Search in sources :

Example 1 with ChainedServiceCallServiceFilterConfiguration

use of org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration in project camel by apache.

the class ChainedServiceFilterTest method testMultiServiceFilter.

@Test
public void testMultiServiceFilter() throws Exception {
    ChainedServiceCallServiceFilterConfiguration conf = new ChainedServiceCallServiceFilterConfiguration().healthy().custom(services -> services.stream().filter(s -> s.getPort() < 2000).collect(Collectors.toList()));
    List<ServiceDefinition> services = conf.newInstance(context).apply(Arrays.asList(new DefaultServiceDefinition("no-name", "127.0.0.1", 1000), new DefaultServiceDefinition("no-name", "127.0.0.1", 1001, new DefaultServiceHealth(false)), new DefaultServiceDefinition("no-name", "127.0.0.1", 1002, new DefaultServiceHealth(true)), new DefaultServiceDefinition("no-name", "127.0.0.1", 2001, new DefaultServiceHealth(true)), new DefaultServiceDefinition("no-name", "127.0.0.1", 2001, new DefaultServiceHealth(false))));
    Assert.assertEquals(2, services.size());
    Assert.assertFalse(services.stream().anyMatch(s -> !s.getHealth().isHealthy()));
    Assert.assertFalse(services.stream().anyMatch(s -> s.getPort() > 2000));
    Assert.assertTrue(services.stream().anyMatch(s -> s.getPort() == 1000));
    Assert.assertTrue(services.stream().anyMatch(s -> s.getPort() == 1002));
}
Also used : Arrays(java.util.Arrays) List(java.util.List) ContextTestSupport(org.apache.camel.ContextTestSupport) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) ChainedServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration) ChainedServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) Test(org.junit.Test)

Example 2 with ChainedServiceCallServiceFilterConfiguration

use of org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration in project camel by apache.

the class ServiceCallConfigurationTest method testServiceDiscoveryConfiguration.

@Test
public void testServiceDiscoveryConfiguration() {
    SpringCamelContext context = createContext("org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml");
    ServiceCallConfigurationDefinition conf1 = context.getServiceCallConfiguration("conf1");
    assertNotNull("No ServiceCallConfiguration (1)", conf1);
    assertNotNull("No ServiceDiscoveryConfiguration (1)", conf1.getServiceDiscoveryConfiguration());
    assertNotNull("No ServiceCallLoadBalancerConfiguration (1)", conf1.getLoadBalancerConfiguration());
    assertTrue(conf1.getLoadBalancerConfiguration() instanceof DefaultServiceCallLoadBalancerConfiguration);
    StaticServiceCallServiceDiscoveryConfiguration discovery1 = (StaticServiceCallServiceDiscoveryConfiguration) conf1.getServiceDiscoveryConfiguration();
    assertEquals(1, discovery1.getServers().size());
    assertEquals("localhost:9091", discovery1.getServers().get(0));
    ServiceCallConfigurationDefinition conf2 = context.getServiceCallConfiguration("conf2");
    assertNotNull("No ServiceCallConfiguration (2)", conf2);
    assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration());
    assertNull(conf2.getLoadBalancerConfiguration());
    ChainedServiceCallServiceDiscoveryConfiguration discovery2 = (ChainedServiceCallServiceDiscoveryConfiguration) conf2.getServiceDiscoveryConfiguration();
    assertEquals(2, discovery2.getServiceDiscoveryConfigurations().size());
    assertTrue(discovery2.getServiceDiscoveryConfigurations().get(0) instanceof StaticServiceCallServiceDiscoveryConfiguration);
    assertTrue(discovery2.getServiceDiscoveryConfigurations().get(1) instanceof StaticServiceCallServiceDiscoveryConfiguration);
    StaticServiceCallServiceDiscoveryConfiguration sconf1 = (StaticServiceCallServiceDiscoveryConfiguration) discovery2.getServiceDiscoveryConfigurations().get(0);
    assertEquals(1, sconf1.getServers().size());
    assertEquals("localhost:9092", sconf1.getServers().get(0));
    StaticServiceCallServiceDiscoveryConfiguration sconf2 = (StaticServiceCallServiceDiscoveryConfiguration) discovery2.getServiceDiscoveryConfigurations().get(1);
    assertEquals(1, sconf2.getServers().size());
    assertEquals("localhost:9093,localhost:9094,localhost:9095,localhost:9096", sconf2.getServers().get(0));
    ChainedServiceCallServiceFilterConfiguration filter = (ChainedServiceCallServiceFilterConfiguration) conf2.getServiceFilterConfiguration();
    assertEquals(2, filter.getServiceFilterConfigurations().size());
    assertTrue(filter.getServiceFilterConfigurations().get(0) instanceof HealthyServiceCallServiceFilterConfiguration);
    assertTrue(filter.getServiceFilterConfigurations().get(1) instanceof BlacklistServiceCallServiceFilterConfiguration);
}
Also used : DefaultServiceCallLoadBalancerConfiguration(org.apache.camel.model.cloud.DefaultServiceCallLoadBalancerConfiguration) ChainedServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) BlacklistServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.BlacklistServiceCallServiceFilterConfiguration) HealthyServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.HealthyServiceCallServiceFilterConfiguration) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) StaticServiceCallServiceDiscoveryConfiguration(org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration) ChainedServiceCallServiceDiscoveryConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration) Test(org.junit.Test)

Example 3 with ChainedServiceCallServiceFilterConfiguration

use of org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration in project camel by apache.

the class ChainedServiceFilterTest method testMultiServiceFilterConfiguration.

@Test
public void testMultiServiceFilterConfiguration() throws Exception {
    ChainedServiceCallServiceFilterConfiguration conf = new ChainedServiceCallServiceFilterConfiguration().healthy().passThrough();
    ChainedServiceFilter filter = (ChainedServiceFilter) conf.newInstance(context);
    Assert.assertEquals(2, filter.getDelegates().size());
    Assert.assertTrue(filter.getDelegates().get(0) instanceof HealthyServiceFilter);
    Assert.assertTrue(filter.getDelegates().get(1) instanceof PassThroughServiceFilter);
}
Also used : ChainedServiceCallServiceFilterConfiguration(org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration) Test(org.junit.Test)

Aggregations

ChainedServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration)3 Test (org.junit.Test)3 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ContextTestSupport (org.apache.camel.ContextTestSupport)1 ServiceDefinition (org.apache.camel.cloud.ServiceDefinition)1 BlacklistServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.BlacklistServiceCallServiceFilterConfiguration)1 ChainedServiceCallServiceDiscoveryConfiguration (org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration)1 DefaultServiceCallLoadBalancerConfiguration (org.apache.camel.model.cloud.DefaultServiceCallLoadBalancerConfiguration)1 HealthyServiceCallServiceFilterConfiguration (org.apache.camel.model.cloud.HealthyServiceCallServiceFilterConfiguration)1 ServiceCallConfigurationDefinition (org.apache.camel.model.cloud.ServiceCallConfigurationDefinition)1 StaticServiceCallServiceDiscoveryConfiguration (org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1 Assert (org.junit.Assert)1