Search in sources :

Example 16 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class InvocationTest method testNoOverflow.

@Test(timeout = 30 * 1000)
public void testNoOverflow() throws Exception {
    DispatchQueue queue = Dispatch.createQueue();
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    map.put("protobuf", new ProtobufSerializationStrategy());
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return new HelloImpl();
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        char[] chars = new char[65 * 1024];
        String payload = new String(chars);
        for (int i = 0; i < 100; i++) {
            hello.hello(payload);
        }
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 17 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class TransportFailureTest method testInvoke.

@Test
public void testInvoke() throws Exception {
    DispatchQueue queue = Dispatch.createQueue();
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    map.put("protobuf", new ProtobufSerializationStrategy());
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return new HelloImpl();
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
        hello.hello("Guillaume", future1);
        long t0 = System.currentTimeMillis();
        try {
            assertEquals("Hello Guillaume!", future1.get(MAX_DELAY, TimeUnit.MILLISECONDS));
            fail("Should have thrown an exception");
        } catch (Exception e) {
            // Expected
            long t1 = System.currentTimeMillis();
            assertTrue(t1 - t0 > SLEEP_TIME / 2);
            assertTrue(t1 - t0 < MAX_DELAY / 2);
        }
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) AsyncCallbackFuture(io.fabric8.dosgi.api.AsyncCallbackFuture) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ProtobufSerializationStrategy(io.fabric8.dosgi.api.ProtobufSerializationStrategy) SerializationStrategy(io.fabric8.dosgi.api.SerializationStrategy) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) ProtobufSerializationStrategy(io.fabric8.dosgi.api.ProtobufSerializationStrategy) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 18 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class ContainerTest method testLoadBalancer.

@Test
public void testLoadBalancer() throws Exception {
    Profiler profiler = new Profiler();
    Breadcrumbs breadcrumbs = new Breadcrumbs();
    CamelContext context = new DefaultCamelContext();
    profiler.manage(context);
    breadcrumbs.manage(context);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:a").loadBalance().failover().to("mock:out");
        }
    });
    context.start();
    final ProducerTemplate template = new DefaultProducerTemplate(context);
    template.start();
    template.sendBody("direct:a", "Hello");
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) ProducerTemplate(org.apache.camel.ProducerTemplate) Profiler(io.fabric8.insight.camel.profiler.Profiler) RouteBuilder(org.apache.camel.builder.RouteBuilder) Breadcrumbs(io.fabric8.insight.camel.breadcrumb.Breadcrumbs) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Example 19 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class HttpGatewayConnectionTimeoutTest method startHttpGateway.

@Override
public HttpGatewayServer startHttpGateway() {
    if (restEndpointServer != null) {
        LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
        ServiceDTO serviceDetails = new ServiceDTO();
        serviceDetails.setContainer("local");
        serviceDetails.setVersion("1");
        // XXX: pick a non routable address to simulate connection refused (in this case 10.0.0.0 )
        mappedServices.put("/hello/world", new MappedServices("http://10.0.0.0:8181", serviceDetails, loadBalancer, false));
    }
    HttpGatewayHandler handler = new HttpGatewayHandler(vertx, new HttpGateway() {

        @Override
        public void addMappingRuleConfiguration(HttpMappingRule mappingRule) {
        }

        @Override
        public void removeMappingRuleConfiguration(HttpMappingRule mappingRule) {
        }

        @Override
        public Map<String, MappedServices> getMappedServices() {
            return mappedServices;
        }

        @Override
        public boolean isEnableIndex() {
            return true;
        }

        @Override
        public InetSocketAddress getLocalAddress() {
            return new InetSocketAddress("0.0.0.0", 8080);
        }

        @Override
        public void addCallDetailRecord(CallDetailRecord cdr) {
        }
    });
    handler.setConnectionTimeout(1000);
    httpGatewayServer = new HttpGatewayServer(vertx, handler, null, 8080);
    httpGatewayServer.setHost("localhost");
    httpGatewayServer.init();
    return httpGatewayServer;
}
Also used : HttpGatewayServer(io.fabric8.gateway.handlers.http.HttpGatewayServer) HttpGatewayHandler(io.fabric8.gateway.handlers.http.HttpGatewayHandler) HttpMappingRule(io.fabric8.gateway.handlers.http.HttpMappingRule) InetSocketAddress(java.net.InetSocketAddress) MappedServices(io.fabric8.gateway.handlers.http.MappedServices) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) Map(java.util.Map) HttpGateway(io.fabric8.gateway.handlers.http.HttpGateway)

Example 20 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class HttpGatewayRequestTimeoutTest method startHttpGateway.

@Override
public HttpGatewayServer startHttpGateway() {
    if (restEndpointServer != null) {
        LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
        ServiceDTO serviceDetails = new ServiceDTO();
        serviceDetails.setContainer("local");
        serviceDetails.setVersion("1");
        mappedServices.put("/hello/world", new MappedServices("http://localhost:8181", serviceDetails, loadBalancer, false));
    }
    HttpGatewayHandler handler = new HttpGatewayHandler(vertx, new HttpGateway() {

        @Override
        public void addMappingRuleConfiguration(HttpMappingRule mappingRule) {
        }

        @Override
        public void removeMappingRuleConfiguration(HttpMappingRule mappingRule) {
        }

        @Override
        public Map<String, MappedServices> getMappedServices() {
            return mappedServices;
        }

        @Override
        public boolean isEnableIndex() {
            return true;
        }

        @Override
        public InetSocketAddress getLocalAddress() {
            return new InetSocketAddress("0.0.0.0", 8080);
        }

        @Override
        public void addCallDetailRecord(CallDetailRecord cdr) {
        }
    });
    handler.setRequestTimeout(1000L);
    httpGatewayServer = new HttpGatewayServer(vertx, handler, null, 8080);
    httpGatewayServer.setHost("localhost");
    httpGatewayServer.init();
    return httpGatewayServer;
}
Also used : HttpGatewayServer(io.fabric8.gateway.handlers.http.HttpGatewayServer) HttpGatewayHandler(io.fabric8.gateway.handlers.http.HttpGatewayHandler) HttpMappingRule(io.fabric8.gateway.handlers.http.HttpMappingRule) InetSocketAddress(java.net.InetSocketAddress) MappedServices(io.fabric8.gateway.handlers.http.MappedServices) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) Map(java.util.Map) HttpGateway(io.fabric8.gateway.handlers.http.HttpGateway)

Aggregations

Test (org.junit.Test)16 HashMap (java.util.HashMap)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)7 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 DispatchQueue (org.fusesource.hawtdispatch.DispatchQueue)7 HttpGatewayHandler (io.fabric8.gateway.handlers.http.HttpGatewayHandler)6 LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)4 RoundRobinLoadBalancer (io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer)4 InetSocketAddress (java.net.InetSocketAddress)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FutureHandler (io.fabric8.gateway.handlers.detecting.FutureHandler)3 HttpGateway (io.fabric8.gateway.handlers.http.HttpGateway)3 HttpGatewayServer (io.fabric8.gateway.handlers.http.HttpGatewayServer)3 HttpMappingRule (io.fabric8.gateway.handlers.http.HttpMappingRule)3 MappedServices (io.fabric8.gateway.handlers.http.MappedServices)3 Map (java.util.Map)3 Handler (org.vertx.java.core.Handler)3 HttpClientResponse (org.vertx.java.core.http.HttpClientResponse)3