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);
}
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();
}
}
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));
}
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));
}
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));
}
Aggregations