Search in sources :

Example 6 with JenkinsController

use of org.jenkinsci.test.acceptance.controller.JenkinsController in project acceptance-test-harness by jenkinsci.

the class JenkinsControllerPoolProcess method processServerSocket.

/**
 * Accepts connection to Unix domain socket and hand it off to a connection handling thread.
 */
private void processServerSocket() throws IOException, InterruptedException {
    socket.deleteOnExit();
    socket.delete();
    try (UnixServerSocketChannel channel = UnixServerSocketChannel.open()) {
        channel.configureBlocking(true);
        channel.socket().bind(new UnixSocketAddress(socket));
        System.out.println("JUT Server is ready and listening at " + socket.getAbsolutePath());
        while (true) {
            final UnixSocketChannel c = channel.accept();
            System.out.println("Accepted");
            final QueueItem qi = queue.take();
            final JenkinsController j = qi.controller;
            System.out.println("Handed out " + j.getUrl());
            new Thread("Connection handling thread") {

                @Override
                public void run() {
                    lifecycle.import_(qi.testScope);
                    try {
                        processConnection(c, j);
                    } finally {
                        TestCleaner scope = injector.getInstance(TestCleaner.class);
                        if (scope != null)
                            scope.performCleanUp();
                        lifecycle.endTestScope();
                    }
                }
            }.start();
        }
    }
}
Also used : TestCleaner(org.jenkinsci.test.acceptance.guice.TestCleaner) UnixSocketChannel(jnr.unixsocket.UnixSocketChannel) JenkinsController(org.jenkinsci.test.acceptance.controller.JenkinsController) IJenkinsController(org.jenkinsci.test.acceptance.controller.IJenkinsController) UnixServerSocketChannel(jnr.unixsocket.UnixServerSocketChannel) UnixSocketAddress(jnr.unixsocket.UnixSocketAddress)

Aggregations

JenkinsController (org.jenkinsci.test.acceptance.controller.JenkinsController)6 World (org.jenkinsci.test.acceptance.guice.World)3 Injector (com.google.inject.Injector)2 IOException (java.io.IOException)2 Annotation (java.lang.annotation.Annotation)2 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 IJenkinsController (org.jenkinsci.test.acceptance.controller.IJenkinsController)2 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)2 TestRule (org.junit.rules.TestRule)2 Description (org.junit.runner.Description)2 Statement (org.junit.runners.model.Statement)2 Provides (com.google.inject.Provides)1 File (java.io.File)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1