@Test
	public void selectAgentsTest() {
		Set<AgentInfo> recentlyUsedAgents = getRecentlyUsedAgents();
		hazelcastService.put(DIST_MAP_NAME_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents);

		User testUser = new User();
		testUser.setUserId(TEST_USER_ID);

		Set<AgentInfo> allFreeAgents = getFreeAgents();
		Set<AgentInfo> selectedAgents = agentService.selectAgent(testUser, allFreeAgents, 5);

		assertThat(selectedAgents.size(), is(5));

		List<AgentInfo> selectedDedicatedAgents = selectedAgents
			.stream()
			.filter(agentInfo -> StringUtils.isNotEmpty(agentInfo.getOwner()))
			.collect(toList());
		assertThat(selectedDedicatedAgents.size(), is(2));

		// Check if recently used agents are selected.
		assertTrue(selectedAgents.contains(createAgentInfo("test-agent-1")));
		assertTrue(selectedAgents.contains(createAgentInfo("test-agent-3")));
		assertTrue(selectedAgents.contains(createAgentInfo("test-agent-5")));

		// Add recently used agents.
		recentlyUsedAgents.add(createAgentInfo("test-agent-11", "test-region", TEST_USER_ID));
		recentlyUsedAgents.add(createAgentInfo("test-agent-14", "test-region", TEST_USER_ID));
		hazelcastService.put(DIST_MAP_NAME_RECENTLY_USED_AGENTS, TEST_USER_ID, recentlyUsedAgents);

		// Add owned agents for another test.
		allFreeAgents.add(createAgentInfo("test-agent-8", "test-region", "another-user"));
		allFreeAgents.add(createAgentInfo("test-agent-9", "test-region", "another-user"));
		allFreeAgents.add(createAgentInfo("test-agent-10", "test-region", "another-user"));
		allFreeAgents.add(createAgentInfo("test-agent-11", "test-region", TEST_USER_ID));
		allFreeAgents.add(createAgentInfo("test-agent-12", "test-region", TEST_USER_ID));
		allFreeAgents.add(createAgentInfo("test-agent-13", "test-region", TEST_USER_ID));
		allFreeAgents.add(createAgentInfo("test-agent-14", "test-region", TEST_USER_ID));
		allFreeAgents.add(createAgentInfo("test-agent-15", "test-region", TEST_USER_ID));

		selectedAgents = agentService.selectAgent(testUser, allFreeAgents, 3);

		assertThat(selectedAgents.size(), is(3));
		// Check if recently used owned agents are selected.
		assertTrue(selectedAgents.contains(createAgentInfo("test-agent-6")));
		assertTrue(selectedAgents.contains(createAgentInfo("test-agent-11")));
		assertTrue(selectedAgents.contains(createAgentInfo("test-agent-14")));

		hazelcastService.delete(DIST_MAP_NAME_RECENTLY_USED_AGENTS, TEST_USER_ID);
	}
Priority of agent selection.
1. dedicated agent of recently used.
2. dedicated agent.
3. public agent of recently used.
4. public agent.
ngrinder-controller/src/test/java/org/ngrinder/agent/service/AgentServiceTest.java