@Before public void setup() { AgentIdentifier agentIdentifier = new AgentIdentifier("duloc", "127.0.0.1", "uuid"); AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, "/home/lord-farquaad/builds", "cookie", false); bvs = new BuildVariables(runtimeInfo, new TestingClock(new Date(0))); }
private AgentRuntimeInfo idleRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.idle(); return agentRuntimeInfo; }
@Test public void shouldUpdateTheLastHeardTime() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); Date time = agentInstance.getLastHeardTime(); Thread.sleep(1000); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); Date newtime = agentInstance.getLastHeardTime(); assertThat(newtime.after(time), is(true)); }
@Test public void shouldBecomeIdleAfterApprove() throws Exception { AgentInstance instance = AgentInstance.createFromLiveAgent(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), systemEnvironment, mock(AgentStatusChangeListener.class)); instance.enable(); instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(instance.getStatus(), is(AgentStatus.Idle)); }
@Test public void shouldAssignCertificateToApprovedAgent() { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); Registration entry = agentInstance.assignCertification(); assertThat(entry.getChain().length, is(not(0))); }
@Test public void shouldTellIfHasCookie() throws Exception { assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false).hasDuplicateCookie("cookie"), is(false)); assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false).hasDuplicateCookie("different"), is(true)); assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false).hasDuplicateCookie("cookie"), is(false)); assertThat(new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false).hasDuplicateCookie(null), is(false)); }
private AgentRuntimeInfo cancelRuntimeInfo() { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.busy(defaultBuildingInfo); agentRuntimeInfo.cancel(); return agentRuntimeInfo; }
@Test public void shouldCancelOncePerJob() { runner.setWork(work); runner.handleInstruction(new AgentInstruction(true), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(work.getCallCount(), is(1)); runner.handleInstruction(new AgentInstruction(true), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(work.getCallCount(), is(1)); }
@Test public void shouldNotChangeWhenAgentRunningUnregisteredAgentWork() { Work work = new UnregisteredAgentWork("uuid"); try { work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, agentRuntimeInfo, packageRepositoryExtension, scmExtension, taskExtension, null, null)); } catch (Exception e) { } assertThat(agentRuntimeInfo, is(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false))); }
@Test public void shouldReportIdleWhenAgentRunningNoWork() { NoWork work = new NoWork(); work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, buildRepository, artifactManipulator, agentRuntimeInfo, packageRepositoryExtension, scmExtension, taskExtension, null, null)); assertThat(agentRuntimeInfo, is(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false))); }
@Test public void shouldReturnTrueOnGetJobIsCancelledWhenJobIsCancelled() { assertThat(runner.isJobCancelled(), is(false)); runner.handleInstruction(new AgentInstruction(true), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(runner.isJobCancelled(), is(true)); }
@Test public void shouldUpdateTheInstallLocation() throws Exception { AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class)); String installPath = "/var/lib/GoServer"; AgentRuntimeInfo newRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); newRuntimeInfo.setLocation(installPath); agentInstance.update(newRuntimeInfo); assertThat(agentInstance.getLocation(), is(installPath)); }
@Test public void shouldBeLostContactWhenLastHeardTimeExeedTimeOut() { AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment() { public int getAgentConnectionTimeout() { return -1; } }, mock(AgentStatusChangeListener.class)); assertThat(instance.getStatus(), is(AgentStatus.Missing)); instance.update(new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); instance.refresh(); assertThat(instance.getStatus(), is(AgentStatus.LostContact)); }
@Test public void shouldDoNothingWhenJobIsNotCancelled() { runner.setWork(work); runner.handleInstruction(new AgentInstruction(false), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false)); assertThat(work.getCallCount(), is(0)); }
@Test public void shouldHaveBeautifulPhigureLikeDisplayString() throws Exception { AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.setLocation("/nim/appan/mane"); assertThat(agentRuntimeInfo.agentInfoForDisplay(), is("Agent located at [localhost, 127.0.0.1, /nim/appan/mane]")); }
@Test public void dataMapEncodingAndDecoding() { AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("go02", "10.10.10.1", "uuid"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", true); AgentRuntimeInfo clonedInfo = MessageEncoding.decodeData(MessageEncoding.encodeData(info), AgentRuntimeInfo.class); assertThat(clonedInfo, is(info)); } }
@Test public void encodeAndDecodeAsMessageData() throws Exception { AgentRuntimeInfo info = new AgentRuntimeInfo(new AgentIdentifier("HostName", "ipAddress", "uuid"), AgentRuntimeStatus.Idle, null, null, true); JobIdentifier jobIdentifier = new JobIdentifier("pipeline", 1, "pipelinelabel", "stagename", "1", "job", 1L); Report report = new Report(info, jobIdentifier, JobResult.Passed); assertThat(MessageEncoding.decodeData(MessageEncoding.encodeData(report), Report.class), is(report)); } }
@Before public void before() { agentIdentifier = new AgentIdentifier("localhost", "127.0.0.1", "uuid"); environmentVariableContext = new EnvironmentVariableContext(); artifactManipulator = new GoArtifactsManipulatorStub(); buildRepository = new BuildRepositoryRemoteStub(); this.agentRuntimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); }
public static AgentInstance idle(final Date lastHeardAt, final String hostname, SystemEnvironment systemEnvironment) { AgentConfig idleAgentConfig = new AgentConfig("uuid2", hostname, "10.18.5.1"); AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(idleAgentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false); agentRuntimeInfo.setLocation("/var/lib/foo"); agentRuntimeInfo.idle(); agentRuntimeInfo.setUsableSpace(10 * 1024l); AgentInstance agentInstance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class)); agentInstance.idle(); agentInstance.update(agentRuntimeInfo); ReflectionUtil.setField(agentInstance, "lastHeardTime", lastHeardAt); return agentInstance; }
@Test public void shouldMergeEnvironmentVariablesFromInitialContext() throws IOException { pipelineConfig.setMaterialConfigs(new MaterialConfigs()); BuildAssignment buildAssignment = createAssignment(new EnvironmentVariableContext("foo", "bar")); BuildWork work = new BuildWork(buildAssignment, systemEnvironment.consoleLogCharset()); EnvironmentVariableContext environmentContext = new EnvironmentVariableContext(); AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID); work.doWork(environmentContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), new GoArtifactsManipulatorStub(), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, null)); assertEnvironmentContext(environmentContext, "foo", is("bar")); }