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);
}
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");
}
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\"]"));
}
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"));
}
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();
}
}
Aggregations