@Test public void shouldNotThrowException_instedReturnAppropriateErrorCode_whenSomethingGoesWrongInLaunch() { AgentLaunchDescriptor launchDesc = mock(AgentLaunchDescriptor.class); when((String) launchDesc.context().get(AgentBootstrapperArgs.SERVER_URL)).thenThrow(new RuntimeException("Ouch!")); try { assertThat(new AgentLauncherImpl().launch(launchDesc), is(-273)); } catch (Exception e) { fail("should not have blown up, because it directly interfaces with bootstrapper"); } }
shutdownHook = registerShutdownHook(); AgentBootstrapperBackwardCompatibility backwardCompatibility = backwardCompatibility(context); ServerUrlGenerator urlGenerator = backwardCompatibility.getUrlGenerator(); File rootCertFile = backwardCompatibility.rootCertFile(); agentDownloader.downloadIfNecessary(DownloadableFile.AGENT); returnValue = agentProcessParentRunner.run(getLauncherVersion(), launcherDownloader.getMd5(), urlGenerator, System.getenv(), context); return UNKNOWN_EXCEPTION_OCCURRED; } finally { removeShutDownHook(shutdownHook); lockFile.delete();
public int launch(AgentLaunchDescriptor descriptor) { LogConfigurator logConfigurator = new LogConfigurator("agent-launcher-logback.xml"); return logConfigurator.runWithLogger(() -> doLaunch(descriptor)); }
@Test public void shouldPassLauncherVersionToAgent() throws InterruptedException, IOException { final List<String> actualVersion = new ArrayList<>(); final AgentLauncher launcher = new AgentLauncherImpl(new AgentLauncherImpl.AgentProcessParentRunner() { public int run(String launcherVersion, String launcherMd5, ServerUrlGenerator urlConstructor, Map<String, String> environmentVariables, Map context) { actualVersion.add(launcherVersion); return 0; } }); TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); launcher.launch(launchDescriptor()); assertThat(actualVersion.size(), is(1)); assertThat(actualVersion.get(0), is(CurrentGoCDVersion.getInstance().fullVersion())); }
@Test public void shouldDownloadLauncherJarIfLocalCopyIsStale() throws IOException { //because new invocation will take care of pulling latest agent down, and will then operate on it with the latest launcher -jj File staleJar = randomFile(AGENT_LAUNCHER_JAR); long original = staleJar.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(staleJar.length(), not(original)); }
@Test public void shouldDownloadLauncherJarIfLocalCopyIsStale_butShouldReturnWithoutDownloadingOrLaunchingAgent() throws Exception { File launcher = randomFile(AGENT_LAUNCHER_JAR); long original = launcher.length(); File agentFile = randomFile(AGENT_BINARY_JAR); long originalAgentLength = agentFile.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(launcher.length(), not(original)); assertThat(agentFile.length(), is(originalAgentLength)); }
@Test public void shouldDownload_AgentJar_IfTheCurrentJarIsStale() throws Exception { if (!OS_CHECKER.satisfy()) { TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); File staleJar = randomFile(AGENT_BINARY_JAR); long original = staleJar.length(); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(staleJar.length(), not(original)); } }
@Test public void should_NOT_Download_AgentJar_IfTheCurrentJarIsUpToDate() throws Exception { if (!OS_CHECKER.satisfy()) { TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); TEST_AGENT.copyTo(AGENT_BINARY_JAR); assertTrue(AGENT_BINARY_JAR.setLastModified(0)); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(AGENT_BINARY_JAR.lastModified(), is(0L)); } }
@Test public void should_NOT_Download_TfsImplJar_IfTheCurrentJarIsUpToDate() throws Exception { if (!OS_CHECKER.satisfy()) { TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR); TEST_AGENT.copyTo(AGENT_BINARY_JAR); TEST_TFS_IMPL.copyTo(TFS_IMPL_JAR); assertTrue(TFS_IMPL_JAR.setLastModified(0)); new AgentLauncherImpl().launch(launchDescriptor()); assertThat(TFS_IMPL_JAR.lastModified(), is(0L)); } }