Search in sources :

Example 21 with Start

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();
    }
}
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) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 22 with Start

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();
    }
}
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) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 23 with Start

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());
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) FabricController(io.fabric8.testkit.FabricController) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 24 with Start

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();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) Test(org.junit.Test)

Example 25 with Start

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();
    }
}
Also used : NetSocket(org.vertx.java.core.net.NetSocket) MalformedURLException(java.net.MalformedURLException) Handler(org.vertx.java.core.Handler) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NetClient(org.vertx.java.core.net.NetClient) ServiceDetails(io.fabric8.gateway.ServiceDetails) AsyncResult(org.vertx.java.core.AsyncResult)

Aggregations

Test (org.junit.Test)25 IOException (java.io.IOException)24 File (java.io.File)18 HashMap (java.util.HashMap)15 Map (java.util.Map)10 Git (org.eclipse.jgit.api.Git)10 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)8 ArrayList (java.util.ArrayList)8 Bundle (org.osgi.framework.Bundle)8 PatchException (io.fabric8.patch.management.PatchException)7 URISyntaxException (java.net.URISyntaxException)7 BundleException (org.osgi.framework.BundleException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 CuratorFramework (org.apache.curator.framework.CuratorFramework)6 Container (io.fabric8.api.Container)5 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)5 FabricService (io.fabric8.api.FabricService)5 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)5 MalformedURLException (java.net.MalformedURLException)5 URI (java.net.URI)5