Search in sources :

Example 11 with Hello

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

the class ContainerTest method testProfilerStrategy.

@Test
public void testProfilerStrategy() 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").doTry().to("seda:polyglot").choice().when(body().isEqualTo("<hello/>")).to("seda:english").throwException(new Exception("Error processing exchange")).endChoice().when(body().isEqualTo("<hallo/>")).to("seda:dutch").delay(2).to("seda:german").endChoice().otherwise().to("seda:french").endDoTry().doCatch(Throwable.class).to("seda:errors");
            String[] eps = { "polyglot", "english", "dutch", "german", "french", "errors" };
            for (String s : eps) {
                from("seda:" + s).aggregate(constant("ok"), new BodyInAggregatingStrategy()).completionSize(3).to("mock:" + s);
            }
        }
    });
    context.start();
    final ProducerTemplate template = new DefaultProducerTemplate(context);
    template.start();
    final String[] values = { "<hello/>", "<hallo/>", "<bonjour/>" };
    final Random rnd = new Random();
    for (int i = 0; i < 100; i++) {
        template.sendBody("direct:a", values[rnd.nextInt(values.length)]);
    }
    profiler.reset();
    long t0 = System.nanoTime();
    int nbThreads = 10;
    final CountDownLatch latch = new CountDownLatch(nbThreads);
    for (int t = 0; t < nbThreads; t++) {
        new Thread() {

            public void run() {
                for (int i = 0; i < 1000; i++) {
                    template.sendBody("direct:a", values[rnd.nextInt(values.length)]);
                }
                latch.countDown();
            }
        }.start();
    }
    latch.await();
    long t1 = System.nanoTime();
    System.out.println("Total time: " + TimeUnit.MILLISECONDS.convert(t1 - t0, TimeUnit.NANOSECONDS));
    print(profiler.getStatistics());
    System.out.println();
    MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = context.getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(context);
    String xml = (String) mbeanServer.invoke(on, "dumpRoutesStatsAsXml", new Object[] { false, true }, new String[] { "boolean", "boolean" });
    System.out.println(xml);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Breadcrumbs(io.fabric8.insight.camel.breadcrumb.Breadcrumbs) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ObjectName(javax.management.ObjectName) Profiler(io.fabric8.insight.camel.profiler.Profiler) Random(java.util.Random) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 12 with Hello

use of io.fabric8.demo.cxf.Hello in project vertx-openshift-it by cescoffier.

the class Http2IT method testGRPC.

@Test
public void testGRPC() throws Exception {
    Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
    String host = securedUrlForRoute(client.routes().withName("hello").get()).getHost();
    System.out.println("Host: " + host);
    System.out.println("Port: " + 443);
    ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, host, 443).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
    GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
    HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
    AtomicReference<String> result = new AtomicReference<>();
    System.out.println("Sending request...");
    stub.sayHello(request, asyncResponse -> {
        System.out.println("Got result");
        if (asyncResponse.succeeded()) {
            System.out.println("Succeeded " + asyncResponse.result().getMessage());
            result.set(asyncResponse.result().getMessage());
        } else {
            asyncResponse.cause().printStackTrace();
        }
    });
    await().atMost(5, TimeUnit.MINUTES).untilAtomic(result, is(notNullValue()));
    assertThat(result.get()).contains("Hello OpenShift");
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) ManagedChannel(io.grpc.ManagedChannel) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) Assertions(io.fabric8.kubernetes.assertions.Assertions) TimeUnit(java.util.concurrent.TimeUnit) Kube.securedUrlForRoute(io.vertx.it.openshift.utils.Kube.securedUrlForRoute) HttpVersion(io.vertx.core.http.HttpVersion) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Matchers.is(org.hamcrest.Matchers.is) HttpClientOptions(io.vertx.core.http.HttpClientOptions) org.junit(org.junit) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 13 with Hello

use of io.fabric8.demo.cxf.Hello in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method testShellIsSet.

@Test
public void testShellIsSet() {
    BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder().shell(new Arguments.Builder().withShell("/bin/sh echo hello").build()).build();
    DockerFileBuilder builder = assemblyManager.createDockerFileBuilder(buildConfig, buildConfig.getAssemblyConfigurations());
    String content = builder.content();
    assertTrue(content.contains("SHELL [\"/bin/sh\",\"echo\",\"hello\"]"));
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 14 with Hello

use of io.fabric8.demo.cxf.Hello in project docker-maven-plugin by fabric8io.

the class DockerFileBuilderTest method testHealthCheckCmdParams.

@Test
public void testHealthCheckCmdParams() {
    HealthCheckConfiguration hc = new HealthCheckConfiguration.Builder().cmd("echo hello").interval("5s").timeout("3s").retries(4).build();
    String dockerfileContent = new DockerFileBuilder().healthCheck(hc).content();
    assertThat(dockerfileToMap(dockerfileContent), hasEntry("HEALTHCHECK", "--interval=5s --timeout=3s --retries=4 CMD echo hello"));
}
Also used : HealthCheckConfiguration(io.fabric8.maven.docker.config.HealthCheckConfiguration) Test(org.junit.Test)

Example 15 with Hello

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

the class InvocationTest method testUnderLoadSyncObject.

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

            public Object get() {
                return helloImpl;
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        assertEquals("Hello World!", hello.helloworld());
        final AtomicInteger requests = new AtomicInteger(0);
        final AtomicInteger failures = new AtomicInteger(0);
        final long[] latencies = new long[BENCHMARK_CLIENTS * BENCHMARK_INVOCATIONS_PER_CLIENT];
        final long start = System.nanoTime();
        Thread[] threads = new Thread[BENCHMARK_CLIENTS];
        for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
            final int thread_idx = t;
            threads[t] = new Thread() {

                public void run() {
                    for (int i = 0; i < BENCHMARK_INVOCATIONS_PER_CLIENT; i++) {
                        try {
                            requests.incrementAndGet();
                            String response;
                            final long start = System.nanoTime();
                            response = hello.hello("Fabric");
                            final long end = System.nanoTime();
                            latencies[(thread_idx * BENCHMARK_INVOCATIONS_PER_CLIENT) + i] = end - start;
                            assertEquals("Hello Fabric!", response);
                        } catch (Throwable t) {
                            latencies[(thread_idx * BENCHMARK_INVOCATIONS_PER_CLIENT) + i] = -1;
                            failures.incrementAndGet();
                            if (t instanceof UndeclaredThrowableException) {
                                t = ((UndeclaredThrowableException) t).getUndeclaredThrowable();
                            }
                            System.err.println("Error: " + t.getClass().getName() + (t.getMessage() != null ? " (" + t.getMessage() + ")" : ""));
                        }
                    }
                }
            };
            threads[t].start();
        }
        for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
            threads[t].join();
        }
        final long end = System.nanoTime();
        long latency_sum = 0;
        for (int t = 0; t < latencies.length; t++) {
            if (latencies[t] != -1) {
                latency_sum += latencies[t];
            }
        }
        double latency_avg = ((latency_sum * 1.0d) / requests.get()) / MILLIS_IN_A_NANO;
        double request_rate = ((requests.get() * 1.0d) / (end - start)) * SECONDS_IN_A_NANO;
        System.err.println(String.format("Requests/Second: %,.2f", request_rate));
        System.err.println(String.format("Average request latency: %,.2f ms", latency_avg));
        System.err.println("Error Ratio: " + failures.get() + " / " + requests.get());
    } 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

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