@Test public void shouldNotMatchRuntimeInfosWithDifferentOperatingSystems() { AgentRuntimeInfo linux = AgentRuntimeInfo.fromServer(new AgentConfig("uuid", "localhost", "176.19.4.1"), true, "/var/lib", 0L, "linux", false); AgentRuntimeInfo osx = AgentRuntimeInfo.fromServer(new AgentConfig("uuid", "localhost", "176.19.4.1"), true, "/var/lib", 0L, "foo bar", false); assertThat(linux, is(not(osx))); }
public void run() { int count = 0; while (!stop) { AgentConfig agentConfig = new AgentConfig("uuid" + count, "CCeDev_" + count, "10.18.5." + count); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", Long.MAX_VALUE, "linux", false)); count++; } }
@Test(expected = Exception.class) public void should() throws Exception { AgentRuntimeInfo.fromServer(new AgentConfig("uuid", "localhost", "127.0.0.1"), false, "", 0L, "linux", false); }
@Test public void agentHostnameShouldBeUnique() { AgentConfig agentConfig = new AgentConfig("uuid2", "CCeDev01", "10.18.5.1"); AgentInstances agentInstances = new AgentInstances(mock(AgentStatusChangeListener.class)); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false)); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false)); }
public static AgentInstance updateUsableSpace(AgentInstance agentInstance, Long freespace) { AgentConfig agentConfig = agentInstance.agentConfig(); agentInstance.update(AgentRuntimeInfo.fromServer(agentConfig, true, agentInstance.getLocation(), freespace, "linux", false)); return agentInstance; }
@Test public void shouldUsingIdleWhenRegistrationRequestIsFromLocalAgent() { AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer( new AgentConfig("uuid", "localhost", "127.0.0.1"), false, "/var/lib", 0L, "linux", false); assertThat(agentRuntimeInfo.getRuntimeStatus(), is(Idle)); }
@Test public void shouldNotAssignCertificateToPendingAgent() { AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false); AgentInstance agentInstance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class)); Registration entry = agentInstance.assignCertification(); assertThat(entry.getChain().length, is(0)); }
long usableSpace = Long.parseLong(usablespaceAsString); AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, registeredAlready, location, usableSpace, operatingSystem, supportsBuildCommandProtocol);
@Test public void shouldBeUnknownWhenRegistrationRequestIsFromLocalAgent() { AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer( new AgentConfig("uuid", "localhost", "176.19.4.1"), false, "/var/lib", 0L, "linux", false); assertThat(agentRuntimeInfo.getRuntimeStatus(), is(AgentRuntimeStatus.Unknown)); }
@Test public void shouldUsingIdleWhenRegistrationRequestIsFromAlreadyRegisteredAgent() { AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer( new AgentConfig("uuid", "localhost", "176.19.4.1"), true, "/var/lib", 0L, "linux", false); assertThat(agentRuntimeInfo.getRuntimeStatus(), is(AgentRuntimeStatus.Idle)); }
@Test public void shouldUnderstandFilteringAgentListBasedOnUuid() { AgentInstances instances = new AgentInstances(mock(AgentStatusChangeListener.class)); AgentRuntimeInfo agent1 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-1", "host-1", "192.168.1.2"), true, "/foo/bar", 100l, "linux", false); AgentRuntimeInfo agent2 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-2", "host-2", "192.168.1.3"), true, "/bar/baz", 200l, "linux", false); AgentRuntimeInfo agent3 = AgentRuntimeInfo.fromServer(new AgentConfig("uuid-3", "host-3", "192.168.1.4"), true, "/baz/quux", 300l, "linux", false); AgentInstance instance1 = AgentInstance.createFromLiveAgent(agent1, systemEnvironment, mock(AgentStatusChangeListener.class)); instances.add(instance1); instances.add(AgentInstance.createFromLiveAgent(agent2, systemEnvironment, mock(AgentStatusChangeListener.class))); AgentInstance instance3 = AgentInstance.createFromLiveAgent(agent3, systemEnvironment, mock(AgentStatusChangeListener.class)); instances.add(instance3); List<AgentInstance> agents = instances.filter(Arrays.asList("uuid-1", "uuid-3")); assertThat(agents, hasItems(instance1, instance3)); assertThat(agents.size(), is(2)); }
@Test(expected = MaxPendingAgentsLimitReachedException.class) public void registerShouldErrorOutIfMaxPendingAgentsLimitIsReached() { AgentConfig agentConfig = new AgentConfig("uuid2", "CCeDev01", "10.18.5.1"); AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, AgentInstanceMother.pending()); when(systemEnvironment.get(SystemEnvironment.MAX_PENDING_AGENTS_ALLOWED)).thenReturn(1); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false)); }
@Test public void shouldSupportConcurrentOperations() throws Exception { final AgentInstances agentInstances = new AgentInstances(mock(AgentStatusChangeListener.class)); // register 100 agents for (int i = 0; i < 100; i++) { AgentConfig agentConfig = new AgentConfig("uuid" + i, "CCeDev_" + i, "10.18.5." + i); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", Long.MAX_VALUE, "linux", false)); } thrown.expect(MaxPendingAgentsLimitReachedException.class); thrown.expectMessage("Max pending agents allowed 100, limit reached"); AgentConfig agentConfig = new AgentConfig("uuid" + 200, "CCeDev_" + 200, "10.18.5." + 200); agentInstances.register(AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", Long.MAX_VALUE, "linux", false)); }
public static AgentInstance updateLocation(AgentInstance agentInstance, String location) { AgentConfig agentConfig = agentInstance.agentConfig(); agentInstance.update(AgentRuntimeInfo.fromServer(agentConfig, true, location, agentInstance.getUsableSpace(), "linux", agentInstance.getSupportsBuildCommandProtocol())); return agentInstance; }
public static AgentInstance updateRuntimeStatus(AgentInstance agentInstance, AgentRuntimeStatus status) { AgentConfig agentConfig = agentInstance.agentConfig(); AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, true, agentInstance.getLocation(), agentInstance.getUsableSpace(), "linux", false); newRuntimeInfo.setRuntimeStatus(status); agentInstance.update(newRuntimeInfo); return agentInstance; }
public static AgentInstance updateOS(AgentInstance agentInstance, String operatingSystem) { AgentConfig agentConfig = agentInstance.agentConfig(); AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, true, agentInstance.getLocation(), agentInstance.getUsableSpace(), operatingSystem, false); newRuntimeInfo.setStatus(agentInstance.getStatus()); agentInstance.update(newRuntimeInfo); return agentInstance; }
public static AgentInstance pending(SystemEnvironment systemEnvironment) { AgentRuntimeInfo runtimeInfo = AgentRuntimeInfo.fromServer(new AgentConfig("uuid4", "CCeDev03", "10.18.5.3", new ResourceConfigs(new ResourceConfig("db"), new ResourceConfig("web"))), false, "/var/lib", 0L, "linux", false); AgentInstance pending = AgentInstance.createFromLiveAgent(runtimeInfo, systemEnvironment, mock(AgentStatusChangeListener.class)); pending.pending(); pending.update(runtimeInfo); pending.pending(); return pending; }