use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class InvocationTest method testUnderLoadAsyncProto.
@Test(timeout = 30 * 1000)
public void testUnderLoadAsyncProto() throws Exception {
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
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);
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();
AsyncClient[] threads = new AsyncClient[BENCHMARK_CLIENTS];
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t] = new AsyncClient(t, BENCHMARK_INVOCATIONS_PER_CLIENT, hello, failures, requests, latencies);
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();
}
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class InvocationTest method testOverflow.
@Test(timeout = 30 * 1000)
public void testOverflow() 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());
final Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
final AtomicInteger requests = new AtomicInteger(0);
final AtomicInteger responses = new AtomicInteger(0);
final AtomicInteger failures = new AtomicInteger(0);
char[] chars = new char[65 * 1024];
final String payload = new String(chars);
Thread[] threads = new Thread[BENCHMARK_CLIENTS];
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t] = new Thread() {
public void run() {
try {
requests.incrementAndGet();
hello.hello(payload);
responses.incrementAndGet();
} catch (Throwable t) {
failures.incrementAndGet();
}
}
};
threads[t].start();
}
for (int t = 0; t < BENCHMARK_CLIENTS; t++) {
threads[t].join(10000);
System.err.format("REQUEST: %d of %d%n", requests.get(), BENCHMARK_CLIENTS);
System.err.format("RESPONSES: %d of %d%n", responses.get(), BENCHMARK_CLIENTS);
assertEquals(threads[t].isAlive(), false);
}
assertEquals(BENCHMARK_CLIENTS, requests.get());
assertEquals(BENCHMARK_CLIENTS, responses.get());
assertEquals(0, failures.get());
} finally {
server.stop();
client.stop();
}
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class Fabric8Container method start.
@Override
public void start() throws LifecycleException {
// lets kill any containers that are running before we start
FabricAssertions.killJavaAndDockerProcesses();
fabricControllerManager = createFabricControllerManager();
Fabric8ContainerConfiguration config = configuration.get();
config.configure(fabricControllerManager);
try {
FabricController fabricController = FabricAssertions.assertFabricCreate(fabricControllerManager);
controller.set(fabricController);
} catch (Exception e) {
throw new LifecycleException("Failed to create fabric: " + e, e);
}
System.out.println("Created a controller " + controller.get());
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class CreateSshContainerTest method testSshContainerProvider.
@Test
public void testSshContainerProvider() throws Throwable {
Assume.assumeTrue(isReady());
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
CreateContainerOptions options = CreateSshContainerOptions.builder().name("ssh1").host(host).port(Integer.parseInt(port)).username(username).password(password).build();
CreateContainerMetadata[] metadata = fabricService.createContainers(options);
assertNotNull(metadata);
assertEquals(1, metadata.length);
if (metadata[0].getFailure() != null) {
throw metadata[0].getFailure();
}
assertTrue("Expected successful creation of remote ssh container", metadata[0].isSuccess());
assertNotNull("Expected successful creation of remote ssh container", metadata[0].getContainer());
Provision.containersStatus(Arrays.asList(metadata[0].getContainer()), "success", PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list -v"));
System.out.println(executeCommand("fabric:container-resolver-list"));
Container ssh1 = fabricService.getContainer("ssh1");
assertTrue(ssh1.isAlive());
createAndAssertChildContainer(fabricService, "ssh2", "ssh1", "default");
// Stop & Start Remote Child
Container ssh2 = fabricService.getContainer("ssh2");
ssh2.stop();
assertFalse(ssh2.isAlive());
ssh2.start();
Provision.containersStatus(Arrays.asList(ssh2), "success", PROVISION_TIMEOUT);
assertTrue(ssh2.isAlive());
ssh2.stop();
// Try stopping and starting the remote container.
ssh1.stop();
assertFalse(ssh1.isAlive());
System.out.println(executeCommand("fabric:container-list -v"));
ssh1.start();
Provision.containersStatus(Arrays.asList(ssh1), "success", PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list -v"));
assertTrue(ssh1.isAlive());
} finally {
fabricProxy.close();
}
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class TcpGatewayHandler method handle.
@Override
public void handle(final NetSocket socket) {
NetClient client = null;
List<String> paths = serviceMap.getPaths();
TcpClientRequestFacade requestFacade = new TcpClientRequestFacade(socket);
String path = pathLoadBalancer.choose(paths, requestFacade);
if (path != null) {
List<ServiceDetails> services = serviceMap.getServices(path);
if (!services.isEmpty()) {
ServiceDetails serviceDetails = serviceLoadBalancer.choose(services, requestFacade);
if (serviceDetails != null) {
List<String> urlStrings = serviceDetails.getServices();
for (String urlString : urlStrings) {
if (Strings.notEmpty(urlString)) {
// lets create a client for this request...
try {
URI uri = new URI(urlString);
// URL url = new URL(urlString);
String urlProtocol = uri.getScheme();
if (Objects.equal(protocol, urlProtocol)) {
Handler<AsyncResult<NetSocket>> handler = new Handler<AsyncResult<NetSocket>>() {
public void handle(final AsyncResult<NetSocket> asyncSocket) {
socket.resume();
NetSocket clientSocket = asyncSocket.result();
Pump.createPump(clientSocket, socket).start();
Pump.createPump(socket, clientSocket).start();
}
};
client = createClient(socket, uri, handler);
break;
}
} catch (MalformedURLException e) {
LOG.warn("Failed to parse URL: " + urlString + ". " + e, e);
} catch (URISyntaxException e) {
LOG.warn("Failed to parse URI: " + urlString + ". " + e, e);
}
}
}
}
}
}
if (client == null) {
// fail to route
LOG.info("No service available for protocol " + protocol + " for paths " + paths);
socket.close();
}
}
Aggregations