Search in sources :

Example 6 with AgentBootstrapperArgs

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

the class MacPreferencesPane method ask.

public void ask() {
    AgentBootstrapperArgs bootstrapperArgs = agentMacWindow.getBootstrapperArgs();
    this.serverTextField.setText(bootstrapperArgs.getServerUrl().toString());
    this.fileBrowser.setFile(bootstrapperArgs.getRootCertFile());
    this.sslModeComponent.setSslMode(bootstrapperArgs.getSslMode());
    serverTextField.selectAll();
    serverTextField.grabFocus();
    setVisible(true);
}
Also used : AgentBootstrapperArgs(com.thoughtworks.go.agent.common.AgentBootstrapperArgs)

Example 7 with AgentBootstrapperArgs

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

the class AgentBootstrapperFunctionalTest method shouldDownloadJarIfTheCurrentOneIsWrong.

@Test
public void shouldDownloadJarIfTheCurrentOneIsWrong() throws Exception {
    if (!OS_CHECKER.satisfy()) {
        File agentJar = new File("agent.jar");
        agentJar.delete();
        createRandomFile(agentJar);
        long original = agentJar.length();
        new AgentBootstrapper() {

            @Override
            void jvmExit(int returnValue) {
            }
        }.go(false, new AgentBootstrapperArgs(new URL("http://" + "localhost" + ":" + server.getPort() + "/go"), null, AgentBootstrapperArgs.SslMode.NONE));
        assertThat(agentJar.length(), not(original));
        agentJar.delete();
    }
}
Also used : AgentBootstrapperArgs(com.thoughtworks.go.agent.common.AgentBootstrapperArgs) URL(java.net.URL) Test(org.junit.Test)

Example 8 with AgentBootstrapperArgs

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

the class AgentBootstrapperTest method shouldNotRelaunchAgentLauncherWhenItReturnsAnIrrecoverableCode.

@Test(timeout = 10 * 1000)
public void shouldNotRelaunchAgentLauncherWhenItReturnsAnIrrecoverableCode() throws InterruptedException {
    final boolean[] destroyCalled = new boolean[1];
    final AgentBootstrapper bootstrapper = new AgentBootstrapper() {

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

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

                        public int launch(AgentLaunchDescriptor descriptor) {
                            return AgentLauncher.IRRECOVERABLE_ERROR;
                        }
                    };
                }

                @Override
                public void close() {
                    destroyCalled[0] = true;
                }
            };
        }
    };
    final AgentBootstrapper spyBootstrapper = stubJVMExit(bootstrapper);
    try {
        spyBootstrapper.go(true, new AgentBootstrapperArgs(new URL("http://" + "ghost-name" + ":" + 3518 + "/go"), null, AgentBootstrapperArgs.SslMode.NONE));
    } catch (Exception e) {
        fail("should not have propagated exception thrown while invoking the launcher");
    }
    assertThat(destroyCalled[0], is(true));
}
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) URL(java.net.URL) Test(org.junit.Test)

Example 9 with AgentBootstrapperArgs

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

the class AgentBootstrapperTest method shouldNotDieWhenCreationOfLauncherRaisesException.

@Test
public void shouldNotDieWhenCreationOfLauncherRaisesException() throws InterruptedException {
    final Semaphore waitForLauncherCreation = new Semaphore(1);
    waitForLauncherCreation.acquire();
    final boolean[] reLaunchWaitIsCalled = new boolean[1];
    final AgentBootstrapper bootstrapper = new AgentBootstrapper() {

        @Override
        void waitForRelaunchTime() {
            assertThat(waitTimeBeforeRelaunch, is(0));
            reLaunchWaitIsCalled[0] = true;
            super.waitForRelaunchTime();
        }

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

                public AgentLauncher createLauncher() {
                    try {
                        throw new RuntimeException("i bombed");
                    } finally {
                        if (waitForLauncherCreation.availablePermits() == 0) {
                            waitForLauncherCreation.release();
                        }
                    }
                }

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

        public void run() {
            try {
                waitForLauncherCreation.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 creating launcher");
    }
    assertThat(reLaunchWaitIsCalled[0], is(true));
}
Also used : AgentBootstrapperArgs(com.thoughtworks.go.agent.common.AgentBootstrapperArgs) Semaphore(java.util.concurrent.Semaphore) URL(java.net.URL) Test(org.junit.Test)

Example 10 with AgentBootstrapperArgs

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

the class AgentBootstrapperTest method shouldRetainStateAcrossLauncherInvocations.

@Test
public void shouldRetainStateAcrossLauncherInvocations() throws Exception {
    final Map expectedContext = new HashMap();
    AgentBootstrapper agentBootstrapper = new AgentBootstrapper() {

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

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

                        public static final String COUNT = "count";

                        public int launch(AgentLaunchDescriptor descriptor) {
                            Map descriptorContext = descriptor.context();
                            incrementCount(descriptorContext);
                            incrementCount(expectedContext);
                            Integer expectedCount = (Integer) expectedContext.get(COUNT);
                            assertThat(descriptorContext.get(COUNT), is(expectedCount));
                            if (expectedCount > 3) {
                                ((AgentBootstrapper) descriptor.getBootstrapper()).stopLooping();
                            }
                            return 0;
                        }

                        private void incrementCount(Map map) {
                            Integer currentInvocationCount = map.containsKey(COUNT) ? (Integer) map.get(COUNT) : 0;
                            map.put(COUNT, currentInvocationCount + 1);
                        }
                    };
                }

                @Override
                public void close() {
                }
            };
        }
    };
    AgentBootstrapper spy = stubJVMExit(agentBootstrapper);
    spy.go(true, new AgentBootstrapperArgs(new URL("http://" + "localhost" + ":" + 80 + "/go"), null, AgentBootstrapperArgs.SslMode.NONE));
}
Also used : HashMap(java.util.HashMap) AgentLauncher(com.thoughtworks.cruise.agent.common.launcher.AgentLauncher) AgentLaunchDescriptor(com.thoughtworks.cruise.agent.common.launcher.AgentLaunchDescriptor) AgentBootstrapperArgs(com.thoughtworks.go.agent.common.AgentBootstrapperArgs) HashMap(java.util.HashMap) Map(java.util.Map) 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