Search in sources :

Example 1 with TestCleaner

use of org.jenkinsci.test.acceptance.guice.TestCleaner 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

UnixServerSocketChannel (jnr.unixsocket.UnixServerSocketChannel)1 UnixSocketAddress (jnr.unixsocket.UnixSocketAddress)1 UnixSocketChannel (jnr.unixsocket.UnixSocketChannel)1 IJenkinsController (org.jenkinsci.test.acceptance.controller.IJenkinsController)1 JenkinsController (org.jenkinsci.test.acceptance.controller.JenkinsController)1 TestCleaner (org.jenkinsci.test.acceptance.guice.TestCleaner)1