Search in sources :

Example 11 with AgentBootstrapperArgs

use of com.thoughtworks.go.agent.common.AgentBootstrapperArgs in project gocd by gocd.

the class AgentBootstrapperTest method shouldNotDieWhenInvocationOfLauncherRaisesException_butCreationOfLauncherWentThrough.

@Test
public void shouldNotDieWhenInvocationOfLauncherRaisesException_butCreationOfLauncherWentThrough() throws InterruptedException {
    final Semaphore waitForLauncherInvocation = new Semaphore(1);
    waitForLauncherInvocation.acquire();
    final AgentBootstrapper bootstrapper = new AgentBootstrapper() {

        @Override
        AgentLauncherCreator getLauncherCreator() {
            return new AgentLauncherCreator() {

                public AgentLauncher createLauncher() {
                    return new AgentLauncher() {

                        public int launch(AgentLaunchDescriptor descriptor) {
                            try {
                                throw new RuntimeException("fail!!! i say.");
                            } finally {
                                if (waitForLauncherInvocation.availablePermits() == 0) {
                                    waitForLauncherInvocation.release();
                                }
                            }
                        }
                    };
                }

                @Override
                public void close() {
                }
            };
        }
    };
    final AgentBootstrapper spyBootstrapper = stubJVMExit(bootstrapper);
    Thread stopLoopThd = new Thread(new Runnable() {

        public void run() {
            try {
                waitForLauncherInvocation.acquire();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            ReflectionUtil.setField(spyBootstrapper, "loop", false);
        }
    });
    stopLoopThd.start();
    try {
        spyBootstrapper.go(true, new AgentBootstrapperArgs(new URL("http://" + "ghost-name" + ":" + 3518 + "/go"), null, AgentBootstrapperArgs.SslMode.NONE));
        stopLoopThd.join();
    } catch (Exception e) {
        fail("should not have propagated exception thrown while invoking the launcher");
    }
}
Also used : AgentLauncher(com.thoughtworks.cruise.agent.common.launcher.AgentLauncher) AgentLaunchDescriptor(com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptor) AgentBootstrapperArgs(com.thoughtworks.go.agent.common.AgentBootstrapperArgs) Semaphore(java.util.concurrent.Semaphore) URL(java.net.URL) Test(org.junit.Test)

Aggregations

AgentBootstrapperArgs (com.thoughtworks.go.agent.common.AgentBootstrapperArgs)11 URL (java.net.URL)8 Test (org.junit.Test)8 AgentLaunchDescriptor (com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptor)3 AgentLauncher (com.thoughtworks.cruise.agent.common.launcher.AgentLauncher)3 AgentCLI (com.thoughtworks.go.agent.common.AgentCLI)2 LogConfigurator (com.thoughtworks.go.logging.LogConfigurator)2 Map (java.util.Map)2 Semaphore (java.util.concurrent.Semaphore)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 HashMap (java.util.HashMap)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1