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